Skip to content

Commit eb6d6f9

Browse files
committed
Add tests for some cases mentioned in #135589
1 parent 03eb454 commit eb6d6f9

8 files changed

+132
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct S;
2+
struct T;
3+
4+
impl<'a> IntoIterator for &S {
5+
//~^ ERROR E0207
6+
//~| NOTE unconstrained lifetime parameter
7+
type Item = &T;
8+
//~^ ERROR in the trait associated type
9+
//~| NOTE this lifetime must come from the implemented type
10+
type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
11+
12+
fn into_iter(self) -> Self::IntoIter {
13+
todo!()
14+
}
15+
}
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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
3+
|
4+
LL | type Item = &T;
5+
| ^ this lifetime must come from the implemented type
6+
7+
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
8+
--> $DIR/missing-lifetime-in-assoc-type-1.rs:4:6
9+
|
10+
LL | impl<'a> IntoIterator for &S {
11+
| ^^ unconstrained lifetime parameter
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0207`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct S;
2+
struct T;
3+
4+
impl IntoIterator for &S {
5+
type Item = &T;
6+
//~^ ERROR in the trait associated type
7+
type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
8+
//~^ ERROR use of undeclared lifetime name `'a`
9+
10+
fn into_iter(self) -> Self::IntoIter {
11+
todo!()
12+
}
13+
}
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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-2.rs:5:17
3+
|
4+
LL | type Item = &T;
5+
| ^ this lifetime must come from the implemented type
6+
7+
error[E0261]: use of undeclared lifetime name `'a`
8+
--> $DIR/missing-lifetime-in-assoc-type-2.rs:7:57
9+
|
10+
LL | type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
11+
| ^^ undeclared lifetime
12+
|
13+
help: consider introducing lifetime `'a` here
14+
|
15+
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
16+
| ++++
17+
help: consider introducing lifetime `'a` here
18+
|
19+
LL | impl<'a> IntoIterator for &S {
20+
| ++++
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0261`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct S;
2+
struct T;
3+
4+
impl IntoIterator for &S {
5+
type Item = &T;
6+
//~^ ERROR in the trait associated type
7+
type IntoIter = std::collections::btree_map::Values<i32, T>;
8+
//~^ ERROR missing lifetime specifier
9+
10+
fn into_iter(self) -> Self::IntoIter {
11+
todo!()
12+
}
13+
}
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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-3.rs:5:17
3+
|
4+
LL | type Item = &T;
5+
| ^ this lifetime must come from the implemented type
6+
7+
error[E0106]: missing lifetime specifier
8+
--> $DIR/missing-lifetime-in-assoc-type-3.rs:7:56
9+
|
10+
LL | type IntoIter = std::collections::btree_map::Values<i32, T>;
11+
| ^ expected named lifetime parameter
12+
|
13+
help: consider introducing a named lifetime parameter
14+
|
15+
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
16+
| ++++ +++
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0106`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct S;
2+
struct T;
3+
4+
impl IntoIterator for &S {
5+
type Item = &T;
6+
//~^ ERROR in the trait associated type
7+
type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
8+
//~^ ERROR lifetime parameters or bounds on type `IntoIter` do not match the trait declaration
9+
10+
fn into_iter(self) -> Self::IntoIter {
11+
todo!()
12+
}
13+
}
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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-4.rs:5:17
3+
|
4+
LL | type Item = &T;
5+
| ^ this lifetime must come from the implemented type
6+
7+
error[E0195]: lifetime parameters or bounds on type `IntoIter` do not match the trait declaration
8+
--> $DIR/missing-lifetime-in-assoc-type-4.rs:7:18
9+
|
10+
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
11+
| ^^^^ lifetimes do not match type in trait
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0195`.

0 commit comments

Comments
 (0)