]> git.lizzy.rs Git - rust.git/blob - src/test/ui/implied-bounds/assoc-ty-wf-used-to-get-assoc-ty.rs
Rollup merge of #105983 - compiler-errors:issue-105981, r=tmiasko
[rust.git] / src / test / ui / implied-bounds / assoc-ty-wf-used-to-get-assoc-ty.rs
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 }