Skip to content

Commit

Permalink
Auto merge of #135994 - 1c3t3a:rename-unsafe-ptr, r=oli-obk
Browse files Browse the repository at this point in the history
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
#134424.

r? `@Noratrieb`
  • Loading branch information
bors committed Feb 12, 2025
2 parents 3a0b1ae + 15d08ef commit 7cd3b8c
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/cast_ptr_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
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.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
} else {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ fn try_parse_ref_op<'tcx>(
},
[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));
},
ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/multiple_unsafe_ops_per_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn collect_unsafe_exprs<'tcx>(
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));
},

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/operators/ptr_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn expr_as_cast_to_usize<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>
// If the given expression is a cast to a `*const` pointer, return the lhs of the cast
// E.g., `foo as *const _` returns `foo`.
fn expr_as_cast_to_raw_pointer<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
if cx.typeck_results().expr_ty(cast_expr).is_unsafe_ptr() {
if cx.typeck_results().expr_ty(cast_expr).is_raw_ptr() {
if let ExprKind::Cast(expr, _) = cast_expr.kind {
return Some(expr);
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/pass_by_ref_or_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ impl PassByRefOrValue {
&& let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind
{
if let Some(typeck) = cx.maybe_typeck_results() {
// Don't lint if an unsafe pointer is created.
// TODO: Limit the check only to unsafe pointers to the argument (or part of the argument)
// Don't lint if a raw pointer is created.
// TODO: Limit the check only to raw pointers to the argument (or part of the argument)
// 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
.adjustments()
.items()
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/ptr_offset_with_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn is_expr_ty_usize(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {

// Is the type of the expression a raw pointer?
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(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/swap_ptr_to_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl LateLintPass<'_> for SwapPtrToRef {
fn is_ptr_to_ref(cx: &LateContext<'_>, e: &Expr<'_>, ctxt: SyntaxContext) -> (bool, Option<Span>) {
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, borrowed_expr) = e.kind
&& let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind
&& cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr()
&& cx.typeck_results().expr_ty(derefed_expr).is_raw_ptr()
{
(
true,
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/eager_or_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
self.eagerness |= NoChange;
},
// 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(_, e)
if matches!(
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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(())
},
ExprKind::MethodCall(..)
Expand Down

0 comments on commit 7cd3b8c

Please sign in to comment.