Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed May 26, 2023
1 parent 8293ca6 commit b7eab00
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,8 @@ fn codegen_stmt<'tcx>(
let to_ty = fx.monomorphize(to_ty);

fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.builtin_deref(true).is_some_and(
|(pointee_ty, _)| {
has_ptr_meta(fx.tcx, pointee_ty)
},
)
ty.builtin_deref(true)
.is_some_and(|(pointee_ty, _)| has_ptr_meta(fx.tcx, pointee_ty))
}

if is_fat_ptr(fx, from_ty) {
Expand Down
25 changes: 12 additions & 13 deletions compiler/rustc_hir_analysis/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
}

// Otherwise, deref if type is derefable:
let (kind, new_ty) = if let Some((ty, _)) =
self.state.cur_ty.builtin_deref(self.include_raw_pointers)
{
debug_assert_eq!(ty, self.infcx.resolve_vars_if_possible(ty));
// NOTE: we may still need to normalize the built-in deref in case
// we have some type like `&<Ty as Trait>::Assoc`, since users of
// autoderef expect this type to have been structurally normalized.
if self.infcx.tcx.trait_solver_next()
let (kind, new_ty) =
if let Some((ty, _)) = self.state.cur_ty.builtin_deref(self.include_raw_pointers) {
debug_assert_eq!(ty, self.infcx.resolve_vars_if_possible(ty));
// NOTE: we may still need to normalize the built-in deref in case
// we have some type like `&<Ty as Trait>::Assoc`, since users of
// autoderef expect this type to have been structurally normalized.
if self.infcx.tcx.trait_solver_next()
&& let ty::Alias(ty::Projection, _) = ty.kind()
{
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
Expand All @@ -82,11 +81,11 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
} else {
(AutoderefKind::Builtin, ty)
}
} else if let Some(ty) = self.overloaded_deref_ty(self.state.cur_ty) {
(AutoderefKind::Overloaded, ty)
} else {
return None;
};
} else if let Some(ty) = self.overloaded_deref_ty(self.state.cur_ty) {
(AutoderefKind::Overloaded, ty)
} else {
return None;
};

if new_ty.references_error() {
return None;
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2099,9 +2099,7 @@ impl<'tcx> Ty<'tcx> {
/// Some types -- notably unsafe ptrs -- can only be dereferenced explicitly.
pub fn builtin_deref(self, explicit: bool) -> Option<(Ty<'tcx>, rustc_type_ir::Mutability)> {
match self.kind() {
Adt(def, _) if def.is_box() => {
Some((self.boxed_ty(), rustc_type_ir::Mutability::Not))
}
Adt(def, _) if def.is_box() => Some((self.boxed_ty(), rustc_type_ir::Mutability::Not)),
Ref(_, ty, mutbl) => Some((*ty, *mutbl)),
RawPtr(mt) if explicit => Some((mt.ty, mt.mutbl)),
_ => None,
Expand Down

0 comments on commit b7eab00

Please sign in to comment.