Don't require lifetime super-bounds on traits apply to trait objects of that trait
This commit is contained in:
parent
e674cf0200
commit
e42c97919c
2 changed files with 33 additions and 14 deletions
|
@ -439,26 +439,29 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
|
|
||||||
let upcast_trait_ref = upcast_trait_ref.unwrap();
|
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
|
for super_trait in tcx
|
||||||
.super_predicates_of(trait_predicate.def_id())
|
.super_predicates_of(trait_predicate.def_id())
|
||||||
.instantiate(tcx, trait_predicate.trait_ref.substs)
|
.instantiate(tcx, trait_predicate.trait_ref.substs)
|
||||||
.predicates
|
.predicates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
{
|
{
|
||||||
let normalized_super_trait = normalize_with_depth_to(
|
if let ty::PredicateAtom::Trait(..) = super_trait.skip_binders() {
|
||||||
self,
|
let normalized_super_trait = normalize_with_depth_to(
|
||||||
obligation.param_env,
|
self,
|
||||||
obligation.cause.clone(),
|
obligation.param_env,
|
||||||
obligation.recursion_depth + 1,
|
obligation.cause.clone(),
|
||||||
&super_trait,
|
obligation.recursion_depth + 1,
|
||||||
&mut nested,
|
&super_trait,
|
||||||
);
|
&mut nested,
|
||||||
nested.push(Obligation::new(
|
);
|
||||||
obligation.cause.clone(),
|
nested.push(Obligation::new(
|
||||||
obligation.param_env.clone(),
|
obligation.cause.clone(),
|
||||||
normalized_super_trait,
|
obligation.param_env.clone(),
|
||||||
));
|
normalized_super_trait,
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let assoc_types: Vec<_> = tcx
|
let assoc_types: Vec<_> = tcx
|
||||||
|
|
16
src/test/ui/traits/trait-object-supertrait-lifetime-bound.rs
Normal file
16
src/test/ui/traits/trait-object-supertrait-lifetime-bound.rs
Normal file
|
@ -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() {}
|
Loading…
Add table
Add a link
Reference in a new issue