Skip to content

Commit 7cd3b8c

Browse files
committed
Auto merge of #135994 - 1c3t3a:rename-unsafe-ptr, r=oli-obk
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 rust-lang/rust#134424. r? `@Noratrieb`
2 parents 3a0b1ae + 15d08ef commit 7cd3b8c

9 files changed

+11
-11
lines changed

clippy_lints/src/casts/cast_ptr_alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
6666
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
6767
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
6868
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
69-
&& cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr()
69+
&& cx.tcx.type_of(def_id).instantiate_identity().is_raw_ptr()
7070
{
7171
true
7272
} else {

clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ fn try_parse_ref_op<'tcx>(
682682
},
683683
[arg],
684684
) => (true, typeck.qpath_res(path, *hir_id).opt_def_id()?, arg),
685-
ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_unsafe_ptr() => {
685+
ExprKind::Unary(UnOp::Deref, sub_expr) if !typeck.expr_ty(sub_expr).is_raw_ptr() => {
686686
return Some((RefOp::Deref, sub_expr));
687687
},
688688
ExprKind::AddrOf(BorrowKind::Ref, mutability, sub_expr) => return Some((RefOp::AddrOf(mutability), sub_expr)),

clippy_lints/src/multiple_unsafe_ops_per_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn collect_unsafe_exprs<'tcx>(
122122
unsafe_ops.push(("access of a mutable static occurs here", expr.span));
123123
},
124124

125-
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_unsafe_ptr() => {
125+
ExprKind::Unary(UnOp::Deref, e) if cx.typeck_results().expr_ty_adjusted(e).is_raw_ptr() => {
126126
unsafe_ops.push(("raw pointer dereference occurs here", expr.span));
127127
},
128128

clippy_lints/src/operators/ptr_eq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn expr_as_cast_to_usize<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>
5353
// If the given expression is a cast to a `*const` pointer, return the lhs of the cast
5454
// E.g., `foo as *const _` returns `foo`.
5555
fn expr_as_cast_to_raw_pointer<'tcx>(cx: &LateContext<'tcx>, cast_expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
56-
if cx.typeck_results().expr_ty(cast_expr).is_unsafe_ptr() {
56+
if cx.typeck_results().expr_ty(cast_expr).is_raw_ptr() {
5757
if let ExprKind::Cast(expr, _) = cast_expr.kind {
5858
return Some(expr);
5959
}

clippy_lints/src/pass_by_ref_or_value.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ impl PassByRefOrValue {
179179
&& let hir::TyKind::Ref(_, MutTy { ty: decl_ty, .. }) = input.kind
180180
{
181181
if let Some(typeck) = cx.maybe_typeck_results() {
182-
// Don't lint if an unsafe pointer is created.
183-
// TODO: Limit the check only to unsafe pointers to the argument (or part of the argument)
182+
// Don't lint if a raw pointer is created.
183+
// TODO: Limit the check only to raw pointers to the argument (or part of the argument)
184184
// which escape the current function.
185-
if typeck.node_types().items().any(|(_, &ty)| ty.is_unsafe_ptr())
185+
if typeck.node_types().items().any(|(_, &ty)| ty.is_raw_ptr())
186186
|| typeck
187187
.adjustments()
188188
.items()

clippy_lints/src/ptr_offset_with_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn is_expr_ty_usize(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
111111

112112
// Is the type of the expression a raw pointer?
113113
fn is_expr_ty_raw_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
114-
cx.typeck_results().expr_ty(expr).is_unsafe_ptr()
114+
cx.typeck_results().expr_ty(expr).is_raw_ptr()
115115
}
116116

117117
fn build_suggestion(

clippy_lints/src/swap_ptr_to_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl LateLintPass<'_> for SwapPtrToRef {
7676
fn is_ptr_to_ref(cx: &LateContext<'_>, e: &Expr<'_>, ctxt: SyntaxContext) -> (bool, Option<Span>) {
7777
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, borrowed_expr) = e.kind
7878
&& let ExprKind::Unary(UnOp::Deref, derefed_expr) = borrowed_expr.kind
79-
&& cx.typeck_results().expr_ty(derefed_expr).is_unsafe_ptr()
79+
&& cx.typeck_results().expr_ty(derefed_expr).is_raw_ptr()
8080
{
8181
(
8282
true,

clippy_utils/src/eager_or_lazy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
217217
self.eagerness |= NoChange;
218218
},
219219
// Dereferences should be cheap, but dereferencing a raw pointer earlier may not be safe.
220-
ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => (),
220+
ExprKind::Unary(UnOp::Deref, e) if !self.cx.typeck_results().expr_ty(e).is_raw_ptr() => (),
221221
ExprKind::Unary(UnOp::Deref, _) => self.eagerness |= NoChange,
222222
ExprKind::Unary(_, e)
223223
if matches!(

clippy_utils/src/visitors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool {
417417
}
418418
fn visit_expr(&mut self, e: &'tcx Expr<'_>) -> Self::Result {
419419
match e.kind {
420-
ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_unsafe_ptr() => {
420+
ExprKind::Unary(UnOp::Deref, e) if self.cx.typeck_results().expr_ty(e).is_raw_ptr() => {
421421
ControlFlow::Break(())
422422
},
423423
ExprKind::MethodCall(..)

0 commit comments

Comments
 (0)