Implement dyn Trait unsizing as well

This commit is contained in:
Florian Diebold
2020-02-21 19:05:27 +01:00
committed by Florian Diebold
parent de39d221a1
commit 0dfbbaf03b
5 changed files with 136 additions and 9 deletions

View File

@@ -661,6 +661,17 @@ impl Ty {
}
}
/// If this is a `dyn Trait` type, this returns the `Trait` part.
pub fn dyn_trait_ref(&self) -> Option<&TraitRef> {
match self {
Ty::Dyn(bounds) => bounds.get(0).and_then(|b| match b {
GenericPredicate::Implemented(trait_ref) => Some(trait_ref),
_ => None,
}),
_ => None,
}
}
fn builtin_deref(&self) -> Option<Ty> {
match self {
Ty::Apply(a_ty) => match a_ty.ctor {