1
Fork 0

Make builtin_deref just return a Ty

This commit is contained in:
Michael Goulet 2024-05-09 22:45:14 -04:00
parent 8c7c151a7a
commit d50c2b0a52
43 changed files with 92 additions and 116 deletions

View file

@ -78,13 +78,9 @@ impl<'tcx> PlaceTy<'tcx> {
}
let answer = match *elem {
ProjectionElem::Deref => {
let ty = self
.ty
.builtin_deref(true)
.unwrap_or_else(|| {
bug!("deref projection of non-dereferenceable ty {:?}", self)
})
.ty;
let ty = self.ty.builtin_deref(true).unwrap_or_else(|| {
bug!("deref projection of non-dereferenceable ty {:?}", self)
});
PlaceTy::from_ty(ty)
}
ProjectionElem::Index(_) | ProjectionElem::ConstantIndex { .. } => {

View file

@ -2164,13 +2164,11 @@ impl<'tcx> Ty<'tcx> {
///
/// The parameter `explicit` indicates if this is an *explicit* dereference.
/// Some types -- notably unsafe ptrs -- can only be dereferenced explicitly.
pub fn builtin_deref(self, explicit: bool) -> Option<TypeAndMut<'tcx>> {
match self.kind() {
Adt(def, _) if def.is_box() => {
Some(TypeAndMut { ty: self.boxed_ty(), mutbl: hir::Mutability::Not })
}
Ref(_, ty, mutbl) => Some(TypeAndMut { ty: *ty, mutbl: *mutbl }),
RawPtr(ty, mutbl) if explicit => Some(TypeAndMut { ty: *ty, mutbl: *mutbl }),
pub fn builtin_deref(self, explicit: bool) -> Option<Ty<'tcx>> {
match *self.kind() {
Adt(def, _) if def.is_box() => Some(self.boxed_ty()),
Ref(_, ty, _) => Some(ty),
RawPtr(ty, _) if explicit => Some(ty),
_ => None,
}
}