22#![ feature( auto_traits) ]
33#![ feature( negative_impls) ]
44
5+ use std:: cell:: Cell ;
6+
57auto trait Foo { }
68
79struct No ;
810
911impl !Foo for No { }
1012
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+ }
1218
1319impl < ' a , ' b : ' a > Foo for A < ' a , ' b > { }
1420
@@ -18,36 +24,39 @@ impl Foo for &'static OnlyFooIfStaticRef {}
1824struct OnlyFooIfRef ( No ) ;
1925impl < ' a > Foo for & ' a OnlyFooIfRef { }
2026
21- fn assert_foo < T : Foo > ( f : T ) { }
27+ fn assert_foo < T : Foo > ( _f : T ) { }
2228
2329fn 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 ;
2632 let gen = || {
2733 let x = x;
2834 yield ;
2935 assert_foo ( x) ;
3036 } ;
31- assert_foo ( gen) ;
37+ assert_foo ( gen) ; // bad
3238 //~^ ERROR implementation of `Foo` is not general enough
3339 //~| ERROR implementation of `Foo` is not general enough
40+ drop ( z) ;
3441
3542 // Allow impls which matches any lifetime
36- let x = & OnlyFooIfRef ( No ) ;
43+ let z = OnlyFooIfRef ( No ) ;
44+ let x = & z;
3745 let gen = || {
3846 let x = x;
3947 yield ;
4048 assert_foo ( x) ;
4149 } ;
4250 assert_foo ( gen) ; // ok
51+ drop ( z) ;
4352
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 ) ;
4756 yield ;
48- assert_foo ( a) ;
57+ drop ( a) ;
4958 } ;
5059 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
5362}
0 commit comments