diff options
| author | Eric Holk <ericholk@microsoft.com> | 2022-04-13 16:38:16 -0700 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2022-09-12 16:55:56 -0700 |
| commit | 7fccac3ea0db7cbbb1b84ff4ab824f8d85f415fe (patch) | |
| tree | 180db46f04cb01e79b9f843387b875de77264db3 /compiler/rustc_middle | |
| parent | 6c01273a1566bc312ea88225880d35c2259914a6 (diff) | |
| download | rust-7fccac3ea0db7cbbb1b84ff4ab824f8d85f415fe.tar.gz rust-7fccac3ea0db7cbbb1b84ff4ab824f8d85f415fe.zip | |
Typecheck dyn* coercions
Also changes things to treat dyn* as a sized type, unlike dyn Trait.
Diffstat (limited to 'compiler/rustc_middle')
| -rw-r--r-- | compiler/rustc_middle/src/ty/sty.rs | 12 |
1 files changed, 10 insertions, 2 deletions
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<u32>` (e.g., derived from `dyn PartialEq<u32>`), + /// 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<u32>`, 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] |
