Skip to content

Commit 8691b96

Browse files
committed
test implied bounds + nested proj oblig
1 parent f25cb83 commit 8691b96

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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`.

0 commit comments

Comments
 (0)