-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that opaque types can't have themselves as a hidden type with in…
…compatible lifetimes
- Loading branch information
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
tests/ui/type-alias-impl-trait/different_args_considered_equal.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,15 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
pub type Opaque<'a> = impl Sized; | ||
|
||
fn get_one<'a>(a: *mut &'a str) -> Opaque<'a> { | ||
a | ||
} | ||
|
||
fn get_iter<'a>() -> Option<Opaque<'a>> { | ||
//~^ ERROR: item does not constrain | ||
None::<Opaque<'static>> | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() {} |
24 changes: 24 additions & 0 deletions
24
tests/ui/type-alias-impl-trait/different_args_considered_equal.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: item does not constrain `Opaque::{opaque#0}`, but has it in its signature | ||
--> $DIR/different_args_considered_equal.rs:9:4 | ||
| | ||
LL | fn get_iter<'a>() -> Option<Opaque<'a>> { | ||
| ^^^^^^^^ | ||
| | ||
= note: consider moving the opaque type's declaration and defining uses into a separate module | ||
note: this opaque type is in the signature | ||
--> $DIR/different_args_considered_equal.rs:3:23 | ||
| | ||
LL | pub type Opaque<'a> = impl Sized; | ||
| ^^^^^^^^^^ | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/different_args_considered_equal.rs:11:5 | ||
| | ||
LL | fn get_iter<'a>() -> Option<Opaque<'a>> { | ||
| -- lifetime `'a` defined here | ||
LL | | ||
LL | None::<Opaque<'static>> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 2 previous errors | ||
|
14 changes: 14 additions & 0 deletions
14
tests/ui/type-alias-impl-trait/different_args_considered_equal2.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,14 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
pub type Opaque<'a> = impl Sized; | ||
|
||
fn get_one<'a>(a: *mut &'a str) -> Option<Opaque<'a>> { | ||
if a.is_null() { | ||
Some(a) | ||
} else { | ||
None::<Opaque<'static>> | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
tests/ui/type-alias-impl-trait/different_args_considered_equal2.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,11 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/different_args_considered_equal2.rs:9:9 | ||
| | ||
LL | fn get_one<'a>(a: *mut &'a str) -> Option<Opaque<'a>> { | ||
| -- lifetime `'a` defined here | ||
... | ||
LL | None::<Opaque<'static>> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|
22 changes: 22 additions & 0 deletions
22
tests/ui/type-alias-impl-trait/different_args_considered_equal3.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,22 @@ | ||
//! Test that we don't allow coercing an opaque type with a static | ||
//! lifetime to a free version of itself. While this kind of | ||
//! conversion is fine for rigid types, the hidden type behind an opaque | ||
//! type may | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
mod defining_scope { | ||
pub type Opaque<'a> = impl Sized; | ||
|
||
fn get_one<'a>(a: *mut &'a str) -> Opaque<'a> { | ||
a | ||
} | ||
} | ||
use defining_scope::Opaque; | ||
|
||
fn get_iter<'a>() -> Option<Opaque<'a>> { | ||
None::<Opaque<'static>> | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
tests/ui/type-alias-impl-trait/different_args_considered_equal3.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,10 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/different_args_considered_equal3.rs:18:5 | ||
| | ||
LL | fn get_iter<'a>() -> Option<Opaque<'a>> { | ||
| -- lifetime `'a` defined here | ||
LL | None::<Opaque<'static>> | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|