From 7fccac3ea0db7cbbb1b84ff4ab824f8d85f415fe Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Wed, 13 Apr 2022 16:38:16 -0700 Subject: Typecheck dyn* coercions Also changes things to treat dyn* as a sized type, unlike dyn Trait. --- compiler/rustc_middle/src/ty/sty.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_middle') diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 702c2d27187..6713660ab8f 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -31,7 +31,7 @@ use ty::util::IntTypeExt; use rustc_type_ir::sty::TyKind::*; use rustc_type_ir::RegionKind as IrRegionKind; -use rustc_type_ir::TyKind as IrTyKind; +use rustc_type_ir::{TraitObjectRepresentation, TyKind as IrTyKind}; // Re-export the `TyKind` from `rustc_type_ir` here for convenience #[rustc_diagnostic_item = "TyKind"] @@ -692,6 +692,9 @@ impl<'tcx> ExistentialPredicate<'tcx> { } impl<'tcx> Binder<'tcx, ExistentialPredicate<'tcx>> { + /// Given an existential predicate like `?Self: PartialEq` (e.g., derived from `dyn PartialEq`), + /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self` + /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq`, in our example). pub fn with_self_ty(&self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> ty::Predicate<'tcx> { use crate::ty::ToPredicate; match self.skip_binder() { @@ -1849,7 +1852,12 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn is_trait(self) -> bool { - matches!(self.kind(), Dynamic(..)) + matches!(self.kind(), Dynamic(_, _, TraitObjectRepresentation::Unsized)) + } + + #[inline] + pub fn is_dyn_star(self) -> bool { + matches!(self.kind(), Dynamic(_, _, TraitObjectRepresentation::Sized)) } #[inline] -- cgit 1.4.1-3-g733a5