Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not suggest adding a bound to a opaque type #100940

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,17 @@ impl<'tcx> BorrowExplanation<'tcx> {
_ => {}
}
}
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(

fn add_lifetime_bound_suggestion_to_diagnostic(
&self,
err: &mut Diagnostic,
category: &ConstraintCategory<'tcx>,
span: Span,
region_name: &RegionName,
) {
if !span.is_desugaring(DesugaringKind::OpaqueTy) {
return;
}
if let ConstraintCategory::OpaqueType = category {
let suggestable_name =
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/regions/do-not-suggest-adding-bound-to-opaque-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub trait T {}

struct S<'a>(&'a ());

impl<'a> T for S<'a> {}

fn foo() -> impl T {
let x = ();
S(&x) //~ ERROR `x` does not live long enough
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0597]: `x` does not live long enough
--> $DIR/do-not-suggest-adding-bound-to-opaque-type.rs:9:7
|
LL | S(&x)
| --^^-
| | |
| | borrowed value does not live long enough
| opaque type requires that `x` is borrowed for `'static`
LL | }
| - `x` dropped here while still borrowed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.