Skip to content

Commit

Permalink
Add tests for some cases mentioned in rust-lang#135589
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 7, 2025
1 parent 03eb454 commit eb6d6f9
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct S;
struct T;

impl<'a> IntoIterator for &S {
//~^ ERROR E0207
//~| NOTE unconstrained lifetime parameter
type Item = &T;
//~^ ERROR in the trait associated type
//~| NOTE this lifetime must come from the implemented type
type IntoIter = std::collections::btree_map::Values<'a, i32, T>;

fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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:7:17
|
LL | type Item = &T;
| ^ this lifetime must come from the implemented type

error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
--> $DIR/missing-lifetime-in-assoc-type-1.rs:4:6
|
LL | impl<'a> IntoIterator for &S {
| ^^ unconstrained lifetime parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0207`.
14 changes: 14 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct S;
struct T;

impl IntoIterator for &S {
type Item = &T;
//~^ ERROR in the trait associated type
type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
//~^ ERROR use of undeclared lifetime name `'a`

fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
fn main() {}
24 changes: 24 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 | type Item = &T;
| ^ this lifetime must come from the implemented type

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/missing-lifetime-in-assoc-type-2.rs:7:57
|
LL | type IntoIter = std::collections::btree_map::Values<'a, i32, T>;
| ^^ undeclared lifetime
|
help: consider introducing lifetime `'a` here
|
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
| ++++
help: consider introducing lifetime `'a` here
|
LL | impl<'a> IntoIterator for &S {
| ++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0261`.
14 changes: 14 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct S;
struct T;

impl IntoIterator for &S {
type Item = &T;
//~^ ERROR in the trait associated type
type IntoIter = std::collections::btree_map::Values<i32, T>;
//~^ ERROR missing lifetime specifier

fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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-3.rs:5:17
|
LL | type Item = &T;
| ^ this lifetime must come from the implemented type

error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-type-3.rs:7:56
|
LL | type IntoIter = std::collections::btree_map::Values<i32, T>;
| ^ expected named lifetime parameter
|
help: consider introducing a named lifetime parameter
|
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
| ++++ +++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0106`.
14 changes: 14 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
struct S;
struct T;

impl IntoIterator for &S {
type Item = &T;
//~^ ERROR in the trait associated type
type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
//~^ ERROR lifetime parameters or bounds on type `IntoIter` do not match the trait declaration

fn into_iter(self) -> Self::IntoIter {
todo!()
}
}
fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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-4.rs:5:17
|
LL | type Item = &T;
| ^ this lifetime must come from the implemented type

error[E0195]: lifetime parameters or bounds on type `IntoIter` do not match the trait declaration
--> $DIR/missing-lifetime-in-assoc-type-4.rs:7:18
|
LL | type IntoIter<'a> = std::collections::btree_map::Values<'a, i32, T>;
| ^^^^ lifetimes do not match type in trait

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0195`.

0 comments on commit eb6d6f9

Please sign in to comment.