Flesh out tests more
This commit is contained in:
parent
1005970485
commit
f0e385d6b7
@ -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() {}
|
||||
|
@ -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() {}
|
@ -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`.
|
16
tests/ui/borrowck/alias-liveness/higher-ranked.rs
Normal file
16
tests/ui/borrowck/alias-liveness/higher-ranked.rs
Normal 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() {}
|
17
tests/ui/borrowck/alias-liveness/opaque-capture.rs
Normal file
17
tests/ui/borrowck/alias-liveness/opaque-capture.rs
Normal 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() {}
|
14
tests/ui/borrowck/alias-liveness/opaque-type-param.rs
Normal file
14
tests/ui/borrowck/alias-liveness/opaque-type-param.rs
Normal 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() {}
|
13
tests/ui/borrowck/alias-liveness/opaque-type-param.stderr
Normal file
13
tests/ui/borrowck/alias-liveness/opaque-type-param.stderr
Normal 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`.
|
@ -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() {}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
15
tests/ui/impl-trait/bivariant-lifetime-liveness.rs
Normal file
15
tests/ui/impl-trait/bivariant-lifetime-liveness.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user