From 64d11fc8e336344a8b8a55a55131ded4be26cebd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 25 Aug 2022 10:30:46 +0000 Subject: [PATCH] Clarify some diagnostic messages --- compiler/rustc_typeck/src/astconv/mod.rs | 3 ++- src/test/ui/associated-types/issue-62200.rs | 3 ++- .../ui/associated-types/issue-62200.stderr | 3 ++- src/test/ui/issues/issue-47511.stderr | 3 ++- .../type-alias-impl-trait/constrain_inputs.rs | 4 ++-- .../constrain_inputs.stderr | 18 ++++++++++++------ 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 801063583e633..d66cf6d099ad5 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -2940,8 +2940,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // though we can easily give a hint that ought to be // relevant. err.note( - "lifetimes appearing in an associated type are not considered constrained", + "lifetimes appearing in an associated or opaque type are not considered constrained", ); + err.note("consider introducing a named lifetime parameter"); } err.emit(); diff --git a/src/test/ui/associated-types/issue-62200.rs b/src/test/ui/associated-types/issue-62200.rs index 9d18690e96049..499bbd6b6fad2 100644 --- a/src/test/ui/associated-types/issue-62200.rs +++ b/src/test/ui/associated-types/issue-62200.rs @@ -10,6 +10,7 @@ impl T<'_> for S { fn foo(x: impl Fn(>::A) -> >::A) {} //~^ ERROR binding for associated type `Output` references an anonymous lifetime -//~^^ NOTE lifetimes appearing in an associated type are not considered constrained +//~| NOTE lifetimes appearing in an associated or opaque type are not considered constrained +//~| NOTE consider introducing a named lifetime parameter fn main() {} diff --git a/src/test/ui/associated-types/issue-62200.stderr b/src/test/ui/associated-types/issue-62200.stderr index f14cd81fdfe1f..04f0728f58ea8 100644 --- a/src/test/ui/associated-types/issue-62200.stderr +++ b/src/test/ui/associated-types/issue-62200.stderr @@ -4,7 +4,8 @@ error[E0582]: binding for associated type `Output` references an anonymous lifet LL | fn foo(x: impl Fn(>::A) -> >::A) {} | ^^^^^^^^^^^^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error: aborting due to previous error diff --git a/src/test/ui/issues/issue-47511.stderr b/src/test/ui/issues/issue-47511.stderr index 5b84f7ed62c3a..9998ee0e8d0c6 100644 --- a/src/test/ui/issues/issue-47511.stderr +++ b/src/test/ui/issues/issue-47511.stderr @@ -4,7 +4,8 @@ error[E0581]: return type references an anonymous lifetime, which is not constra LL | fn f(_: X) -> X { | ^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types --> $DIR/issue-47511.rs:12:23 diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs.rs b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs index 1300a2e45d57d..03fb64b7b94d7 100644 --- a/src/test/ui/type-alias-impl-trait/constrain_inputs.rs +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs @@ -12,7 +12,7 @@ mod lifetime_params { //~^ ERROR binding for associated type `Output` references an anonymous lifetime } -mod type_params { +mod lifetime_params_2 { type Ty<'a> = impl FnOnce() -> &'a str; fn defining(s: &str) -> Ty<'_> { move || s } fn execute(ty: Ty<'_>) -> &str { ty() } @@ -20,7 +20,7 @@ mod type_params { } // regression test for https://github.com/rust-lang/rust/issues/97104 -mod type_params2 { +mod type_params { type Ty = impl Sized; fn define(s: T) -> Ty { s } diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr b/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr index c35b55df64380..93953fd06d1fd 100644 --- a/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs.stderr @@ -4,7 +4,8 @@ error[E0581]: return type references an anonymous lifetime, which is not constra LL | fn execute(ty: Ty<'_>) -> &str { todo!() } | ^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types --> $DIR/constrain_inputs.rs:9:35 @@ -12,7 +13,8 @@ error[E0581]: return type references an anonymous lifetime, which is not constra LL | type BadFnSig = fn(Ty<'_>) -> &str; | ^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types --> $DIR/constrain_inputs.rs:11:42 @@ -20,7 +22,8 @@ error[E0582]: binding for associated type `Output` references an anonymous lifet LL | type BadTraitRef = dyn Fn(Ty<'_>) -> &str; | ^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types --> $DIR/constrain_inputs.rs:18:31 @@ -28,7 +31,8 @@ error[E0581]: return type references an anonymous lifetime, which is not constra LL | fn execute(ty: Ty<'_>) -> &str { ty() } | ^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types --> $DIR/constrain_inputs.rs:27:37 @@ -36,7 +40,8 @@ error[E0581]: return type references an anonymous lifetime, which is not constra LL | type BadFnSig = fn(Ty<&str>) -> &str; | ^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types --> $DIR/constrain_inputs.rs:29:44 @@ -44,7 +49,8 @@ error[E0582]: binding for associated type `Output` references an anonymous lifet LL | type BadTraitRef = dyn Fn(Ty<&str>) -> &str; | ^^^^ | - = note: lifetimes appearing in an associated type are not considered constrained + = note: lifetimes appearing in an associated or opaque type are not considered constrained + = note: consider introducing a named lifetime parameter error: aborting due to 6 previous errors