-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
231 additions
and
22 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
2 changes: 1 addition & 1 deletion
2
tests/ui/impl-trait/defining-use-captured-non-universal-region.infer.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
5 changes: 2 additions & 3 deletions
5
tests/ui/impl-trait/defining-use-captured-non-universal-region.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
12 changes: 12 additions & 0 deletions
12
tests/ui/impl-trait/defining-use-captured-non-universal-region.statik.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,12 @@ | ||
error[E0792]: expected generic lifetime parameter, found `'static` | ||
--> $DIR/defining-use-captured-non-universal-region.rs:10:18 | ||
| | ||
LL | fn foo<'a>() -> impl Sized + 'a { | ||
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type | ||
LL | #[cfg(statik)] | ||
LL | let i: i32 = foo::<'static>(); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0792`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// issue: #111935 | ||
|
||
#![allow(unconditional_recursion)] | ||
|
||
// Lt indirection is necessary to make the lifetime of the function late-bound, | ||
// in order to bypass some other bugs. | ||
type Lt<'lt> = Option<*mut &'lt ()>; | ||
|
||
mod statik { | ||
use super::*; | ||
// invalid defining use: Opaque<'static> := () | ||
fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { | ||
let _: () = foo(Lt::<'static>::None); | ||
//~^ ERROR expected generic lifetime parameter, found `'static` | ||
} | ||
} | ||
|
||
mod infer { | ||
use super::*; | ||
// invalid defining use: Opaque<'_> := () | ||
fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { | ||
let _: () = foo(Lt::<'_>::None); | ||
//~^ ERROR expected generic lifetime parameter, found `'_` | ||
} | ||
} | ||
|
||
mod equal { | ||
use super::*; | ||
// invalid defining use: Opaque<'a, 'a> := () | ||
// because of the use of equal lifetimes in args | ||
fn foo<'a, 'b>(_: Lt<'a>, _: Lt<'b>) -> impl Sized + 'a + 'b { | ||
let _: () = foo(Lt::<'a>::None, Lt::<'a>::None); | ||
//~^ ERROR non-defining opaque type use in defining scope | ||
} | ||
} | ||
|
||
fn main() {} |
31 changes: 31 additions & 0 deletions
31
tests/ui/impl-trait/rpit/non-defining-use-lifetimes.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,31 @@ | ||
error[E0792]: expected generic lifetime parameter, found `'static` | ||
--> $DIR/non-defining-use-lifetimes.rs:13:16 | ||
| | ||
LL | fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { | ||
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type | ||
LL | let _: () = foo(Lt::<'static>::None); | ||
| ^^ | ||
|
||
error[E0792]: expected generic lifetime parameter, found `'_` | ||
--> $DIR/non-defining-use-lifetimes.rs:22:16 | ||
| | ||
LL | fn foo<'a>(_: Lt<'a>) -> impl Sized + 'a { | ||
| -- this generic parameter must be used with a generic lifetime parameter | ||
LL | let _: () = foo(Lt::<'_>::None); | ||
| ^^ | ||
|
||
error: non-defining opaque type use in defining scope | ||
--> $DIR/non-defining-use-lifetimes.rs:32:16 | ||
| | ||
LL | let _: () = foo(Lt::<'a>::None, Lt::<'a>::None); | ||
| ^^ | ||
| | ||
note: lifetime used multiple times | ||
--> $DIR/non-defining-use-lifetimes.rs:31:58 | ||
| | ||
LL | fn foo<'a, 'b>(_: Lt<'a>, _: Lt<'b>) -> impl Sized + 'a + 'b { | ||
| ^^ ^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0792`. |
50 changes: 50 additions & 0 deletions
50
tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.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,50 @@ | ||
// FIXME: description | ||
// issue: #113916 | ||
// check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
#![feature(impl_trait_in_assoc_type)] | ||
|
||
trait Trait<'a, 'b> {} | ||
impl<T> Trait<'_, '_> for T {} | ||
|
||
mod equal_params { | ||
type Opaque<'a: 'b, 'b: 'a> = impl super::Trait<'a, 'b>; | ||
fn test<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> { | ||
let _ = None::<&'a &'b &'a ()>; | ||
0u8 | ||
} | ||
} | ||
|
||
mod equal_static { | ||
type Opaque<'a: 'static> = impl Sized + 'a; | ||
fn test<'a: 'static>() -> Opaque<'a> { | ||
let _ = None::<&'static &'a ()>; | ||
0u8 | ||
} | ||
} | ||
|
||
mod implied_bounds { | ||
trait Traitor { | ||
type Assoc; | ||
fn define(self) -> Self::Assoc; | ||
} | ||
|
||
impl<'a> Traitor for &'static &'a () { | ||
type Assoc = impl Sized + 'a; | ||
fn define(self) -> Self::Assoc { | ||
let _ = None::<&'static &'a ()>; | ||
0u8 | ||
} | ||
} | ||
|
||
impl<'a, 'b> Traitor for (&'a &'b (), &'b &'a ()) { | ||
type Assoc = impl Sized + 'a + 'b; | ||
fn define(self) -> Self::Assoc { | ||
let _ = None::<(&'a &'b (), &'b &'a ())>; | ||
0u8 | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |