mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 14:38:46 +00:00
Auto merge of #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 #59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing. r? oli-obk
This commit is contained in:
commit
1816caaa76
3 changed files with 9 additions and 9 deletions
|
@ -9,7 +9,7 @@ use rustc_hir::{
|
|||
Body, Expr, ExprKind, GenericArg, Impl, ImplItemKind, Item, ItemKind, Node, PathSegment, QPath, TyKind,
|
||||
};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::adjustment::{Adjust, PointerCast};
|
||||
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
|
||||
use rustc_middle::ty::{self, Adt, AdtDef, SubstsRef, Ty, TypeckResults};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::sym;
|
||||
|
@ -116,7 +116,7 @@ fn check_struct<'tcx>(
|
|||
let is_default_without_adjusts = |expr| {
|
||||
is_default_equivalent(cx, expr)
|
||||
&& typeck_results.expr_adjustments(expr).iter().all(|adj| {
|
||||
!matches!(adj.kind, Adjust::Pointer(PointerCast::Unsize)
|
||||
!matches!(adj.kind, Adjust::Pointer(PointerCoercion::Unsize)
|
||||
if contains_trait_object(adj.target))
|
||||
})
|
||||
};
|
||||
|
|
|
@ -14,7 +14,7 @@ use rustc_hir as hir;
|
|||
use rustc_hir::intravisit::FnKind;
|
||||
use rustc_hir::{BindingAnnotation, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, Node, PatKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::adjustment::{Adjust, PointerCast};
|
||||
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::{self, RegionKind};
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
|
@ -195,7 +195,7 @@ impl<'tcx> PassByRefOrValue {
|
|||
.adjustments()
|
||||
.items()
|
||||
.flat_map(|(_, a)| a)
|
||||
.any(|a| matches!(a.kind, Adjust::Pointer(PointerCast::UnsafeFnPointer)))
|
||||
.any(|a| matches!(a.kind, Adjust::Pointer(PointerCoercion::UnsafeFnPointer)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use rustc_middle::mir::{
|
|||
};
|
||||
use rustc_middle::traits::{ImplSource, ObligationCause};
|
||||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, adjustment::PointerCoercion, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{BoundConstness, TraitRef};
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_span::symbol::sym;
|
||||
|
@ -119,18 +119,18 @@ fn check_rvalue<'tcx>(
|
|||
| CastKind::FloatToFloat
|
||||
| CastKind::FnPtrToPtr
|
||||
| CastKind::PtrToPtr
|
||||
| CastKind::Pointer(PointerCast::MutToConstPointer | PointerCast::ArrayToPointer),
|
||||
| CastKind::PointerCoercion(PointerCoercion::MutToConstPointer | PointerCoercion::ArrayToPointer),
|
||||
operand,
|
||||
_,
|
||||
) => check_operand(tcx, operand, span, body),
|
||||
Rvalue::Cast(
|
||||
CastKind::Pointer(
|
||||
PointerCast::UnsafeFnPointer | PointerCast::ClosureFnPointer(_) | PointerCast::ReifyFnPointer,
|
||||
CastKind::PointerCoercion(
|
||||
PointerCoercion::UnsafeFnPointer | PointerCoercion::ClosureFnPointer(_) | PointerCoercion::ReifyFnPointer,
|
||||
),
|
||||
_,
|
||||
_,
|
||||
) => Err((span, "function pointer casts are not allowed in const fn".into())),
|
||||
Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), op, cast_ty) => {
|
||||
Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::Unsize), op, cast_ty) => {
|
||||
let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) {
|
||||
deref_ty.ty
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue