2
2
#![ feature( auto_traits) ]
3
3
#![ feature( negative_impls) ]
4
4
5
+ use std:: cell:: Cell ;
6
+
5
7
auto trait Foo { }
6
8
7
9
struct No ;
8
10
9
11
impl !Foo for No { }
10
12
11
- struct A < ' a , ' b > ( & ' a mut bool , & ' b mut bool , No ) ;
13
+ struct A < ' a , ' b > ( Cell < & ' a bool > , Cell < & ' b mut bool > , No ) ;
14
+
15
+ impl < ' a , ' b > Drop for A < ' a , ' b > {
16
+ fn drop ( & mut self ) { }
17
+ }
12
18
13
19
impl < ' a , ' b : ' a > Foo for A < ' a , ' b > { }
14
20
@@ -18,36 +24,39 @@ impl Foo for &'static OnlyFooIfStaticRef {}
18
24
struct OnlyFooIfRef ( No ) ;
19
25
impl < ' a > Foo for & ' a OnlyFooIfRef { }
20
26
21
- fn assert_foo < T : Foo > ( f : T ) { }
27
+ fn assert_foo < T : Foo > ( _f : T ) { }
22
28
23
29
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 ) ;
30
+ let z = OnlyFooIfStaticRef ( No ) ;
31
+ let x = & z ;
26
32
let gen = || {
27
33
let x = x;
28
34
yield ;
29
35
assert_foo ( x) ;
30
36
} ;
31
- assert_foo ( gen) ;
37
+ assert_foo ( gen) ; // bad
32
38
//~^ ERROR implementation of `Foo` is not general enough
33
39
//~| ERROR implementation of `Foo` is not general enough
40
+ drop ( z) ;
34
41
35
42
// Allow impls which matches any lifetime
36
- let x = & OnlyFooIfRef ( No ) ;
43
+ let z = OnlyFooIfRef ( No ) ;
44
+ let x = & z;
37
45
let gen = || {
38
46
let x = x;
39
47
yield ;
40
48
assert_foo ( x) ;
41
49
} ;
42
50
assert_foo ( gen) ; // ok
51
+ drop ( z) ;
43
52
44
- // Disallow impls which relates lifetimes in the generator interior
45
- let gen = || {
46
- let a = A ( & mut true , & mut true , No ) ;
53
+ let gen = static || {
54
+ let mut y = true ;
55
+ let a = A :: < ' static , ' _ > ( Cell :: new ( & true ) , Cell :: new ( & mut y ) , No ) ;
47
56
yield ;
48
- assert_foo ( a) ;
57
+ drop ( a) ;
49
58
} ;
50
59
assert_foo ( gen) ;
51
- //~^ ERROR not general enough
52
- //~| ERROR not general enough
60
+ //~^ ERROR implementation of `Foo` is not general enough
61
+ //~| ERROR implementation of `Foo` is not general enough
53
62
}
0 commit comments