Unnamed repository; edit this file 'description' to name the repository.
Remove ProjectionElem::OpaqueCast
| -rw-r--r-- | crates/hir-ty/src/mir.rs | 30 | ||||
| -rw-r--r-- | crates/hir-ty/src/mir/borrowck.rs | 3 | ||||
| -rw-r--r-- | crates/hir-ty/src/mir/eval.rs | 7 | ||||
| -rw-r--r-- | crates/hir-ty/src/mir/lower/pattern_matching.rs | 2 | ||||
| -rw-r--r-- | crates/hir-ty/src/mir/pretty.rs | 3 |
5 files changed, 17 insertions, 28 deletions
diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs index d0b7e5f654..7c5c0ea564 100644 --- a/crates/hir-ty/src/mir.rs +++ b/crates/hir-ty/src/mir.rs @@ -181,7 +181,6 @@ pub enum ProjectionElem<V: PartialEq> { }, /// "Downcast" to a variant of an enum or a coroutine. Downcast(VariantId), - OpaqueCast(std::convert::Infallible), // TODO remove this } impl<V: PartialEq> ProjectionElem<V> { @@ -195,7 +194,6 @@ impl<V: PartialEq> ProjectionElem<V> { } ProjectionElem::Subslice { from, to } => ProjectionElem::Subslice { from, to }, ProjectionElem::Downcast(variant_id) => ProjectionElem::Downcast(variant_id), - ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty), } } @@ -212,7 +210,6 @@ impl<V: PartialEq> ProjectionElem<V> { } ProjectionElem::Subslice { from, to } => ProjectionElem::Subslice { from, to }, ProjectionElem::Downcast(variant_id) => ProjectionElem::Downcast(variant_id), - ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty), }) } } @@ -1257,7 +1254,7 @@ impl<'db> PlaceTy<'db> { .instantiate(infcx.interner, args) .skip_norm_wip() } - // TODO TyKind::Coroutine... + // FIXME TyKind::Coroutine... _ => panic!("can't downcast non-adt non-coroutine type: {self_ty:?}"), } } else { @@ -1272,7 +1269,7 @@ impl<'db> PlaceTy<'db> { TyKind::Closure(_, args) => { args.as_closure().tupled_upvars_ty().tuple_fields()[f.0 as usize] } - // TODO TyKind::Coroutine / TyKind::CoroutineClosure... + // FIXME TyKind::Coroutine / TyKind::CoroutineClosure... TyKind::Tuple(tys) => tys .get(f.0 as usize) .cloned() @@ -1291,7 +1288,7 @@ impl<'db> PlaceTy<'db> { ) -> PlaceTy<'db> { self.projection_ty_core( infcx.interner, - &elem, + elem, |ty| { if matches!(ty.kind(), TyKind::Alias(..)) { let mut ocx = ObligationCtxt::new(infcx); @@ -1311,16 +1308,13 @@ impl<'db> PlaceTy<'db> { /// projects `place_ty` onto `elem`, returning the appropriate /// `Ty` or downcast variant corresponding to that projection. /// The `handle_field` callback must map a `FieldIndex` to its `Ty` - pub fn projection_ty_core<V: PartialEq>( + pub fn projection_ty_core<V: PartialEq + ::std::fmt::Debug>( self, tcx: DbInterner<'db>, elem: &ProjectionElem<V>, mut structurally_normalize: impl FnMut(Ty<'db>) -> Ty<'db>, mut handle_field: impl FnMut(Ty<'db>, Option<VariantId>, FieldIndex /*, T*/) -> Ty<'db>, - ) -> PlaceTy<'db> - where - V: ::std::fmt::Debug, - { + ) -> PlaceTy<'db> { // we only bail on mir building when there are type mismatches // but error types may pop up resulting in us still attempting to build the mir // so just propagate the error type @@ -1330,7 +1324,7 @@ impl<'db> PlaceTy<'db> { if self.variant_id.is_some() && !matches!(elem, ProjectionElem::Field(..)) { panic!("cannot use non field projection on downcasted place") } - let answer = match *elem { + match *elem { ProjectionElem::Deref => { let ty = structurally_normalize(self.ty).builtin_deref(true).unwrap_or_else(|| { panic!("deref projection of non-dereferenceable ty {:?}", self) @@ -1355,13 +1349,9 @@ impl<'db> PlaceTy<'db> { }) } ProjectionElem::Downcast(index) => PlaceTy { ty: self.ty, variant_id: Some(index) }, - ProjectionElem::Field(f) => PlaceTy::from_ty(handle_field( - structurally_normalize(self.ty), - self.variant_id.clone(), - f, - )), - ProjectionElem::OpaqueCast(_ty) => unimplemented!("not emitted, to be removed"), - }; - answer + ProjectionElem::Field(f) => { + PlaceTy::from_ty(handle_field(structurally_normalize(self.ty), self.variant_id, f)) + } + } } } diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs index bf241aed72..c5367f630e 100644 --- a/crates/hir-ty/src/mir/borrowck.rs +++ b/crates/hir-ty/src/mir/borrowck.rs @@ -436,8 +436,7 @@ fn place_case<'db>( | ProjectionElem::Index(_) => { is_part_of = true; } - ProjectionElem::Downcast(_) | - ProjectionElem::OpaqueCast(_) => (), + ProjectionElem::Downcast(_) => (), } ty = ty.projection_ty(infcx, proj, env); } diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index f8bf3cc3ae..f0e2218cde 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -741,11 +741,11 @@ impl<'a, 'db: 'a> Evaluator<'a, 'db> { fn projected_ty(&self, ty: PlaceTy<'db>, proj: PlaceElem) -> PlaceTy<'db> { let pair = (ty, proj); if let Some(r) = self.projected_ty_cache.borrow().get(&pair) { - return r.clone(); + return *r; } let (ty, proj) = pair; - let r = ty.clone().projection_ty(&self.infcx, &proj, self.param_env.param_env); - self.projected_ty_cache.borrow_mut().insert((ty, proj), r.clone()); + let r = ty.projection_ty(&self.infcx, &proj, self.param_env.param_env); + self.projected_ty_cache.borrow_mut().insert((ty, proj), r); r } @@ -852,7 +852,6 @@ impl<'a, 'db: 'a> Evaluator<'a, 'db> { ProjectionElem::Downcast(_) => { // no runtime effect } - ProjectionElem::OpaqueCast(_) => not_supported!("opaque cast"), } } Ok((addr, ty.ty, metadata)) diff --git a/crates/hir-ty/src/mir/lower/pattern_matching.rs b/crates/hir-ty/src/mir/lower/pattern_matching.rs index 254d561a66..f273a823ba 100644 --- a/crates/hir-ty/src/mir/lower/pattern_matching.rs +++ b/crates/hir-ty/src/mir/lower/pattern_matching.rs @@ -662,7 +662,7 @@ impl<'db> MirLowerCtx<'_, 'db> { let downcast_place = if matches!(v, VariantId::EnumVariantId(_)) { cond_place.project(ProjectionElem::Downcast(v)) } else { - cond_place.clone() + *cond_place }; Ok(match shape { AdtPatternShape::Record { args } => { diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs index 09824d282b..3e41454424 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -366,7 +366,8 @@ impl<'a, 'db> MirPrettyCtx<'a, 'db> { } else { match place_ty.ty.kind() { TyKind::Adt(adt_def, _) if !adt_def.is_enum() => { - let variant_id = VariantId::from_non_enum(adt_def.def_id()).unwrap(); + let variant_id = + VariantId::from_non_enum(adt_def.def_id()).unwrap(); let fields = variant_id.fields(this.db); w!( this, |