Add tests for some cases mentioned in #135589
This commit is contained in:
parent
51f5892019
commit
2e01acc59e
8 changed files with 132 additions and 0 deletions
16
tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.rs
Normal file
16
tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.rs
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.stderr
Normal file
15
tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.stderr
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.rs
Normal file
14
tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.rs
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr
Normal file
24
tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.rs
Normal file
14
tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.rs
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.stderr
Normal file
20
tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.stderr
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs
Normal file
14
tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.rs
Normal file
|
|
@ -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
tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr
Normal file
15
tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue