Skip to content

Commit 1816caa

Browse files
committed
Auto merge of rust-lang#113376 - Nilstrieb:pointer-coercions-are-not-casts-because-that-sounds-way-to-general-aaaa, r=oli-obk
Rename `adjustment::PointerCast` and variants using it to `PointerCoercion` It makes it sounds like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a little enum variants. Make it clear there these are only coercions and that people who see this and think "why are so many pointer related casts not in these variants" aren't insane. This enum was added in rust-lang#59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing. r? oli-obk
2 parents 87373d7 + b5ac726 commit 1816caa

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

clippy_lints/src/derivable_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{
99
Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass};
12-
use rustc_middle::ty::adjustment::{Adjust, PointerCast};
12+
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
1313
use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults};
1414
use rustc_session::{declare_tool_lint, impl_lint_pass};
1515
use rustc_span::sym;
@@ -116,7 +116,7 @@ fn check_struct<'tcx>(
116116
let is_default_without_adjusts = |expr| {
117117
is_default_equivalent(cx, expr)
118118
&& typeck_results.expr_adjustments(expr).iter().all(|adj| {
119-
!matches!(adj.kind, Adjust::Pointer(PointerCast::Unsize)
119+
!matches!(adj.kind, Adjust::Pointer(PointerCoercion::Unsize)
120120
if contains_trait_object(adj.target))
121121
})
122122
};

clippy_lints/src/pass_by_ref_or_value.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir as hir;
1414
use rustc_hir::intravisit::FnKind;
1515
use rustc_hir::{BindingAnnotation, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind};
1616
use rustc_lint::{LateContext, LateLintPass};
17-
use rustc_middle::ty::adjustment::{Adjust, PointerCast};
17+
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
1818
use rustc_middle::ty::layout::LayoutOf;
1919
use rustc_middle::ty::{self, RegionKind};
2020
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -195,7 +195,7 @@ impl<'tcx> PassByRefOrValue {
195195
.adjustments()
196196
.items()
197197
.flat_map(|(_, a)| a)
198-
.any(|a| matches!(a.kind, Adjust::Pointer(PointerCast::UnsafeFnPointer)))
198+
.any(|a| matches!(a.kind, Adjust::Pointer(PointerCoercion::UnsafeFnPointer)))
199199
{
200200
continue;
201201
}

clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir::{
1616
};
1717
use rustc_middle::traits::{ImplSource, ObligationCause};
1818
use rustc_middle::ty::subst::GenericArgKind;
19-
use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt};
19+
use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
2020
use rustc_middle::ty::{BoundConstness, TraitRef};
2121
use rustc_semver::RustcVersion;
2222
use rustc_span::symbol::sym;
@@ -119,18 +119,18 @@ fn check_rvalue<'tcx>(
119119
| CastKind::FloatToFloat
120120
| CastKind::FnPtrToPtr
121121
| CastKind::PtrToPtr
122-
| CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer),
122+
| CastKind::PointerCoercion(PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer),
123123
operand,
124124
_,
125125
) => check_operand(tcx, operand, span, body),
126126
Rvalue::Cast(
127-
CastKind::Pointer(
128-
PointerCast::UnsafeFnPointer | PointerCast::ClosureFnPointer(_) | PointerCast::ReifyFnPointer,
127+
CastKind::PointerCoercion(
128+
PointerCoercion::UnsafeFnPointer | PointerCoercion::ClosureFnPointer(_) | PointerCoercion::ReifyFnPointer,
129129
),
130130
_,
131131
_,
132132
) => Err((span, "function pointer casts are not allowed in const fn".into())),
133-
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), op, cast_ty) => {
133+
Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::Unsize), op, cast_ty) => {
134134
let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) {
135135
deref_ty.ty
136136
} else {

0 commit comments

Comments
 (0)