You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tweak wording in associated type with anon lifetime error
Move the previous long message to a note and use a shorter primary message:
```
error: missing lifetime in associated type
--> $DIR/missing-lifetime-in-assoc-type-1.rs:9:17
|
LL | impl<'a> IntoIterator for &S {
| ---- there is a named lifetime specified on the impl block you could use
...
LL | type Item = &T;
| ^ this lifetime must come from the implemented type
|
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
help: consider using the lifetime from the impl block
|
LL | type Item = &'a T;
| ++
```
Copy file name to clipboardExpand all lines: compiler/rustc_resolve/messages.ftl
+2-2
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,9 @@ resolve_added_macro_use =
11
11
resolve_ancestor_only =
12
12
visibilities can only be restricted to ancestor modules
13
13
14
-
resolve_anonymous_lifetime_non_gat_report_error =
15
-
in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
14
+
resolve_anonymous_lifetime_non_gat_report_error = missing lifetime in associated type
16
15
.label = this lifetime must come from the implemented type
16
+
.note = in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
17
17
18
18
resolve_arguments_macro_use_not_allowed = arguments to `macro_use` are not allowed here
Copy file name to clipboardExpand all lines: tests/ui/impl-header-lifetime-elision/assoc-type.rs
+3-3
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ trait MyTrait {
9
9
10
10
implMyTraitfor&i32{
11
11
typeOutput = &i32;
12
-
//~^ ERROR in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
12
+
//~^ ERROR missing lifetime in associated type
13
13
}
14
14
15
15
implMyTraitfor&u32{
@@ -19,15 +19,15 @@ impl MyTrait for &u32 {
19
19
20
20
impl<'a>MyTraitfor&f64{
21
21
typeOutput = &f64;
22
-
//~^ ERROR in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
22
+
//~^ ERROR missing lifetime in associated type
23
23
}
24
24
25
25
traitOtherTrait<'a>{
26
26
typeOutput;
27
27
}
28
28
implOtherTrait<'_>forf64{
29
29
typeOutput = &f64;
30
-
//~^ ERROR in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/impl-header-lifetime-elision/assoc-type.stderr
+6-3
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
1
+
error: missing lifetime in associated type
2
2
--> $DIR/assoc-type.rs:11:19
3
3
|
4
4
LL | type Output = &i32;
5
5
| ^ this lifetime must come from the implemented type
6
6
|
7
+
= note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
7
8
help: add a lifetime to the impl block and use it in the self type and associated type
8
9
|
9
10
LL ~ impl<'a> MyTrait for &'a i32 {
@@ -16,25 +17,27 @@ error[E0637]: `'_` cannot be used here
16
17
LL | type Output = &'_ i32;
17
18
| ^^ `'_` is a reserved lifetime name
18
19
19
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
20
+
error: missing lifetime in associated type
20
21
--> $DIR/assoc-type.rs:21:19
21
22
|
22
23
LL | impl<'a> MyTrait for &f64 {
23
24
| ---- there is a named lifetime specified on the impl block you could use
24
25
LL | type Output = &f64;
25
26
| ^ this lifetime must come from the implemented type
26
27
|
28
+
= note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
27
29
help: consider using the lifetime from the impl block
28
30
|
29
31
LL | type Output = &'a f64;
30
32
| ++
31
33
32
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
34
+
error: missing lifetime in associated type
33
35
--> $DIR/assoc-type.rs:29:19
34
36
|
35
37
LL | type Output = &f64;
36
38
| ^ this lifetime must come from the implemented type
37
39
|
40
+
= note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
38
41
help: add a lifetime to the impl block and use it in the trait and associated type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.stderr
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
| ^ this lifetime must come from the implemented type
9
9
|
10
+
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
1
+
error: missing lifetime in associated type
2
2
--> $DIR/missing-lifetime-in-assoc-type-2.rs:5:17
3
3
|
4
4
LL | type Item = &T;
5
5
| ^ this lifetime must come from the implemented type
6
6
|
7
+
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.stderr
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
1
+
error: missing lifetime in associated type
2
2
--> $DIR/missing-lifetime-in-assoc-type-3.rs:5:17
3
3
|
4
4
LL | type Item = &T;
5
5
| ^ this lifetime must come from the implemented type
6
6
|
7
+
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
1
+
error: missing lifetime in associated type
2
2
--> $DIR/missing-lifetime-in-assoc-type-4.rs:5:17
3
3
|
4
4
LL | type Item = &T;
5
5
| ^ this lifetime must come from the implemented type
6
6
|
7
+
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-5.stderr
+3-1
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
1
+
error: missing lifetime in associated type
2
2
--> $DIR/missing-lifetime-in-assoc-type-5.rs:9:17
3
3
|
4
4
LL | impl<'a> IntoIterator for &'_ S {
@@ -7,6 +7,8 @@ LL | impl<'a> IntoIterator for &'_ S {
7
7
LL | type Item = &T;
8
8
| ^ this lifetime must come from the implemented type
9
9
|
10
+
note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
| ---- there is a named lifetime specified on the impl block you could use
6
+
...
7
+
LL | type Item = &T;
8
+
| ^ this lifetime must come from the implemented type
9
+
|
10
+
= note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
11
+
help: consider using the lifetime from the impl block
12
+
|
13
+
LL | type Item = &'a T;
14
+
| ++
15
+
16
+
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
17
+
--> $DIR/missing-lifetime-in-assoc-type-6.rs:11:6
18
+
|
19
+
LL | impl<'a> Trait for &'_ S {
20
+
| ^^ unconstrained lifetime parameter
21
+
|
22
+
help: consider using the named lifetime here instead of an implict lifetime
23
+
|
24
+
LL | impl<'a> Trait for &'a S {
25
+
| ~~
26
+
27
+
error: aborting due to 2 previous errors
28
+
29
+
For more information about this error, try `rustc --explain E0207`.
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/no_lending_iterators.rs
+2-2
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ trait Bar {
16
16
17
17
implBarforusize{
18
18
typeItem = &usize;
19
-
//~^ ERROR 18:17: 18:18: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
19
+
//~^ ERROR missing lifetime in associated type
20
20
21
21
fnpoke(&mutself,item:Self::Item){
22
22
self += *item;
@@ -25,7 +25,7 @@ impl Bar for usize {
25
25
26
26
implBarforisize{
27
27
typeItem<'a> = &'aisize;
28
-
//~^ ERROR 27:14: 27:18: lifetime parameters or bounds on type `Item` do not match the trait declaration [E0195]
28
+
//~^ ERROR lifetime parameters or bounds on type `Item` do not match the trait declaration [E0195]
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/no_lending_iterators.stderr
+3-1
Original file line number
Diff line number
Diff line change
@@ -10,13 +10,15 @@ note: you can't create an `Iterator` that borrows each `Item` from itself, but y
10
10
LL | impl Iterator for Data {
11
11
| ^^^^
12
12
13
-
error: in the trait associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
13
+
error: missing lifetime in associated type
14
14
--> $DIR/no_lending_iterators.rs:18:17
15
15
|
16
16
LL | impl Bar for usize {
17
17
| - you could add a lifetime on the impl block, if the trait or the self type could have one
18
18
LL | type Item = &usize;
19
19
| ^ this lifetime must come from the implemented type
20
+
|
21
+
= note: in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type
20
22
21
23
error[E0195]: lifetime parameters or bounds on type `Item` do not match the trait declaration
0 commit comments