Skip to content

Commit ef7bda3

Browse files
committed
no unnormalized types for implied bounds
1 parent 7e3e8a8 commit ef7bda3

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

compiler/rustc_trait_selection/src/traits/engine.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,18 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
124124
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
125125
let cause = ObligationCause::misc(span, hir_id);
126126
for ty in assumed_wf_types {
127-
implied_bounds.insert(ty);
127+
// FIXME(@lcnr): rustc currently does not check wf for types
128+
// pre-normalization, meaning that implied bounds are sometimes
129+
// incorrect. See #100910 for more details.
130+
//
131+
// Not adding the unnormalized types here mostly fixes that, except
132+
// that there are projections which are still ambiguous in the item definition
133+
// but do normalize successfully when using the item, see #98543.
134+
//
135+
// Anyways, I will hopefully soon change implied bounds to make all of this
136+
// sound and then uncomment this line again.
137+
138+
// implied_bounds.insert(ty);
128139
let normalized = self.normalize(cause.clone(), param_env, ty);
129140
implied_bounds.insert(normalized);
130141
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
struct Foo<T>(T);
2+
3+
trait GoodBye {
4+
type Forget;
5+
}
6+
impl<T> GoodBye for T {
7+
type Forget = ();
8+
}
9+
10+
trait NeedsWf<'a, 'b> {
11+
type Assoc;
12+
}
13+
14+
impl<'a, 'b> NeedsWf<'a, 'b> for Foo<<&'a &'b () as GoodBye>::Forget> {
15+
type Assoc = &'a &'b ();
16+
//~^ ERROR in type `&'a &'b ()`, reference has a longer lifetime than the data it references
17+
}
18+
19+
fn needs_wf<'a, 'b, T: NeedsWf<'a, 'b>>() {}
20+
21+
fn foo<'a: 'a, 'b: 'b>(_: &'b String) {
22+
needs_wf::<'a, 'b, Foo<()>>();
23+
}
24+
25+
fn main() {
26+
let x = String::from("hello");
27+
foo::<'static, '_>(&x);
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0491]: in type `&'a &'b ()`, reference has a longer lifetime than the data it references
2+
--> $DIR/impl-header-unnormalized-types.rs:15:18
3+
|
4+
LL | type Assoc = &'a &'b ();
5+
| ^^^^^^^^^^
6+
|
7+
note: the pointer is valid for the lifetime `'a` as defined here
8+
--> $DIR/impl-header-unnormalized-types.rs:14:6
9+
|
10+
LL | impl<'a, 'b> NeedsWf<'a, 'b> for Foo<<&'a &'b () as GoodBye>::Forget> {
11+
| ^^
12+
note: but the referenced data is only valid for the lifetime `'b` as defined here
13+
--> $DIR/impl-header-unnormalized-types.rs:14:10
14+
|
15+
LL | impl<'a, 'b> NeedsWf<'a, 'b> for Foo<<&'a &'b () as GoodBye>::Forget> {
16+
| ^^
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0491`.

0 commit comments

Comments
 (0)