2022-10-01 10:19:31 +00:00
|
|
|
// revisions: no_drop_tracking drop_tracking drop_tracking_mir
|
|
|
|
// [drop_tracking] compile-flags: -Zdrop-tracking
|
|
|
|
// [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir
|
2017-10-07 14:36:28 +00:00
|
|
|
#![feature(generators)]
|
2020-11-23 03:54:31 +00:00
|
|
|
#![feature(auto_traits)]
|
2020-01-09 10:56:38 +00:00
|
|
|
#![feature(negative_impls)]
|
2017-10-07 14:36:28 +00:00
|
|
|
|
|
|
|
auto trait Foo {}
|
|
|
|
|
|
|
|
struct No;
|
|
|
|
|
|
|
|
impl !Foo for No {}
|
|
|
|
|
|
|
|
struct A<'a, 'b>(&'a mut bool, &'b mut bool, No);
|
|
|
|
|
|
|
|
impl<'a, 'b: 'a> Foo for A<'a, 'b> {}
|
|
|
|
|
|
|
|
struct OnlyFooIfStaticRef(No);
|
|
|
|
impl Foo for &'static OnlyFooIfStaticRef {}
|
|
|
|
|
|
|
|
struct OnlyFooIfRef(No);
|
|
|
|
impl<'a> Foo for &'a OnlyFooIfRef {}
|
|
|
|
|
|
|
|
fn assert_foo<T: Foo>(f: T) {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Make sure 'static is erased for generator interiors so we can't match it in trait selection
|
|
|
|
let x: &'static _ = &OnlyFooIfStaticRef(No);
|
|
|
|
let gen = || {
|
|
|
|
let x = x;
|
|
|
|
yield;
|
|
|
|
assert_foo(x);
|
|
|
|
};
|
2018-10-30 20:57:52 +00:00
|
|
|
assert_foo(gen);
|
2018-11-19 00:07:38 +00:00
|
|
|
//~^ ERROR implementation of `Foo` is not general enough
|
2017-10-07 14:36:28 +00:00
|
|
|
|
|
|
|
// Allow impls which matches any lifetime
|
|
|
|
let x = &OnlyFooIfRef(No);
|
|
|
|
let gen = || {
|
|
|
|
let x = x;
|
|
|
|
yield;
|
|
|
|
assert_foo(x);
|
|
|
|
};
|
|
|
|
assert_foo(gen); // ok
|
|
|
|
|
|
|
|
// Disallow impls which relates lifetimes in the generator interior
|
|
|
|
let gen = || {
|
|
|
|
let a = A(&mut true, &mut true, No);
|
2022-04-01 17:13:25 +00:00
|
|
|
//~^ temporary value dropped while borrowed
|
|
|
|
//~| temporary value dropped while borrowed
|
2017-10-07 14:36:28 +00:00
|
|
|
yield;
|
|
|
|
assert_foo(a);
|
|
|
|
};
|
2018-10-30 20:57:52 +00:00
|
|
|
assert_foo(gen);
|
2018-11-17 13:18:37 +00:00
|
|
|
//~^ ERROR not general enough
|
2017-10-07 14:36:28 +00:00
|
|
|
}
|