-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for generic associated type bounds
- Loading branch information
1 parent
d785c8c
commit eeb82e4
Showing
9 changed files
with
190 additions
and
76 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/test/ui/generic-associated-types/generic-associated-type-bounds.rs
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,35 @@ | ||
// run-pass | ||
|
||
#![allow(incomplete_features)] | ||
#![feature(generic_associated_types)] | ||
|
||
pub trait X { | ||
type Y<'a>; | ||
fn m(&self) -> Self::Y<'_>; | ||
} | ||
|
||
impl X for () { | ||
type Y<'a> = &'a (); | ||
|
||
fn m(&self) -> Self::Y<'_> { | ||
self | ||
} | ||
} | ||
|
||
fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &() { | ||
x.m() | ||
} | ||
|
||
fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &() { | ||
x.m() | ||
} | ||
|
||
fn h(x: &()) -> &() { | ||
x.m() | ||
} | ||
|
||
fn main() { | ||
f(&()); | ||
g(&()); | ||
h(&()); | ||
} |
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
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
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
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
36 changes: 36 additions & 0 deletions
36
src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.rs
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,36 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(generic_associated_types)] | ||
|
||
pub trait X { | ||
type Y<'a>; | ||
fn m(&self) -> Self::Y<'_>; | ||
} | ||
|
||
impl X for () { | ||
type Y<'a> = &'a (); | ||
|
||
fn m(&self) -> Self::Y<'_> { | ||
self | ||
} | ||
} | ||
|
||
fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &'static () { | ||
x.m() | ||
//~^ ERROR explicit lifetime required | ||
} | ||
|
||
fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &'static () { | ||
x.m() | ||
//~^ ERROR explicit lifetime required | ||
} | ||
|
||
fn h(x: &()) -> &'static () { | ||
x.m() | ||
//~^ ERROR explicit lifetime required | ||
} | ||
|
||
fn main() { | ||
f(&()); | ||
g(&()); | ||
h(&()); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/ui/generic-associated-types/projection-type-lifetime-mismatch.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,27 @@ | ||
error[E0621]: explicit lifetime required in the type of `x` | ||
--> $DIR/projection-type-lifetime-mismatch.rs:18:5 | ||
| | ||
LL | fn f(x: &impl for<'a> X<Y<'a> = &'a ()>) -> &'static () { | ||
| ------------------------------- help: add explicit lifetime `'static` to the type of `x`: `&'static impl for<'a> X<Y<'a> = &'a ()>` | ||
LL | x.m() | ||
| ^^^^^ lifetime `'static` required | ||
|
||
error[E0621]: explicit lifetime required in the type of `x` | ||
--> $DIR/projection-type-lifetime-mismatch.rs:23:5 | ||
| | ||
LL | fn g<T: for<'a> X<Y<'a> = &'a ()>>(x: &T) -> &'static () { | ||
| -- help: add explicit lifetime `'static` to the type of `x`: `&'static T` | ||
LL | x.m() | ||
| ^^^^^ lifetime `'static` required | ||
|
||
error[E0621]: explicit lifetime required in the type of `x` | ||
--> $DIR/projection-type-lifetime-mismatch.rs:28:5 | ||
| | ||
LL | fn h(x: &()) -> &'static () { | ||
| --- help: add explicit lifetime `'static` to the type of `x`: `&'static ()` | ||
LL | x.m() | ||
| ^^^^^ lifetime `'static` required | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0621`. |
28 changes: 28 additions & 0 deletions
28
src/test/ui/generic-associated-types/unsatified-item-lifetime-bound.rs
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,28 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(generic_associated_types)] | ||
|
||
pub trait X { | ||
type Y<'a: 'static>; | ||
//~^ WARNING unnecessary lifetime parameter | ||
} | ||
|
||
impl X for () { | ||
type Y<'a> = &'a (); | ||
} | ||
|
||
struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> { | ||
f: <T as X>::Y<'a>, | ||
//~^ ERROR lifetime bound not satisfied | ||
} | ||
|
||
struct C<'a, T: X> { | ||
f: <T as X>::Y<'a>, | ||
//~^ ERROR lifetime bound not satisfied | ||
} | ||
|
||
struct D<'a> { | ||
f: <() as X>::Y<'a>, | ||
//~^ ERROR lifetime bound not satisfied | ||
} | ||
|
||
fn main() {} |
50 changes: 50 additions & 0 deletions
50
src/test/ui/generic-associated-types/unsatified-item-lifetime-bound.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,50 @@ | ||
warning: unnecessary lifetime parameter `'a` | ||
--> $DIR/unsatified-item-lifetime-bound.rs:5:12 | ||
| | ||
LL | type Y<'a: 'static>; | ||
| ^^^^^^^^^^^ | ||
| | ||
= help: you can use the `'static` lifetime directly, in place of `'a` | ||
|
||
error[E0478]: lifetime bound not satisfied | ||
--> $DIR/unsatified-item-lifetime-bound.rs:14:8 | ||
| | ||
LL | f: <T as X>::Y<'a>, | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 13:10 | ||
--> $DIR/unsatified-item-lifetime-bound.rs:13:10 | ||
| | ||
LL | struct B<'a, T: for<'r> X<Y<'r> = &'r ()>> { | ||
| ^^ | ||
= note: but lifetime parameter must outlive the static lifetime | ||
|
||
error[E0478]: lifetime bound not satisfied | ||
--> $DIR/unsatified-item-lifetime-bound.rs:19:8 | ||
| | ||
LL | f: <T as X>::Y<'a>, | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 18:10 | ||
--> $DIR/unsatified-item-lifetime-bound.rs:18:10 | ||
| | ||
LL | struct C<'a, T: X> { | ||
| ^^ | ||
= note: but lifetime parameter must outlive the static lifetime | ||
|
||
error[E0478]: lifetime bound not satisfied | ||
--> $DIR/unsatified-item-lifetime-bound.rs:24:8 | ||
| | ||
LL | f: <() as X>::Y<'a>, | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined on the struct at 23:10 | ||
--> $DIR/unsatified-item-lifetime-bound.rs:23:10 | ||
| | ||
LL | struct D<'a> { | ||
| ^^ | ||
= note: but lifetime parameter must outlive the static lifetime | ||
|
||
error: aborting due to 3 previous errors; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0478`. |