Skip to content

Commit e674cf0

Browse files
committed
Normalize super trait bounds when confirming object candidates
1 parent d08ab94 commit e674cf0

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,26 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
440440
let upcast_trait_ref = upcast_trait_ref.unwrap();
441441

442442
// Check supertraits hold
443-
nested.extend(
444-
tcx.super_predicates_of(trait_predicate.def_id())
445-
.instantiate(tcx, trait_predicate.trait_ref.substs)
446-
.predicates
447-
.into_iter()
448-
.map(|super_trait| {
449-
Obligation::new(obligation.cause.clone(), obligation.param_env, super_trait)
450-
}),
451-
);
443+
for super_trait in tcx
444+
.super_predicates_of(trait_predicate.def_id())
445+
.instantiate(tcx, trait_predicate.trait_ref.substs)
446+
.predicates
447+
.into_iter()
448+
{
449+
let normalized_super_trait = normalize_with_depth_to(
450+
self,
451+
obligation.param_env,
452+
obligation.cause.clone(),
453+
obligation.recursion_depth + 1,
454+
&super_trait,
455+
&mut nested,
456+
);
457+
nested.push(Obligation::new(
458+
obligation.cause.clone(),
459+
obligation.param_env.clone(),
460+
normalized_super_trait,
461+
));
462+
}
452463

453464
let assoc_types: Vec<_> = tcx
454465
.associated_items(trait_predicate.def_id())
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ignore-tidy-linelength
2+
3+
// Check that we normalize super predicates for object candidates.
4+
5+
// check-pass
6+
7+
use std::ops::Index;
8+
9+
fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
10+
// To prove
11+
// `dyn SVec<Item = T, Output = T>: SVec`
12+
// we need to show
13+
// `dyn SVec<Item = T, Output = T> as Index>::Output == <dyn SVec<Item = T, Output = T> as SVec>::Item`
14+
// which, with the current normalization strategy, has to be eagerly
15+
// normalized to:
16+
// `dyn SVec<Item = T, Output = T> as Index>::Output == T`.
17+
let _ = s.len();
18+
}
19+
20+
trait SVec: Index<usize, Output = <Self as SVec>::Item> {
21+
type Item;
22+
23+
fn len(&self) -> usize;
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)