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
When an associated type is missing a lifetime, point at its enclosing `impl`, whether it has or doesn't have lifetimes defined. If it does have a lifetime, suggest using it.
```
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
--> $DIR/missing-lifetime-in-assoc-type-1.rs:8: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
|
help: consider using the lifetime from the impl block
|
LL | type Item = &'a T;
| ++
```
```
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
--> $DIR/missing-lifetime-in-assoc-type-2.rs:5:17
|
LL | impl IntoIterator for &S {
| - you could add a lifetime on the impl block, if the trait or the self type can have one
LL | type Item = &T;
| ^ this lifetime must come from the implemented type
```
Copy file name to clipboardExpand all lines: tests/ui/impl-header-lifetime-elision/assoc-type.stderr
+2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
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
2
2
--> $DIR/assoc-type.rs:11:19
3
3
|
4
+
LL | impl MyTrait for &i32 {
5
+
| - you could add a lifetime on the impl block, if the trait or the self type can have one
4
6
LL | type Output = &i32;
5
7
| ^ this lifetime must come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.stderr
+9-1
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,16 @@
1
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
2
-
--> $DIR/missing-lifetime-in-assoc-type-1.rs:7:17
2
+
--> $DIR/missing-lifetime-in-assoc-type-1.rs:8:17
3
3
|
4
+
LL | impl<'a> IntoIterator for &S {
5
+
| ---- there is a named lifetime specified on the impl block you could use
6
+
...
4
7
LL | type Item = &T;
5
8
| ^ this lifetime must come from the implemented type
9
+
|
10
+
help: consider using the lifetime from the impl block
11
+
|
12
+
LL | type Item = &'a T;
13
+
| ++
6
14
7
15
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr
+2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
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
2
2
--> $DIR/missing-lifetime-in-assoc-type-2.rs:5:17
3
3
|
4
+
LL | impl IntoIterator for &S {
5
+
| - you could add a lifetime on the impl block, if the trait or the self type can have one
4
6
LL | type Item = &T;
5
7
| ^ this lifetime must come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.stderr
+2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
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
2
2
--> $DIR/missing-lifetime-in-assoc-type-3.rs:5:17
3
3
|
4
+
LL | impl IntoIterator for &S {
5
+
| - you could add a lifetime on the impl block, if the trait or the self type can have one
4
6
LL | type Item = &T;
5
7
| ^ this lifetime must come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr
+2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
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
2
2
--> $DIR/missing-lifetime-in-assoc-type-4.rs:5:17
3
3
|
4
+
LL | impl IntoIterator for &S {
5
+
| - you could add a lifetime on the impl block, if the trait or the self type can have one
4
6
LL | type Item = &T;
5
7
| ^ this lifetime must come from the implemented type
Copy file name to clipboardExpand all lines: tests/ui/lifetimes/no_lending_iterators.stderr
+2
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@ LL | impl Iterator for Data {
13
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
14
14
--> $DIR/no_lending_iterators.rs:18:17
15
15
|
16
+
LL | impl Bar for usize {
17
+
| - you could add a lifetime on the impl block, if the trait or the self type can have one
16
18
LL | type Item = &usize;
17
19
| ^ this lifetime must come from the implemented type
0 commit comments