forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for some cases mentioned in rust-lang#135589
- Loading branch information
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
tests/ui/lifetimes/missing-lifetime-in-assoc-type-1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
tests/ui/lifetimes/missing-lifetime-in-assoc-type-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
tests/ui/lifetimes/missing-lifetime-in-assoc-type-3.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
tests/ui/lifetimes/missing-lifetime-in-assoc-type-4.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |