]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generator/auto-trait-regions.rs
Auto merge of #98051 - davidtwco:split-dwarf-stabilization, r=wesleywiser
[rust.git] / src / test / ui / generator / auto-trait-regions.rs
1 #![feature(generators)]
2 #![feature(auto_traits)]
3 #![feature(negative_impls)]
4
5 auto trait Foo {}
6
7 struct No;
8
9 impl !Foo for No {}
10
11 struct A<'a, 'b>(&'a mut bool, &'b mut bool, No);
12
13 impl<'a, 'b: 'a> Foo for A<'a, 'b> {}
14
15 struct OnlyFooIfStaticRef(No);
16 impl Foo for &'static OnlyFooIfStaticRef {}
17
18 struct OnlyFooIfRef(No);
19 impl<'a> Foo for &'a OnlyFooIfRef {}
20
21 fn assert_foo<T: Foo>(f: T) {}
22
23 fn main() {
24     // Make sure 'static is erased for generator interiors so we can't match it in trait selection
25     let x: &'static _ = &OnlyFooIfStaticRef(No);
26     let gen = || {
27         let x = x;
28         yield;
29         assert_foo(x);
30     };
31     assert_foo(gen);
32     //~^ ERROR implementation of `Foo` is not general enough
33
34     // Allow impls which matches any lifetime
35     let x = &OnlyFooIfRef(No);
36     let gen = || {
37         let x = x;
38         yield;
39         assert_foo(x);
40     };
41     assert_foo(gen); // ok
42
43     // Disallow impls which relates lifetimes in the generator interior
44     let gen = || {
45         let a = A(&mut true, &mut true, No);
46         //~^ temporary value dropped while borrowed
47         //~| temporary value dropped while borrowed
48         yield;
49         assert_foo(a);
50     };
51     assert_foo(gen);
52     //~^ ERROR not general enough
53 }