Rename rustc_middle::Ty::is_unsafe_ptr to is_raw_ptr
The wording unsafe pointer is less common and not mentioned in a lot of places, instead this is usually called a "raw pointer". For the sake of uniformity, we rename this method. This came up during the review of https://github.com/rust-lang/rust/pull/134424.
This commit is contained in:
parent
80c091958f
commit
f842ee8245
28 changed files with 43 additions and 43 deletions
|
@ -570,7 +570,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
// If we didn't find an overloaded deref or index, then assume it's a
|
// If we didn't find an overloaded deref or index, then assume it's a
|
||||||
// built in deref and check the type of the base.
|
// built in deref and check the type of the base.
|
||||||
let base_ty = deref_base.ty(self.body, tcx).ty;
|
let base_ty = deref_base.ty(self.body, tcx).ty;
|
||||||
if base_ty.is_unsafe_ptr() {
|
if base_ty.is_raw_ptr() {
|
||||||
BorrowedContentSource::DerefRawPointer
|
BorrowedContentSource::DerefRawPointer
|
||||||
} else if base_ty.is_mutable_ptr() {
|
} else if base_ty.is_mutable_ptr() {
|
||||||
BorrowedContentSource::DerefMutableRef
|
BorrowedContentSource::DerefMutableRef
|
||||||
|
|
|
@ -1013,7 +1013,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
//
|
//
|
||||||
// This is also relevant for `Pin<&mut Self>`, where we need to peel the
|
// This is also relevant for `Pin<&mut Self>`, where we need to peel the
|
||||||
// `Pin`.
|
// `Pin`.
|
||||||
while !op.layout.ty.is_unsafe_ptr() && !op.layout.ty.is_ref() {
|
while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
|
||||||
let (idx, _) = op.layout.non_1zst_field(bx).expect(
|
let (idx, _) = op.layout.non_1zst_field(bx).expect(
|
||||||
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
|
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
|
||||||
);
|
);
|
||||||
|
@ -1045,7 +1045,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
}
|
}
|
||||||
Immediate(_) => {
|
Immediate(_) => {
|
||||||
// See comment above explaining why we peel these newtypes
|
// See comment above explaining why we peel these newtypes
|
||||||
while !op.layout.ty.is_unsafe_ptr() && !op.layout.ty.is_ref() {
|
while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() {
|
||||||
let (idx, _) = op.layout.non_1zst_field(bx).expect(
|
let (idx, _) = op.layout.non_1zst_field(bx).expect(
|
||||||
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
|
"not exactly one non-1-ZST field in a `DispatchFromDyn` type",
|
||||||
);
|
);
|
||||||
|
|
|
@ -367,7 +367,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
bx.sess().dcx().emit_fatal(errors::AtomicCompareExchange);
|
bx.sess().dcx().emit_fatal(errors::AtomicCompareExchange);
|
||||||
};
|
};
|
||||||
let ty = fn_args.type_at(0);
|
let ty = fn_args.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_raw_ptr() {
|
||||||
let weak = instruction == "cxchgweak";
|
let weak = instruction == "cxchgweak";
|
||||||
let dst = args[0].immediate();
|
let dst = args[0].immediate();
|
||||||
let cmp = args[1].immediate();
|
let cmp = args[1].immediate();
|
||||||
|
@ -395,7 +395,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
|
|
||||||
"load" => {
|
"load" => {
|
||||||
let ty = fn_args.type_at(0);
|
let ty = fn_args.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_raw_ptr() {
|
||||||
let layout = bx.layout_of(ty);
|
let layout = bx.layout_of(ty);
|
||||||
let size = layout.size;
|
let size = layout.size;
|
||||||
let source = args[0].immediate();
|
let source = args[0].immediate();
|
||||||
|
@ -413,7 +413,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
|
|
||||||
"store" => {
|
"store" => {
|
||||||
let ty = fn_args.type_at(0);
|
let ty = fn_args.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_raw_ptr() {
|
||||||
let size = bx.layout_of(ty).size;
|
let size = bx.layout_of(ty).size;
|
||||||
let val = args[1].immediate();
|
let val = args[1].immediate();
|
||||||
let ptr = args[0].immediate();
|
let ptr = args[0].immediate();
|
||||||
|
@ -458,7 +458,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty = fn_args.type_at(0);
|
let ty = fn_args.type_at(0);
|
||||||
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
|
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_raw_ptr() {
|
||||||
let ptr = args[0].immediate();
|
let ptr = args[0].immediate();
|
||||||
let val = args[1].immediate();
|
let val = args[1].immediate();
|
||||||
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
|
bx.atomic_rmw(atom_op, ptr, val, parse_ordering(bx, ordering))
|
||||||
|
|
|
@ -689,7 +689,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
(OperandValue::Immediate(llval), operand.layout)
|
(OperandValue::Immediate(llval), operand.layout)
|
||||||
}
|
}
|
||||||
mir::UnOp::PtrMetadata => {
|
mir::UnOp::PtrMetadata => {
|
||||||
assert!(operand.layout.ty.is_unsafe_ptr() || operand.layout.ty.is_ref(),);
|
assert!(operand.layout.ty.is_raw_ptr() || operand.layout.ty.is_ref(),);
|
||||||
let (_, meta) = operand.val.pointer_parts();
|
let (_, meta) = operand.val.pointer_parts();
|
||||||
assert_eq!(operand.layout.fields.count() > 1, meta.is_some());
|
assert_eq!(operand.layout.fields.count() > 1, meta.is_some());
|
||||||
if let Some(meta) = meta {
|
if let Some(meta) = meta {
|
||||||
|
|
|
@ -710,7 +710,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
|
|
||||||
if is_int_bool_float_or_char(lhs_ty) && is_int_bool_float_or_char(rhs_ty) {
|
if is_int_bool_float_or_char(lhs_ty) && is_int_bool_float_or_char(rhs_ty) {
|
||||||
// Int, bool, float, and char operations are fine.
|
// Int, bool, float, and char operations are fine.
|
||||||
} else if lhs_ty.is_fn_ptr() || lhs_ty.is_unsafe_ptr() {
|
} else if lhs_ty.is_fn_ptr() || lhs_ty.is_raw_ptr() {
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
op,
|
op,
|
||||||
BinOp::Eq
|
BinOp::Eq
|
||||||
|
|
|
@ -203,7 +203,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
cast_to: TyAndLayout<'tcx>,
|
cast_to: TyAndLayout<'tcx>,
|
||||||
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
|
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
|
||||||
assert!(src.layout.ty.is_any_ptr());
|
assert!(src.layout.ty.is_any_ptr());
|
||||||
assert!(cast_to.ty.is_unsafe_ptr());
|
assert!(cast_to.ty.is_raw_ptr());
|
||||||
// Handle casting any ptr to raw ptr (might be a wide ptr).
|
// Handle casting any ptr to raw ptr (might be a wide ptr).
|
||||||
if cast_to.size == src.layout.size {
|
if cast_to.size == src.layout.size {
|
||||||
// Thin or wide pointer that just has the ptr kind of target type changed.
|
// Thin or wide pointer that just has the ptr kind of target type changed.
|
||||||
|
@ -212,7 +212,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
// Casting the metadata away from a wide ptr.
|
// Casting the metadata away from a wide ptr.
|
||||||
assert_eq!(src.layout.size, 2 * self.pointer_size());
|
assert_eq!(src.layout.size, 2 * self.pointer_size());
|
||||||
assert_eq!(cast_to.size, self.pointer_size());
|
assert_eq!(cast_to.size, self.pointer_size());
|
||||||
assert!(src.layout.ty.is_unsafe_ptr());
|
assert!(src.layout.ty.is_raw_ptr());
|
||||||
return match **src {
|
return match **src {
|
||||||
Immediate::ScalarPair(data, _) => interp_ok(ImmTy::from_scalar(data, cast_to)),
|
Immediate::ScalarPair(data, _) => interp_ok(ImmTy::from_scalar(data, cast_to)),
|
||||||
Immediate::Scalar(..) => span_bug!(
|
Immediate::Scalar(..) => span_bug!(
|
||||||
|
|
|
@ -241,7 +241,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||||
// Figure out whether this is an addr_of of an already raw place.
|
// Figure out whether this is an addr_of of an already raw place.
|
||||||
let place_base_raw = if place.is_indirect_first_projection() {
|
let place_base_raw = if place.is_indirect_first_projection() {
|
||||||
let ty = self.frame().body.local_decls[place.local].ty;
|
let ty = self.frame().body.local_decls[place.local].ty;
|
||||||
ty.is_unsafe_ptr()
|
ty.is_raw_ptr()
|
||||||
} else {
|
} else {
|
||||||
// Not a deref, and thus not raw.
|
// Not a deref, and thus not raw.
|
||||||
false
|
false
|
||||||
|
|
|
@ -690,7 +690,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||||
} else {
|
} else {
|
||||||
match self.try_coercion_cast(fcx) {
|
match self.try_coercion_cast(fcx) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
if self.expr_ty.is_unsafe_ptr() && self.cast_ty.is_unsafe_ptr() {
|
if self.expr_ty.is_raw_ptr() && self.cast_ty.is_raw_ptr() {
|
||||||
// When casting a raw pointer to another raw pointer, we cannot convert the cast into
|
// When casting a raw pointer to another raw pointer, we cannot convert the cast into
|
||||||
// a coercion because the pointee types might only differ in regions, which HIR typeck
|
// a coercion because the pointee types might only differ in regions, which HIR typeck
|
||||||
// cannot distinguish. This would cause us to erroneously discard a cast which will
|
// cannot distinguish. This would cause us to erroneously discard a cast which will
|
||||||
|
|
|
@ -3556,7 +3556,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if base_t.is_unsafe_ptr() && idx_t.is_integral() {
|
if base_t.is_raw_ptr() && idx_t.is_integral() {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"consider using `wrapping_add` or `add` for indexing into raw pointer",
|
"consider using `wrapping_add` or `add` for indexing into raw pointer",
|
||||||
vec![
|
vec![
|
||||||
|
|
|
@ -598,7 +598,7 @@ fn method_autoderef_steps<'tcx>(
|
||||||
unsize: false,
|
unsize: false,
|
||||||
reachable_via_deref,
|
reachable_via_deref,
|
||||||
};
|
};
|
||||||
if ty.is_unsafe_ptr() {
|
if ty.is_raw_ptr() {
|
||||||
// all the subsequent steps will be from_unsafe_deref
|
// all the subsequent steps will be from_unsafe_deref
|
||||||
reached_raw_pointer = true;
|
reached_raw_pointer = true;
|
||||||
}
|
}
|
||||||
|
@ -618,7 +618,7 @@ fn method_autoderef_steps<'tcx>(
|
||||||
unsize: false,
|
unsize: false,
|
||||||
reachable_via_deref: true,
|
reachable_via_deref: true,
|
||||||
};
|
};
|
||||||
if ty.is_unsafe_ptr() {
|
if ty.is_raw_ptr() {
|
||||||
// all the subsequent steps will be from_unsafe_deref
|
// all the subsequent steps will be from_unsafe_deref
|
||||||
reached_raw_pointer = true;
|
reached_raw_pointer = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,7 +645,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// pointer + {integer} or pointer - pointer.
|
// pointer + {integer} or pointer - pointer.
|
||||||
if op.span.can_be_used_for_suggestions() {
|
if op.span.can_be_used_for_suggestions() {
|
||||||
match op.node {
|
match op.node {
|
||||||
hir::BinOpKind::Add if lhs_ty.is_unsafe_ptr() && rhs_ty.is_integral() => {
|
hir::BinOpKind::Add if lhs_ty.is_raw_ptr() && rhs_ty.is_integral() => {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"consider using `wrapping_add` or `add` for pointer + {integer}",
|
"consider using `wrapping_add` or `add` for pointer + {integer}",
|
||||||
vec![
|
vec![
|
||||||
|
@ -659,7 +659,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
hir::BinOpKind::Sub => {
|
hir::BinOpKind::Sub => {
|
||||||
if lhs_ty.is_unsafe_ptr() && rhs_ty.is_integral() {
|
if lhs_ty.is_raw_ptr() && rhs_ty.is_integral() {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"consider using `wrapping_sub` or `sub` for \
|
"consider using `wrapping_sub` or `sub` for \
|
||||||
pointer - {integer}",
|
pointer - {integer}",
|
||||||
|
@ -674,7 +674,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if lhs_ty.is_unsafe_ptr() && rhs_ty.is_unsafe_ptr() {
|
if lhs_ty.is_raw_ptr() && rhs_ty.is_raw_ptr() {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"consider using `offset_from` for pointer - pointer if the \
|
"consider using `offset_from` for pointer - pointer if the \
|
||||||
pointers point to the same allocation",
|
pointers point to the same allocation",
|
||||||
|
|
|
@ -2042,7 +2042,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> {
|
||||||
restrict_repr_packed_field_ref_capture(place_with_id.place.clone(), capture_kind);
|
restrict_repr_packed_field_ref_capture(place_with_id.place.clone(), capture_kind);
|
||||||
|
|
||||||
// Raw pointers don't inherit mutability
|
// Raw pointers don't inherit mutability
|
||||||
if place_with_id.place.deref_tys().any(Ty::is_unsafe_ptr) {
|
if place_with_id.place.deref_tys().any(Ty::is_raw_ptr) {
|
||||||
capture_kind = ty::UpvarCapture::ByRef(ty::BorrowKind::Immutable);
|
capture_kind = ty::UpvarCapture::ByRef(ty::BorrowKind::Immutable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2093,7 +2093,7 @@ fn restrict_precision_for_unsafe(
|
||||||
mut place: Place<'_>,
|
mut place: Place<'_>,
|
||||||
mut curr_mode: ty::UpvarCapture,
|
mut curr_mode: ty::UpvarCapture,
|
||||||
) -> (Place<'_>, ty::UpvarCapture) {
|
) -> (Place<'_>, ty::UpvarCapture) {
|
||||||
if place.base_ty.is_unsafe_ptr() {
|
if place.base_ty.is_raw_ptr() {
|
||||||
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, 0);
|
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2102,7 +2102,7 @@ fn restrict_precision_for_unsafe(
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i, proj) in place.projections.iter().enumerate() {
|
for (i, proj) in place.projections.iter().enumerate() {
|
||||||
if proj.ty.is_unsafe_ptr() {
|
if proj.ty.is_raw_ptr() {
|
||||||
// Don't apply any projections on top of an unsafe ptr.
|
// Don't apply any projections on top of an unsafe ptr.
|
||||||
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1);
|
truncate_place_to_len_and_update_capture_kind(&mut place, &mut curr_mode, i + 1);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -576,7 +576,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
|
||||||
// and recommending Copy might be a bad idea.
|
// and recommending Copy might be a bad idea.
|
||||||
for field in def.all_fields() {
|
for field in def.all_fields() {
|
||||||
let did = field.did;
|
let did = field.did;
|
||||||
if cx.tcx.type_of(did).instantiate_identity().is_unsafe_ptr() {
|
if cx.tcx.type_of(did).instantiate_identity().is_raw_ptr() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
|
||||||
|
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
|
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
|
||||||
let non_zero = !ty.is_unsafe_ptr();
|
let non_zero = !ty.is_raw_ptr();
|
||||||
|
|
||||||
let tail = tcx.struct_tail_raw(
|
let tail = tcx.struct_tail_raw(
|
||||||
pointee,
|
pointee,
|
||||||
|
@ -841,7 +841,7 @@ where
|
||||||
// as the `Abi` or `FieldsShape` is checked by users.
|
// as the `Abi` or `FieldsShape` is checked by users.
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
let nil = tcx.types.unit;
|
let nil = tcx.types.unit;
|
||||||
let unit_ptr_ty = if this.ty.is_unsafe_ptr() {
|
let unit_ptr_ty = if this.ty.is_raw_ptr() {
|
||||||
Ty::new_mut_ptr(tcx, nil)
|
Ty::new_mut_ptr(tcx, nil)
|
||||||
} else {
|
} else {
|
||||||
Ty::new_mut_ref(tcx, tcx.lifetimes.re_static, nil)
|
Ty::new_mut_ref(tcx, tcx.lifetimes.re_static, nil)
|
||||||
|
|
|
@ -1199,7 +1199,7 @@ impl<'tcx> Ty<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_unsafe_ptr(self) -> bool {
|
pub fn is_raw_ptr(self) -> bool {
|
||||||
matches!(self.kind(), RawPtr(_, _))
|
matches!(self.kind(), RawPtr(_, _))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1207,7 +1207,7 @@ impl<'tcx> Ty<'tcx> {
|
||||||
/// `Box` is *not* considered a pointer here!
|
/// `Box` is *not* considered a pointer here!
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_any_ptr(self) -> bool {
|
pub fn is_any_ptr(self) -> bool {
|
||||||
self.is_ref() || self.is_unsafe_ptr() || self.is_fn_ptr()
|
self.is_ref() || self.is_raw_ptr() || self.is_fn_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -554,7 +554,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
||||||
_ => self.requires_unsafe(expr.span, UseOfExternStatic),
|
_ => self.requires_unsafe(expr.span, UseOfExternStatic),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if self.thir[arg].ty.is_unsafe_ptr() {
|
} else if self.thir[arg].ty.is_raw_ptr() {
|
||||||
self.requires_unsafe(expr.span, DerefOfRawPointer);
|
self.requires_unsafe(expr.span, DerefOfRawPointer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PointerFinder<'a, 'tcx> {
|
||||||
let pointer_ty = self.local_decls[place.local].ty;
|
let pointer_ty = self.local_decls[place.local].ty;
|
||||||
|
|
||||||
// We only want to check places based on raw pointers
|
// We only want to check places based on raw pointers
|
||||||
if !pointer_ty.is_unsafe_ptr() {
|
if !pointer_ty.is_raw_ptr() {
|
||||||
trace!("Indirect, but not based on an raw ptr, not checking {:?}", place);
|
trace!("Indirect, but not based on an raw ptr, not checking {:?}", place);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl<'a, 'tcx> UndefinedTransmutesChecker<'a, 'tcx> {
|
||||||
{
|
{
|
||||||
let fn_sig = function.ty(self.body, self.tcx).fn_sig(self.tcx).skip_binder();
|
let fn_sig = function.ty(self.body, self.tcx).fn_sig(self.tcx).skip_binder();
|
||||||
if let [input] = fn_sig.inputs() {
|
if let [input] = fn_sig.inputs() {
|
||||||
return input.is_unsafe_ptr() && fn_sig.output().is_integral();
|
return input.is_raw_ptr() && fn_sig.output().is_integral();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -1397,8 +1397,8 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||||
// or `*mut [i32]` <=> `*const [u64]`), including the common special
|
// or `*mut [i32]` <=> `*const [u64]`), including the common special
|
||||||
// case of `*const T` <=> `*mut T`.
|
// case of `*const T` <=> `*mut T`.
|
||||||
if let Transmute = kind
|
if let Transmute = kind
|
||||||
&& from.is_unsafe_ptr()
|
&& from.is_raw_ptr()
|
||||||
&& to.is_unsafe_ptr()
|
&& to.is_raw_ptr()
|
||||||
&& self.pointers_have_same_metadata(from, to)
|
&& self.pointers_have_same_metadata(from, to)
|
||||||
{
|
{
|
||||||
kind = PtrToPtr;
|
kind = PtrToPtr;
|
||||||
|
|
|
@ -753,7 +753,7 @@ fn make_thin_self_ptr<'tcx>(
|
||||||
// To get the type `*mut RcInner<Self>`, we just keep unwrapping newtypes until we
|
// To get the type `*mut RcInner<Self>`, we just keep unwrapping newtypes until we
|
||||||
// get a built-in pointer type
|
// get a built-in pointer type
|
||||||
let mut wide_pointer_layout = layout;
|
let mut wide_pointer_layout = layout;
|
||||||
while !wide_pointer_layout.ty.is_unsafe_ptr() && !wide_pointer_layout.ty.is_ref() {
|
while !wide_pointer_layout.ty.is_raw_ptr() && !wide_pointer_layout.ty.is_ref() {
|
||||||
wide_pointer_layout = wide_pointer_layout
|
wide_pointer_layout = wide_pointer_layout
|
||||||
.non_1zst_field(cx)
|
.non_1zst_field(cx)
|
||||||
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type")
|
.expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type")
|
||||||
|
|
|
@ -269,7 +269,7 @@ fn layout_of_uncached<'tcx>(
|
||||||
// Potentially-wide pointers.
|
// Potentially-wide pointers.
|
||||||
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
|
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
|
||||||
let mut data_ptr = scalar_unit(Pointer(AddressSpace::DATA));
|
let mut data_ptr = scalar_unit(Pointer(AddressSpace::DATA));
|
||||||
if !ty.is_unsafe_ptr() {
|
if !ty.is_raw_ptr() {
|
||||||
data_ptr.valid_range_mut().start = 1;
|
data_ptr.valid_range_mut().start = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
||||||
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
|
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
|
||||||
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
|
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
|
||||||
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
|
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
|
||||||
&& cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr()
|
&& cx.tcx.type_of(def_id).instantiate_identity().is_raw_ptr()
|
||||||
{
|
{
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -682,7 +682,7 @@ fn try_parse_ref_op<'tcx>(
|
||||||
},
|
},
|
||||||
[arg],
|
[arg],
|
||||||
) => (true, typeck.qpath_res(path, *hir_id).opt_def_id()?, arg),
|
) => (true, typeck.qpath_res(path, *hir_id).opt_def_id()?, arg),
|
||||||
ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_unsafe_ptr() => {
|
ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_raw_ptr() => {
|
||||||
return Some((RefOp::Deref, sub_expr));
|
return Some((RefOp::Deref, sub_expr));
|
||||||
},
|
},
|
||||||
ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)),
|
ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)),
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn collect_unsafe_exprs<'tcx>(
|
||||||
unsafe_ops.push(("access of a mutable static occurs here", expr.span));
|
unsafe_ops.push(("access of a mutable static occurs here", expr.span));
|
||||||
},
|
},
|
||||||
|
|
||||||
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_unsafe_ptr() => {
|
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_raw_ptr() => {
|
||||||
unsafe_ops.push(("raw pointer dereference occurs here", expr.span));
|
unsafe_ops.push(("raw pointer dereference occurs here", expr.span));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -179,10 +179,10 @@ impl PassByRefOrValue {
|
||||||
&& let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind
|
&& let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind
|
||||||
{
|
{
|
||||||
if let Some(typeck) = cx.maybe_typeck_results() {
|
if let Some(typeck) = cx.maybe_typeck_results() {
|
||||||
// Don't lint if an unsafe pointer is created.
|
// Don't lint if a raw pointer is created.
|
||||||
// TODO: Limit the check only to unsafe pointers to the argument (or part of the argument)
|
// TODO: Limit the check only to raw pointers to the argument (or part of the argument)
|
||||||
// which escape the current function.
|
// which escape the current function.
|
||||||
if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr())
|
if typeck.node_types().items().any(|(_, &ty)| ty.is_raw_ptr())
|
||||||
|| typeck
|
|| typeck
|
||||||
.adjustments()
|
.adjustments()
|
||||||
.items()
|
.items()
|
||||||
|
|
|
@ -111,7 +111,7 @@ fn is_expr_ty_usize(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||||
|
|
||||||
// Is the type of the expression a raw pointer?
|
// Is the type of the expression a raw pointer?
|
||||||
fn is_expr_ty_raw_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
fn is_expr_ty_raw_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
|
||||||
cx.typeck_results().expr_ty(expr).is_unsafe_ptr()
|
cx.typeck_results().expr_ty(expr).is_raw_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_suggestion(
|
fn build_suggestion(
|
||||||
|
|
|
@ -217,7 +217,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
|
||||||
self.eagerness |= NoChange;
|
self.eagerness |= NoChange;
|
||||||
},
|
},
|
||||||
// Dereferences should be cheap, but dereferencing a raw pointer earlier may not be safe.
|
// Dereferences should be cheap, but dereferencing a raw pointer earlier may not be safe.
|
||||||
ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => (),
|
ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_raw_ptr() => (),
|
||||||
ExprKind::Unary(UnOp::Deref, _) => self.eagerness |= NoChange,
|
ExprKind::Unary(UnOp::Deref, _) => self.eagerness |= NoChange,
|
||||||
ExprKind::Unary(_, e)
|
ExprKind::Unary(_, e)
|
||||||
if matches!(
|
if matches!(
|
||||||
|
|
|
@ -417,7 +417,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
|
||||||
}
|
}
|
||||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result {
|
fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result {
|
||||||
match e.kind {
|
match e.kind {
|
||||||
ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => {
|
ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_raw_ptr() => {
|
||||||
ControlFlow::Break(())
|
ControlFlow::Break(())
|
||||||
},
|
},
|
||||||
ExprKind::MethodCall(..)
|
ExprKind::MethodCall(..)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue