Skip to content

Commit 71a9c63

Browse files
committed
Remove ProjectionElem::OpaqueCast
1 parent bde303a commit 71a9c63

5 files changed

Lines changed: 17 additions & 28 deletions

File tree

crates/hir-ty/src/mir.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ pub enum ProjectionElem<V: PartialEq> {
181181
},
182182
/// "Downcast" to a variant of an enum or a coroutine.
183183
Downcast(VariantId),
184-
OpaqueCast(std::convert::Infallible), // TODO remove this
185184
}
186185

187186
impl<V: PartialEq> ProjectionElem<V> {
@@ -195,7 +194,6 @@ impl<V: PartialEq> ProjectionElem<V> {
195194
}
196195
ProjectionElem::Subslice { from, to } => ProjectionElem::Subslice { from, to },
197196
ProjectionElem::Downcast(variant_id) => ProjectionElem::Downcast(variant_id),
198-
ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty),
199197
}
200198
}
201199

@@ -212,7 +210,6 @@ impl<V: PartialEq> ProjectionElem<V> {
212210
}
213211
ProjectionElem::Subslice { from, to } => ProjectionElem::Subslice { from, to },
214212
ProjectionElem::Downcast(variant_id) => ProjectionElem::Downcast(variant_id),
215-
ProjectionElem::OpaqueCast(ty) => ProjectionElem::OpaqueCast(ty),
216213
})
217214
}
218215
}
@@ -1257,7 +1254,7 @@ impl<'db> PlaceTy<'db> {
12571254
.instantiate(infcx.interner, args)
12581255
.skip_norm_wip()
12591256
}
1260-
// TODO TyKind::Coroutine...
1257+
// FIXME TyKind::Coroutine...
12611258
_ => panic!("can't downcast non-adt non-coroutine type: {self_ty:?}"),
12621259
}
12631260
} else {
@@ -1272,7 +1269,7 @@ impl<'db> PlaceTy<'db> {
12721269
TyKind::Closure(_, args) => {
12731270
args.as_closure().tupled_upvars_ty().tuple_fields()[f.0 as usize]
12741271
}
1275-
// TODO TyKind::Coroutine / TyKind::CoroutineClosure...
1272+
// FIXME TyKind::Coroutine / TyKind::CoroutineClosure...
12761273
TyKind::Tuple(tys) => tys
12771274
.get(f.0 as usize)
12781275
.cloned()
@@ -1291,7 +1288,7 @@ impl<'db> PlaceTy<'db> {
12911288
) -> PlaceTy<'db> {
12921289
self.projection_ty_core(
12931290
infcx.interner,
1294-
&elem,
1291+
elem,
12951292
|ty| {
12961293
if matches!(ty.kind(), TyKind::Alias(..)) {
12971294
let mut ocx = ObligationCtxt::new(infcx);
@@ -1311,16 +1308,13 @@ impl<'db> PlaceTy<'db> {
13111308
/// projects `place_ty` onto `elem`, returning the appropriate
13121309
/// `Ty` or downcast variant corresponding to that projection.
13131310
/// The `handle_field` callback must map a `FieldIndex` to its `Ty`
1314-
pub fn projection_ty_core<V: PartialEq>(
1311+
pub fn projection_ty_core<V: PartialEq + ::std::fmt::Debug>(
13151312
self,
13161313
tcx: DbInterner<'db>,
13171314
elem: &ProjectionElem<V>,
13181315
mut structurally_normalize: impl FnMut(Ty<'db>) -> Ty<'db>,
13191316
mut handle_field: impl FnMut(Ty<'db>, Option<VariantId>, FieldIndex /*, T*/) -> Ty<'db>,
1320-
) -> PlaceTy<'db>
1321-
where
1322-
V: ::std::fmt::Debug,
1323-
{
1317+
) -> PlaceTy<'db> {
13241318
// we only bail on mir building when there are type mismatches
13251319
// but error types may pop up resulting in us still attempting to build the mir
13261320
// so just propagate the error type
@@ -1330,7 +1324,7 @@ impl<'db> PlaceTy<'db> {
13301324
if self.variant_id.is_some() && !matches!(elem, ProjectionElem::Field(..)) {
13311325
panic!("cannot use non field projection on downcasted place")
13321326
}
1333-
let answer = match *elem {
1327+
match *elem {
13341328
ProjectionElem::Deref => {
13351329
let ty = structurally_normalize(self.ty).builtin_deref(true).unwrap_or_else(|| {
13361330
panic!("deref projection of non-dereferenceable ty {:?}", self)
@@ -1355,13 +1349,9 @@ impl<'db> PlaceTy<'db> {
13551349
})
13561350
}
13571351
ProjectionElem::Downcast(index) => PlaceTy { ty: self.ty, variant_id: Some(index) },
1358-
ProjectionElem::Field(f) => PlaceTy::from_ty(handle_field(
1359-
structurally_normalize(self.ty),
1360-
self.variant_id.clone(),
1361-
f,
1362-
)),
1363-
ProjectionElem::OpaqueCast(_ty) => unimplemented!("not emitted, to be removed"),
1364-
};
1365-
answer
1352+
ProjectionElem::Field(f) => {
1353+
PlaceTy::from_ty(handle_field(structurally_normalize(self.ty), self.variant_id, f))
1354+
}
1355+
}
13661356
}
13671357
}

crates/hir-ty/src/mir/borrowck.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ fn place_case<'db>(
436436
| ProjectionElem::Index(_) => {
437437
is_part_of = true;
438438
}
439-
ProjectionElem::Downcast(_) |
440-
ProjectionElem::OpaqueCast(_) => (),
439+
ProjectionElem::Downcast(_) => (),
441440
}
442441
ty = ty.projection_ty(infcx, proj, env);
443442
}

crates/hir-ty/src/mir/eval.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,11 @@ impl<'a, 'db: 'a> Evaluator<'a, 'db> {
741741
fn projected_ty(&self, ty: PlaceTy<'db>, proj: PlaceElem) -> PlaceTy<'db> {
742742
let pair = (ty, proj);
743743
if let Some(r) = self.projected_ty_cache.borrow().get(&pair) {
744-
return r.clone();
744+
return *r;
745745
}
746746
let (ty, proj) = pair;
747-
let r = ty.clone().projection_ty(&self.infcx, &proj, self.param_env.param_env);
748-
self.projected_ty_cache.borrow_mut().insert((ty, proj), r.clone());
747+
let r = ty.projection_ty(&self.infcx, &proj, self.param_env.param_env);
748+
self.projected_ty_cache.borrow_mut().insert((ty, proj), r);
749749
r
750750
}
751751

@@ -852,7 +852,6 @@ impl<'a, 'db: 'a> Evaluator<'a, 'db> {
852852
ProjectionElem::Downcast(_) => {
853853
// no runtime effect
854854
}
855-
ProjectionElem::OpaqueCast(_) => not_supported!("opaque cast"),
856855
}
857856
}
858857
Ok((addr, ty.ty, metadata))

crates/hir-ty/src/mir/lower/pattern_matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'db> MirLowerCtx<'_, 'db> {
662662
let downcast_place = if matches!(v, VariantId::EnumVariantId(_)) {
663663
cond_place.project(ProjectionElem::Downcast(v))
664664
} else {
665-
cond_place.clone()
665+
*cond_place
666666
};
667667
Ok(match shape {
668668
AdtPatternShape::Record { args } => {

crates/hir-ty/src/mir/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ impl<'a, 'db> MirPrettyCtx<'a, 'db> {
366366
} else {
367367
match place_ty.ty.kind() {
368368
TyKind::Adt(adt_def, _) if !adt_def.is_enum() => {
369-
let variant_id = VariantId::from_non_enum(adt_def.def_id()).unwrap();
369+
let variant_id =
370+
VariantId::from_non_enum(adt_def.def_id()).unwrap();
370371
let fields = variant_id.fields(this.db);
371372
w!(
372373
this,

0 commit comments

Comments
 (0)