Skip to content

Commit

Permalink
Clarify some diagnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 8, 2022
1 parent 5cd3cc1 commit 64d11fc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/associated-types/issue-62200.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl T<'_> for S {

fn foo(x: impl Fn(<S as T<'_>>::A) -> <S as T<'_>>::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() {}
3 changes: 2 additions & 1 deletion src/test/ui/associated-types/issue-62200.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ error[E0582]: binding for associated type `Output` references an anonymous lifet
LL | fn foo(x: impl Fn(<S as T<'_>>::A) -> <S as T<'_>>::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

Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-47511.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/type-alias-impl-trait/constrain_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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() }
//~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types
}

// regression test for https://github.com/rust-lang/rust/issues/97104
mod type_params2 {
mod type_params {
type Ty<T> = impl Sized;
fn define<T>(s: T) -> Ty<T> { s }

Expand Down
18 changes: 12 additions & 6 deletions src/test/ui/type-alias-impl-trait/constrain_inputs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,53 @@ 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
|
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
|
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
|
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
|
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
|
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

Expand Down

0 comments on commit 64d11fc

Please sign in to comment.