Skip to content

Commit

Permalink
Rollup merge of #100940 - TaKO8Ki:do-not-suggest-adding-bound-to-opaq…
Browse files Browse the repository at this point in the history
…ue-type, r=fee1-dead

Do not suggest adding a bound to a opaque type

fixes #100442
  • Loading branch information
matthiaskrgr authored Aug 24, 2022
2 parents a0fbfd8 + c57ecfa commit 75b1b69
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ impl<'tcx> BorrowExplanation<'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`.

0 comments on commit 75b1b69

Please sign in to comment.