Skip to content

Commit

Permalink
Don't require lifetime super-bounds on traits apply to trait objects …
Browse files Browse the repository at this point in the history
…of that trait
  • Loading branch information
matthewjasper committed Oct 6, 2020
1 parent e674cf0 commit e42c979
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
31 changes: 17 additions & 14 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Expand Up @@ -439,26 +439,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

let upcast_trait_ref = upcast_trait_ref.unwrap();

// Check supertraits hold
// Check supertraits hold. This is so that their associated type bounds
// will be checked in the code below.
for super_trait in tcx
.super_predicates_of(trait_predicate.def_id())
.instantiate(tcx, trait_predicate.trait_ref.substs)
.predicates
.into_iter()
{
let normalized_super_trait = normalize_with_depth_to(
self,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
&super_trait,
&mut nested,
);
nested.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env.clone(),
normalized_super_trait,
));
if let ty::PredicateAtom::Trait(..) = super_trait.skip_binders() {
let normalized_super_trait = normalize_with_depth_to(
self,
obligation.param_env,
obligation.cause.clone(),
obligation.recursion_depth + 1,
&super_trait,
&mut nested,
);
nested.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env.clone(),
normalized_super_trait,
));
}
}

let assoc_types: Vec<_> = tcx
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/traits/trait-object-supertrait-lifetime-bound.rs
@@ -0,0 +1,16 @@
// check-pass

use std::any::Any;

trait A<T>: Any {
fn m(&self) {}
}

impl<S, T: 'static> A<S> for T {}

fn call_obj<'a>() {
let obj: &dyn A<&'a ()> = &();
obj.m();
}

fn main() {}

0 comments on commit e42c979

Please sign in to comment.