Skip to content

Commit

Permalink
add tests in #111906
Browse files Browse the repository at this point in the history
  • Loading branch information
zirconium-n committed May 30, 2023
1 parent 0cf7ab2 commit 5c69a5d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![allow(unconditional_recursion)]

fn foo<'a: 'a>() -> impl Sized {
let _: *mut &'a () = foo::<'a>();
//~^ ERROR
loop {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
--> $DIR/recursive-impl-trait-type-direct-with-earlybound-lifetime-2.rs:4:12
|
LL | fn foo<'a: 'a>() -> impl Sized {
| -- ---------- opaque type defined here
| |
| hidden type `*mut &'a ()` captures the lifetime `'a` as defined here
LL | let _: *mut &'a () = foo::<'a>();
| ^^^^^^^^^^^
|
help: to declare that `impl Sized` captures `'a`, you can add an explicit `'a` lifetime bound
|
LL | fn foo<'a: 'a>() -> impl Sized + 'a {
| ++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0700`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

#![allow(unconditional_recursion)]

fn foo<'a: 'a>() -> impl Sized + 'a {
let _: *mut &'a () = foo::<'a>();
loop {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![allow(unconditional_recursion)]

trait Trait<'a, 'b> {}
impl<'a, 'b, T> Trait<'a, 'b> for T {}

fn foo<'a: 'a, 'b: 'b>() -> impl Trait<'a, 'b> {
let _: *mut &'a () = foo::<'a, 'b>();
let _: *mut &'b () = foo::<'a, 'b>();
//~^ ERROR
loop {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: concrete type differs from previous defining opaque type use
--> $DIR/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs:8:12
|
LL | let _: *mut &'b () = foo::<'a, 'b>();
| ^^^^^^^^^^^ expected `*mut &'a ()`, got `*mut &'b ()`
|
note: previous use here
--> $DIR/recursive-impl-trait-type-direct-with-earlybound-lifetime-4.rs:7:12
|
LL | let _: *mut &'a () = foo::<'a, 'b>();
| ^^^^^^^^^^^

error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

#![allow(unconditional_recursion)]

fn foo<'a: 'a>() -> impl Sized {
let _: () = foo::<'a>();
loop {}
}

fn main() {}

0 comments on commit 5c69a5d

Please sign in to comment.