-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imply outlives-bounds on lazy type aliases
- Loading branch information
Showing
6 changed files
with
128 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
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
12 changes: 12 additions & 0 deletions
12
tests/ui/lazy-type-alias/dont-imply-implied-outlives-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,12 @@ | ||
// Ensure that we don't imply the *implied* outlives-bounds of weak aliases. | ||
// For context, we only imply the explicit bounds. | ||
#![feature(lazy_type_alias)] | ||
#![allow(incomplete_features)] | ||
|
||
type Alias<'a, T> = &'a T; // implied bound `T: 'a` | ||
|
||
struct Outer0<'a, T>(Alias<'a, T>); //~ ERROR the parameter type `T` may not live long enough | ||
|
||
type Outer1<'a, T> = Alias<'a, T>; //~ ERROR the parameter type `T` may not live long enough | ||
|
||
fn main() {} |
29 changes: 29 additions & 0 deletions
29
tests/ui/lazy-type-alias/dont-imply-implied-outlives-bounds.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,29 @@ | ||
error[E0309]: the parameter type `T` may not live long enough | ||
--> $DIR/dont-imply-implied-outlives-bounds.rs:8:22 | ||
| | ||
LL | struct Outer0<'a, T>(Alias<'a, T>); | ||
| -- ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds | ||
| | | ||
| the parameter type `T` must be valid for the lifetime `'a` as defined here... | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | struct Outer0<'a, T: 'a>(Alias<'a, T>); | ||
| ++++ | ||
|
||
error[E0309]: the parameter type `T` may not live long enough | ||
--> $DIR/dont-imply-implied-outlives-bounds.rs:10:22 | ||
| | ||
LL | type Outer1<'a, T> = Alias<'a, T>; | ||
| -- ^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds | ||
| | | ||
| the parameter type `T` must be valid for the lifetime `'a` as defined here... | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | type Outer1<'a, T: 'a> = Alias<'a, T>; | ||
| ++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0309`. |
26 changes: 26 additions & 0 deletions
26
tests/ui/lazy-type-alias/implied-outlives-bounds.neg.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,26 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/implied-outlives-bounds.rs:18:12 | ||
| | ||
LL | fn env0<'any>() { | ||
| ---- lifetime `'any` defined here | ||
LL | let _: TypeOutlives<'static, &'any ()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'any` must outlive `'static` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/implied-outlives-bounds.rs:23:12 | ||
| | ||
LL | fn env1<'any>() { | ||
| ---- lifetime `'any` defined here | ||
LL | let _: RegionOutlives<'static, 'any>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'any` must outlive `'static` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/implied-outlives-bounds.rs:28:12 | ||
| | ||
LL | fn env2<'any>() { | ||
| ---- lifetime `'any` defined here | ||
LL | let _: Outer0<'static, &'any ()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'any` must outlive `'static` | ||
|
||
error: aborting due to 3 previous errors | ||
|
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,31 @@ | ||
// Check that we imply outlives-bounds on lazy type aliases. | ||
|
||
// revisions: pos neg | ||
//[pos] check-pass | ||
|
||
#![feature(lazy_type_alias)] | ||
#![allow(incomplete_features)] | ||
|
||
type TypeOutlives<'a, T> = &'a T; | ||
type RegionOutlives<'a, 'b> = &'a &'b (); | ||
|
||
// Ensure that we imply `T: 'a` from the explicit predicates of the weak alias `Alias`. | ||
struct Outer0<'a, T>(Alias<'a, T>); | ||
type Alias<'a, T: 'a> = &'a T; | ||
|
||
#[cfg(neg)] | ||
fn env0<'any>() { | ||
let _: TypeOutlives<'static, &'any ()>; //[neg]~ ERROR lifetime may not live long enough | ||
} | ||
|
||
#[cfg(neg)] | ||
fn env1<'any>() { | ||
let _: RegionOutlives<'static, 'any>; //[neg]~ ERROR lifetime may not live long enough | ||
} | ||
|
||
#[cfg(neg)] | ||
fn env2<'any>() { | ||
let _: Outer0<'static, &'any ()>; //[neg]~ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() {} |