Rollup merge of #100940 - TaKO8Ki:do-not-suggest-adding-bound-to-opaque-type, r=fee1-dead

Do not suggest adding a bound to a opaque type

fixes #100442
This commit is contained in:
Matthias Krüger 2022-08-24 18:20:20 +02:00 committed by GitHub
commit 75b1b69171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -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 };

View File

@ -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() {}

View File

@ -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`.