Skip to content

Commit e42c979

Browse files
committed
Don't require lifetime super-bounds on traits apply to trait objects of that trait
1 parent e674cf0 commit e42c979

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -439,26 +439,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
439439

440440
let upcast_trait_ref = upcast_trait_ref.unwrap();
441441

442-
// Check supertraits hold
442+
// Check supertraits hold. This is so that their associated type bounds
443+
// will be checked in the code below.
443444
for super_trait in tcx
444445
.super_predicates_of(trait_predicate.def_id())
445446
.instantiate(tcx, trait_predicate.trait_ref.substs)
446447
.predicates
447448
.into_iter()
448449
{
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-
));
450+
if let ty::PredicateAtom::Trait(..) = super_trait.skip_binders() {
451+
let normalized_super_trait = normalize_with_depth_to(
452+
self,
453+
obligation.param_env,
454+
obligation.cause.clone(),
455+
obligation.recursion_depth + 1,
456+
&super_trait,
457+
&mut nested,
458+
);
459+
nested.push(Obligation::new(
460+
obligation.cause.clone(),
461+
obligation.param_env.clone(),
462+
normalized_super_trait,
463+
));
464+
}
462465
}
463466

464467
let assoc_types: Vec<_> = tcx
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
3+
use std::any::Any;
4+
5+
trait A<T>: Any {
6+
fn m(&self) {}
7+
}
8+
9+
impl<S, T: 'static> A<S> for T {}
10+
11+
fn call_obj<'a>() {
12+
let obj: &dyn A<&'a ()> = &();
13+
obj.m();
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)