2023-10-19 16:46:28 -05:00
|
|
|
#![feature(coroutines)]
|
2020-11-22 21:54:31 -06:00
|
|
|
#![feature(auto_traits)]
|
2020-01-09 04:56:38 -06:00
|
|
|
#![feature(negative_impls)]
|
2017-10-07 09:36:28 -05: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() {
|
2023-10-19 16:46:28 -05:00
|
|
|
// Make sure 'static is erased for coroutine interiors so we can't match it in trait selection
|
2017-10-07 09:36:28 -05:00
|
|
|
let x: &'static _ = &OnlyFooIfStaticRef(No);
|
2021-05-07 13:00:17 -05:00
|
|
|
let gen = move || {
|
2017-10-07 09:36:28 -05:00
|
|
|
let x = x;
|
|
|
|
yield;
|
|
|
|
assert_foo(x);
|
|
|
|
};
|
2018-10-30 15:57:52 -05:00
|
|
|
assert_foo(gen);
|
2018-11-18 18:07:38 -06:00
|
|
|
//~^ ERROR implementation of `Foo` is not general enough
|
2017-10-07 09:36:28 -05:00
|
|
|
|
|
|
|
// Allow impls which matches any lifetime
|
|
|
|
let x = &OnlyFooIfRef(No);
|
2021-05-07 13:00:17 -05:00
|
|
|
let gen = move || {
|
2017-10-07 09:36:28 -05:00
|
|
|
let x = x;
|
|
|
|
yield;
|
|
|
|
assert_foo(x);
|
|
|
|
};
|
|
|
|
assert_foo(gen); // ok
|
|
|
|
|
2023-10-19 16:46:28 -05:00
|
|
|
// Disallow impls which relates lifetimes in the coroutine interior
|
2021-05-07 13:00:17 -05:00
|
|
|
let gen = move || {
|
2017-10-07 09:36:28 -05:00
|
|
|
let a = A(&mut true, &mut true, No);
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ temporary value dropped while borrowed
|
|
|
|
//~| temporary value dropped while borrowed
|
2017-10-07 09:36:28 -05:00
|
|
|
yield;
|
|
|
|
assert_foo(a);
|
|
|
|
};
|
2018-10-30 15:57:52 -05:00
|
|
|
assert_foo(gen);
|
2018-11-17 07:18:37 -06:00
|
|
|
//~^ ERROR not general enough
|
2017-10-07 09:36:28 -05:00
|
|
|
}
|