File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
src/test/ui/implied-bounds Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ // Test for a less than ideal interaction of implied bounds and normalization.
2+ trait Tr {
3+ type Ty ;
4+ }
5+
6+ impl < T : ' static > Tr for T {
7+ type Ty = & ' static T ;
8+ }
9+
10+ // `<&'a u8 as Tr>::Ty` should cause an error because `&'a u8: Tr` doesn't hold for
11+ // all possible 'a. However, we consider normalized types for implied bounds.
12+ //
13+ // We normalize this projection to `&'static &'a u8` and add a nested `&'a u8: 'static`
14+ // bound. This bound is then proven using the implied bounds for `&'static &'a u8` which
15+ // we only get by normalizing in the first place.
16+ fn test < ' a > ( x : & ' a u8 , _wf : <& ' a u8 as Tr >:: Ty ) -> & ' static u8 { x }
17+
18+ fn main ( ) {
19+ // This works as we have 'static references due to promotion.
20+ let _: & ' static u8 = test ( & 3 , & & 3 ) ;
21+ // This causes an error because the projection requires 'a to be 'static.
22+ // It would be unsound if this compiled.
23+ let x: u8 = 3 ;
24+ let _: & ' static u8 = test ( & x, & & 3 ) ;
25+ //~^ ERROR `x` does not live long enough
26+
27+ }
Original file line number Diff line number Diff line change 1+ error[E0597]: `x` does not live long enough
2+ --> $DIR/assoc-ty-wf-used-to-get-assoc-ty.rs:24:31
3+ |
4+ LL | let _: &'static u8 = test(&x, &&3);
5+ | -----^^------
6+ | | |
7+ | | borrowed value does not live long enough
8+ | argument requires that `x` is borrowed for `'static`
9+ ...
10+ LL | }
11+ | - `x` dropped here while still borrowed
12+
13+ error: aborting due to previous error
14+
15+ For more information about this error, try `rustc --explain E0597`.
You can’t perform that action at this time.
0 commit comments