Flesh out tests more

This commit is contained in:
Michael Goulet 2023-10-14 15:28:44 +01:00
parent 1005970485
commit f0e385d6b7
11 changed files with 143 additions and 7 deletions

View File

@ -8,7 +8,7 @@ trait Foo {
fn assoc(&mut self) -> Self::Assoc<'_>;
}
fn test<T>(mut t: T)
fn overlapping_mut<T>(mut t: T)
where
T: Foo,
for<'a> T::Assoc<'a>: 'static,
@ -17,4 +17,13 @@ fn test<T>(mut t: T)
let b = t.assoc();
}
fn live_past_borrow<T>(mut t: T)
where
T: Foo,
for<'a> T::Assoc<'a>: 'static {
let x = t.assoc();
drop(t);
drop(x);
}
fn main() {}

View File

@ -0,0 +1,16 @@
// known-bug: #42940
trait Captures<'a> {}
impl<T> Captures<'_> for T {}
trait Outlives<'a>: 'a {}
impl<'a, T: 'a> Outlives<'a> for T {}
// Test that we treat `for<'a> Opaque: 'a` as `Opaque: 'static`
fn test<'o>(v: &'o Vec<i32>) -> impl Captures<'o> + for<'a> Outlives<'a> {}
fn statik() -> impl Sized {
test(&vec![])
}
fn main() {}

View File

@ -0,0 +1,16 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/higher-ranked-outlives-for-capture.rs:13:11
|
LL | test(&vec![])
| ------^^^^^^-
| | |
| | creates a temporary value which is freed while still in use
| argument requires that borrow lasts for `'static`
LL | }
| - temporary value is freed at the end of this statement
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0716`.

View File

@ -0,0 +1,16 @@
// check-pass
trait Captures<'a> {}
impl<T> Captures<'_> for T {}
trait Outlives<'a>: 'a {}
impl<'a, T: 'a> Outlives<'a> for T {}
// Test that we treat `for<'a> Opaque: 'a` as `Opaque: 'static`
fn test<'o>(v: &'o Vec<i32>) -> impl Captures<'o> + for<'a> Outlives<'a> {}
fn opaque_doesnt_use_temporary() {
let a = test(&vec![]);
}
fn main() {}

View File

@ -0,0 +1,17 @@
// check-pass
// Check that opaques capturing early and late-bound vars correctly mark
// regions required to be live using the item bounds.
trait Captures<'a> {}
impl<T> Captures<'_> for T {}
fn captures_temp_late<'a>(x: &'a Vec<i32>) -> impl Sized + Captures<'a> + 'static {}
fn captures_temp_early<'a: 'a>(x: &'a Vec<i32>) -> impl Sized + Captures<'a> + 'static {}
fn test() {
let x = captures_temp_early(&vec![]);
let y = captures_temp_late(&vec![]);
}
fn main() {}

View File

@ -0,0 +1,14 @@
// known-bug: #42940
trait Trait {}
impl Trait for () {}
fn foo<'a>(s: &'a str) -> impl Trait + 'static {
bar(s)
}
fn bar<P: AsRef<str>>(s: P) -> impl Trait + 'static {
()
}
fn main() {}

View File

@ -0,0 +1,13 @@
error[E0700]: hidden type for `impl Trait + 'static` captures lifetime that does not appear in bounds
--> $DIR/opaque-type-param.rs:7:5
|
LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static {
| -- -------------------- opaque type defined here
| |
| hidden type `impl Trait + 'static` captures the lifetime `'a` as defined here
LL | bar(s)
| ^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0700`.

View File

@ -3,12 +3,20 @@
trait Captures<'a> {}
impl<T> Captures<'_> for T {}
fn foo(x: &i32) -> impl Sized + Captures<'_> + 'static {}
fn foo(x: &mut i32) -> impl Sized + Captures<'_> + 'static {}
fn main() {
fn overlapping_mut() {
let i = &mut 1;
let x = foo(i);
let y = foo(i);
}
fn live_past_borrow() {
let y;
{
let x = 1;
y = foo(&x);
let x = &mut 1;
y = foo(x);
}
}
fn main() {}

View File

@ -4,7 +4,13 @@ trait Foo {
fn rpitit(&mut self) -> impl Sized + 'static;
}
fn test<T: Foo>(mut t: T) {
fn live_past_borrow<T: Foo>(mut t: T) {
let x = t.rpitit();
drop(t);
drop(x);
}
fn overlapping_mut<T: Foo>(mut t: T) {
let a = t.rpitit();
let b = t.rpitit();
}

View File

@ -7,9 +7,15 @@ trait Foo {
fn borrow(&mut self) -> impl Sized + '_;
}
fn live_past_borrow<T: Foo<borrow(): 'static>>(mut t: T) {
let x = t.borrow();
drop(t);
drop(x);
}
// Test that the `'_` item bound in `borrow` does not cause us to
// overlook the `'static` RTN bound.
fn test<T: Foo<borrow(): 'static>>(mut t: T) {
fn overlapping_mut<T: Foo<borrow(): 'static>>(mut t: T) {
let x = t.borrow();
let x = t.borrow();
}

View File

@ -0,0 +1,15 @@
// check-pass
// issue: 116794
// Uncaptured lifetimes should not be required to be live.
struct Invariant<T>(*mut T);
fn opaque<'a: 'a>(_: &'a str) -> Invariant<impl Sized> {
Invariant(&mut ())
}
fn main() {
let x = opaque(&String::new());
drop(x);
}