Skip to content

Commit 64d11fc

Browse files
committed
Clarify some diagnostic messages
1 parent 5cd3cc1 commit 64d11fc

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2940,8 +2940,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29402940
// though we can easily give a hint that ought to be
29412941
// relevant.
29422942
err.note(
2943-
"lifetimes appearing in an associated type are not considered constrained",
2943+
"lifetimes appearing in an associated or opaque type are not considered constrained",
29442944
);
2945+
err.note("consider introducing a named lifetime parameter");
29452946
}
29462947

29472948
err.emit();

src/test/ui/associated-types/issue-62200.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl T<'_> for S {
1010

1111
fn foo(x: impl Fn(<S as T<'_>>::A) -> <S as T<'_>>::A) {}
1212
//~^ ERROR binding for associated type `Output` references an anonymous lifetime
13-
//~^^ NOTE lifetimes appearing in an associated type are not considered constrained
13+
//~| NOTE lifetimes appearing in an associated or opaque type are not considered constrained
14+
//~| NOTE consider introducing a named lifetime parameter
1415

1516
fn main() {}

src/test/ui/associated-types/issue-62200.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0582]: binding for associated type `Output` references an anonymous lifet
44
LL | fn foo(x: impl Fn(<S as T<'_>>::A) -> <S as T<'_>>::A) {}
55
| ^^^^^^^^^^^^^^^
66
|
7-
= note: lifetimes appearing in an associated type are not considered constrained
7+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
8+
= note: consider introducing a named lifetime parameter
89

910
error: aborting due to previous error
1011

src/test/ui/issues/issue-47511.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error[E0581]: return type references an anonymous lifetime, which is not constra
44
LL | fn f(_: X) -> X {
55
| ^
66
|
7-
= note: lifetimes appearing in an associated type are not considered constrained
7+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
8+
= note: consider introducing a named lifetime parameter
89

910
error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
1011
--> $DIR/issue-47511.rs:12:23

src/test/ui/type-alias-impl-trait/constrain_inputs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ mod lifetime_params {
1212
//~^ ERROR binding for associated type `Output` references an anonymous lifetime
1313
}
1414

15-
mod type_params {
15+
mod lifetime_params_2 {
1616
type Ty<'a> = impl FnOnce() -> &'a str;
1717
fn defining(s: &str) -> Ty<'_> { move || s }
1818
fn execute(ty: Ty<'_>) -> &str { ty() }
1919
//~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types
2020
}
2121

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

src/test/ui/type-alias-impl-trait/constrain_inputs.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,53 @@ error[E0581]: return type references an anonymous lifetime, which is not constra
44
LL | fn execute(ty: Ty<'_>) -> &str { todo!() }
55
| ^^^^
66
|
7-
= note: lifetimes appearing in an associated type are not considered constrained
7+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
8+
= note: consider introducing a named lifetime parameter
89

910
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
1011
--> $DIR/constrain_inputs.rs:9:35
1112
|
1213
LL | type BadFnSig = fn(Ty<'_>) -> &str;
1314
| ^^^^
1415
|
15-
= note: lifetimes appearing in an associated type are not considered constrained
16+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
17+
= note: consider introducing a named lifetime parameter
1618

1719
error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types
1820
--> $DIR/constrain_inputs.rs:11:42
1921
|
2022
LL | type BadTraitRef = dyn Fn(Ty<'_>) -> &str;
2123
| ^^^^
2224
|
23-
= note: lifetimes appearing in an associated type are not considered constrained
25+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
26+
= note: consider introducing a named lifetime parameter
2427

2528
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
2629
--> $DIR/constrain_inputs.rs:18:31
2730
|
2831
LL | fn execute(ty: Ty<'_>) -> &str { ty() }
2932
| ^^^^
3033
|
31-
= note: lifetimes appearing in an associated type are not considered constrained
34+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
35+
= note: consider introducing a named lifetime parameter
3236

3337
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
3438
--> $DIR/constrain_inputs.rs:27:37
3539
|
3640
LL | type BadFnSig = fn(Ty<&str>) -> &str;
3741
| ^^^^
3842
|
39-
= note: lifetimes appearing in an associated type are not considered constrained
43+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
44+
= note: consider introducing a named lifetime parameter
4045

4146
error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types
4247
--> $DIR/constrain_inputs.rs:29:44
4348
|
4449
LL | type BadTraitRef = dyn Fn(Ty<&str>) -> &str;
4550
| ^^^^
4651
|
47-
= note: lifetimes appearing in an associated type are not considered constrained
52+
= note: lifetimes appearing in an associated or opaque type are not considered constrained
53+
= note: consider introducing a named lifetime parameter
4854

4955
error: aborting due to 6 previous errors
5056

0 commit comments

Comments
 (0)