Skip to content

Commit 6a40dab

Browse files
And the tools too
1 parent 7be0dbe commit 6a40dab

20 files changed

+44
-71
lines changed

src/tools/clippy/clippy_lints/src/casts/as_ptr_cast_mut.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ use rustc_errors::Applicability;
44
use rustc_hir::{Expr, ExprKind};
55
use rustc_lint::LateContext;
66
use rustc_middle::mir::Mutability;
7-
use rustc_middle::ty::{self, Ty, TypeAndMut};
7+
use rustc_middle::ty::{self, Ty};
88

99
use super::AS_PTR_CAST_MUT;
1010

1111
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>) {
12-
if let ty::RawPtr(TypeAndMut {
13-
mutbl: Mutability::Mut,
14-
ty: ptrty,
15-
}) = cast_to.kind()
16-
&& let ty::RawPtr(TypeAndMut {
17-
mutbl: Mutability::Not, ..
18-
}) = cx.typeck_results().node_type(cast_expr.hir_id).kind()
12+
if let ty::RawPtr(ptrty, Mutability::Mut) = cast_to.kind()
13+
&& let ty::RawPtr(_, Mutability::Not) = cx.typeck_results().node_type(cast_expr.hir_id).kind()
1914
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
2015
&& method_name.ident.name == rustc_span::sym::as_ptr
2116
&& let Some(as_ptr_did) = cx

src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
3333
}
3434

3535
fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) {
36-
if let ty::RawPtr(from_ptr_ty) = &cast_from.kind()
37-
&& let ty::RawPtr(to_ptr_ty) = &cast_to.kind()
38-
&& let Ok(from_layout) = cx.layout_of(from_ptr_ty.ty)
39-
&& let Ok(to_layout) = cx.layout_of(to_ptr_ty.ty)
36+
if let ty::RawPtr(from_ptr_ty, _) = *cast_from.kind()
37+
&& let ty::RawPtr(to_ptr_ty, _) = *cast_to.kind()
38+
&& let Ok(from_layout) = cx.layout_of(from_ptr_ty)
39+
&& let Ok(to_layout) = cx.layout_of(to_ptr_ty)
4040
&& from_layout.align.abi < to_layout.align.abi
4141
// with c_void, we inherently need to trust the user
42-
&& !is_c_void(cx, from_ptr_ty.ty)
42+
&& !is_c_void(cx, from_ptr_ty)
4343
// when casting from a ZST, we don't know enough to properly lint
4444
&& !from_layout.is_zst()
4545
&& !is_used_as_unaligned(cx, expr)

src/tools/clippy/clippy_lints/src/casts/cast_slice_from_raw_parts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ fn raw_parts_kind(cx: &LateContext<'_>, did: DefId) -> Option<RawPartsKind> {
2525

2626
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_to: Ty<'_>, msrv: &Msrv) {
2727
if msrv.meets(msrvs::PTR_SLICE_RAW_PARTS)
28-
&& let ty::RawPtr(ptrty) = cast_to.kind()
29-
&& let ty::Slice(_) = ptrty.ty.kind()
28+
&& let ty::RawPtr(ptrty, _) = cast_to.kind()
29+
&& let ty::Slice(_) = ptrty.kind()
3030
&& let ExprKind::Call(fun, [ptr_arg, len_arg]) = cast_expr.peel_blocks().kind
3131
&& let ExprKind::Path(ref qpath) = fun.kind
3232
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()

src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::{Expr, ExprKind, Mutability, QPath, TyKind};
77
use rustc_hir_pretty::qpath_to_string;
88
use rustc_lint::LateContext;
9-
use rustc_middle::ty::{self, TypeAndMut};
9+
use rustc_middle::ty;
1010
use rustc_span::sym;
1111

1212
use super::PTR_AS_PTR;

src/tools/clippy/clippy_lints/src/casts/ptr_cast_constness.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::sugg::Sugg;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, Mutability};
66
use rustc_lint::LateContext;
7-
use rustc_middle::ty::{self, Ty, TypeAndMut};
7+
use rustc_middle::ty::{self, Ty};
88

99
use super::PTR_CAST_CONSTNESS;
1010

@@ -17,14 +17,8 @@ pub(super) fn check<'tcx>(
1717
msrv: &Msrv,
1818
) {
1919
if msrv.meets(msrvs::POINTER_CAST_CONSTNESS)
20-
&& let ty::RawPtr(TypeAndMut {
21-
mutbl: from_mutbl,
22-
ty: from_ty,
23-
}) = cast_from.kind()
24-
&& let ty::RawPtr(TypeAndMut {
25-
mutbl: to_mutbl,
26-
ty: to_ty,
27-
}) = cast_to.kind()
20+
&& let ty::RawPtr(from_ty, from_mutbl) = cast_from.kind()
21+
&& let ty::RawPtr(to_ty, to_mutbl) = cast_to.kind()
2822
&& matches!(
2923
(from_mutbl, to_mutbl),
3024
(Mutability::Not, Mutability::Mut) | (Mutability::Mut, Mutability::Not)

src/tools/clippy/clippy_lints/src/casts/ref_as_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::{expr_use_ctxt, is_no_std_crate, ExprUseNode};
55
use rustc_errors::Applicability;
66
use rustc_hir::{Expr, Mutability, Ty, TyKind};
77
use rustc_lint::LateContext;
8-
use rustc_middle::ty::{self, TypeAndMut};
8+
use rustc_middle::ty;
99

1010
use super::REF_AS_PTR;
1111

src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
44
use rustc_hir::def_id::DefId;
55
use rustc_hir::{Expr, ExprKind, QPath};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{RawPtr, TypeAndMut};
7+
use rustc_middle::ty::{RawPtr};
88
use rustc_session::declare_lint_pass;
99
use rustc_span::sym;
1010

@@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr {
4444
&& seg.ident.name == sym!(from_raw)
4545
&& let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id))
4646
&& let arg_kind = cx.typeck_results().expr_ty(arg).kind()
47-
&& let ty::RawPtr(ty, _) = arg_kind
47+
&& let RawPtr(ty, _) = arg_kind
4848
&& is_c_void(cx, *ty)
4949
{
5050
let msg = format!("creating a `{type_str}` from a void raw pointer");

src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_errors::Applicability;
1010
use rustc_hir::{Expr, Mutability};
1111
use rustc_lint::LateContext;
1212
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
13-
use rustc_middle::ty::{self, EarlyBinder, Ty, TypeAndMut};
13+
use rustc_middle::ty::{self, EarlyBinder, Ty};
1414
use rustc_span::sym;
1515

1616
pub(super) fn check(
@@ -160,7 +160,7 @@ fn is_ref_iterable<'tcx>(
160160
let self_ty = if mutbl.is_mut() {
161161
self_ty
162162
} else {
163-
Ty::new_ref(cx.tcx, region, TypeAndMut { ty, mutbl })
163+
Ty::new_ref(cx.tcx, region, ty, mutbl)
164164
};
165165
if implements_trait(cx, self_ty, trait_id, &[])
166166
&& let Some(ty) =
@@ -175,7 +175,7 @@ fn is_ref_iterable<'tcx>(
175175
&& !self_ty.is_ref()
176176
{
177177
// Attempt to borrow
178-
let self_ty = Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, TypeAndMut { ty: self_ty, mutbl });
178+
let self_ty = Ty::new_ref(cx.tcx, cx.tcx.lifetimes.re_erased, self_ty, mutbl);
179179
if implements_trait(cx, self_ty, trait_id, &[])
180180
&& let Some(ty) = make_normalized_projection(cx.tcx, cx.param_env, trait_id, sym!(IntoIter), [self_ty])
181181
&& ty == res_ty

src/tools/clippy/clippy_lints/src/mut_reference.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ fn check_arguments<'tcx>(
8484
for (argument, parameter) in iter::zip(arguments, parameters) {
8585
match parameter.kind() {
8686
ty::Ref(_, _, Mutability::Not)
87-
| ty::RawPtr(ty::TypeAndMut {
88-
mutbl: Mutability::Not, ..
89-
}) => {
87+
| ty::RawPtr(_, Mutability::Not) => {
9088
if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) = argument.kind {
9189
span_lint(
9290
cx,

src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::intravisit::{walk_expr, Visitor};
88
use rustc_hir::{self as hir};
99
use rustc_lint::{LateContext, LateLintPass, LintContext};
10-
use rustc_middle::ty::{GenericArgKind, Ty, TypeAndMut};
10+
use rustc_middle::ty::{GenericArgKind, Ty};
1111
use rustc_session::impl_lint_pass;
1212
use rustc_span::symbol::Ident;
1313
use rustc_span::{sym, Span, DUMMY_SP};

src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use clippy_utils::diagnostics::span_lint_and_help;
55
use rustc_hir::{BinOpKind, Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{self, Ty, TypeAndMut};
7+
use rustc_middle::ty::{self, Ty};
88
use rustc_session::declare_lint_pass;
99
use rustc_span::sym;
1010

src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_middle::ty::{self, Ty};
77
/// Checks for `crosspointer_transmute` lint.
88
/// Returns `true` if it's triggered, otherwise returns `false`.
99
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool {
10-
match (&from_ty.kind(), &to_ty.kind()) {
11-
(ty::RawPtr(from_ptr), _) if from_ptr.ty == to_ty => {
10+
match (*from_ty.kind(), *to_ty.kind()) {
11+
(ty::RawPtr(from_ptr_ty, _), _) if from_ptr_ty == to_ty => {
1212
span_lint(
1313
cx,
1414
CROSSPOINTER_TRANSMUTE,
@@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty
1717
);
1818
true
1919
},
20-
(_, ty::RawPtr(to_ptr)) if to_ptr.ty == from_ty => {
20+
(_, ty::RawPtr(to_ptr_ty, _)) if to_ptr_ty == from_ty => {
2121
span_lint(
2222
cx,
2323
CROSSPOINTER_TRANSMUTE,

src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ pub(super) fn check<'tcx>(
1616
arg: &'tcx Expr<'_>,
1717
) -> bool {
1818
match (&from_ty.kind(), &to_ty.kind()) {
19-
(ty::RawPtr(_, _), ty::RawPtr(to_ty)) => {
19+
(ty::RawPtr(_, _), ty::RawPtr(to_ty, to_mutbl)) => {
2020
span_lint_and_then(
2121
cx,
2222
TRANSMUTE_PTR_TO_PTR,
2323
e.span,
2424
"transmute from a pointer to a pointer",
2525
|diag| {
2626
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
27-
let sugg = arg.as_ty(Ty::new_ptr(cx.tcx, *to_ty));
27+
let sugg = arg.as_ty(Ty::new_ptr(cx.tcx, *to_ty, *to_mutbl));
2828
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
2929
}
3030
},

src/tools/clippy/clippy_lints/src/transmute/transmute_ptr_to_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub(super) fn check<'tcx>(
2020
msrv: &Msrv,
2121
) -> bool {
2222
match (&from_ty.kind(), &to_ty.kind()) {
23-
(ty::RawPtr(from_ptr_ty), ty::Ref(_, to_ref_ty, mutbl)) => {
23+
(ty::RawPtr(from_ptr_ty, _), ty::Ref(_, to_ref_ty, mutbl)) => {
2424
span_lint_and_then(
2525
cx,
2626
TRANSMUTE_PTR_TO_REF,
@@ -44,7 +44,7 @@ pub(super) fn check<'tcx>(
4444
} else {
4545
sugg::make_unop(deref, arg.as_ty(format!("{cast} {ty_snip}"))).to_string()
4646
}
47-
} else if from_ptr_ty.ty == *to_ref_ty {
47+
} else if *from_ptr_ty == *to_ref_ty {
4848
if from_ptr_ty.has_erased_regions() {
4949
if msrv.meets(msrvs::POINTER_CAST) {
5050
format!("{deref}{}.cast::<{to_ref_ty}>()", arg.maybe_par())

src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ pub(super) fn check<'tcx>(
1919
) -> bool {
2020
let mut triggered = false;
2121

22-
if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (&from_ty.kind(), &to_ty.kind()) {
22+
if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (*from_ty.kind(), *to_ty.kind()) {
2323
if let ty::Slice(slice_ty) = *ty_from.kind()
2424
&& ty_to.is_str()
2525
&& let ty::Uint(ty::UintTy::U8) = slice_ty.kind()
2626
&& from_mutbl == to_mutbl
2727
{
2828
let Some(top_crate) = std_or_core(cx) else { return true };
2929

30-
let postfix = if *from_mutbl == Mutability::Mut { "_mut" } else { "" };
30+
let postfix = if from_mutbl == Mutability::Mut { "_mut" } else { "" };
3131

3232
let snippet = snippet(cx, arg.span, "..");
3333

@@ -53,18 +53,10 @@ pub(super) fn check<'tcx>(
5353
"transmute from a reference to a reference",
5454
|diag| {
5555
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
56-
let ty_from_and_mut = ty::TypeAndMut {
57-
ty: *ty_from,
58-
mutbl: *from_mutbl,
59-
};
60-
let ty_to_and_mut = ty::TypeAndMut {
61-
ty: *ty_to,
62-
mutbl: *to_mutbl,
63-
};
6456
let sugg_paren = arg
65-
.as_ty(Ty::new_ptr(cx.tcx, ty_from_and_mut))
66-
.as_ty(Ty::new_ptr(cx.tcx, ty_to_and_mut));
67-
let sugg = if *to_mutbl == Mutability::Mut {
57+
.as_ty(Ty::new_ptr(cx.tcx, ty_from, from_mutbl))
58+
.as_ty(Ty::new_ptr(cx.tcx, ty_to, to_mutbl));
59+
let sugg = if to_mutbl == Mutability::Mut {
6860
sugg_paren.mut_addr_deref()
6961
} else {
7062
sugg_paren.addr_deref()

src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::ty::is_c_void;
44
use rustc_hir::Expr;
55
use rustc_lint::LateContext;
6-
use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, TypeAndMut, UintTy};
6+
use rustc_middle::ty::{self, GenericArgsRef, IntTy, Ty, UintTy};
77

88
#[expect(clippy::too_many_lines)]
99
pub(super) fn check<'tcx>(

src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(super) fn check<'tcx>(
1515
to_ty: Ty<'tcx>,
1616
arg: &'tcx Expr<'_>,
1717
) -> bool {
18-
match (&from_ty.kind(), &to_ty.kind()) {
18+
match (*from_ty.kind(), *to_ty.kind()) {
1919
_ if from_ty == to_ty && !from_ty.has_erased_regions() => {
2020
span_lint(
2121
cx,
@@ -25,7 +25,7 @@ pub(super) fn check<'tcx>(
2525
);
2626
true
2727
},
28-
(ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty)) => {
28+
(ty::Ref(_, rty, rty_mutbl), ty::RawPtr(ptr_ty, ptr_mutbl)) => {
2929
// No way to give the correct suggestion here. Avoid linting for now.
3030
if !rty.has_erased_regions() {
3131
span_lint_and_then(
@@ -35,15 +35,10 @@ pub(super) fn check<'tcx>(
3535
"transmute from a reference to a pointer",
3636
|diag| {
3737
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
38-
let rty_and_mut = ty::TypeAndMut {
39-
ty: *rty,
40-
mutbl: *rty_mutbl,
41-
};
42-
43-
let sugg = if *ptr_ty == rty_and_mut {
38+
let sugg = if ptr_ty == rty && rty_mutbl == ptr_mutbl {
4439
arg.as_ty(to_ty)
4540
} else {
46-
arg.as_ty(Ty::new_ptr(cx.tcx, rty_and_mut)).as_ty(to_ty)
41+
arg.as_ty(Ty::new_ptr(cx.tcx, rty, rty_mutbl)).as_ty(to_ty)
4742
};
4843

4944
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);

src/tools/clippy/clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use rustc_middle::ty::fast_reject::SimplifiedType;
112112
use rustc_middle::ty::layout::IntegerExt;
113113
use rustc_middle::ty::{
114114
self as rustc_ty, Binder, BorrowKind, ClosureKind, EarlyBinder, FloatTy, GenericArgsRef, IntTy, ParamEnv,
115-
ParamEnvAnd, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, UintTy, UpvarCapture,
115+
ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt, UintTy, UpvarCapture,
116116
};
117117
use rustc_span::hygiene::{ExpnKind, MacroKind};
118118
use rustc_span::source_map::SourceMap;

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl NewPermission {
9090
}
9191
}
9292
}
93-
ty::RawPtr(ty::TypeAndMut { mutbl: Mutability::Mut, .. }) => {
93+
ty::RawPtr(_, Mutability::Mut) => {
9494
assert!(protector.is_none()); // RetagKind can't be both FnEntry and Raw.
9595
// Mutable raw pointer. No access, not protected.
9696
NewPermission::Uniform {
@@ -114,7 +114,7 @@ impl NewPermission {
114114
// This fixes https://github.com/rust-lang/rust/issues/55005.
115115
}
116116
}
117-
ty::RawPtr(ty::TypeAndMut { mutbl: Mutability::Not, .. }) => {
117+
ty::RawPtr(_, Mutability::Not) => {
118118
assert!(protector.is_none()); // RetagKind can't be both FnEntry and Raw.
119119
// `*const T`, when freshly created, are read-only in the frozen part.
120120
NewPermission::FreezeSensitive {

src/tools/miri/src/machine.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rand::rngs::StdRng;
1212
use rand::Rng;
1313
use rand::SeedableRng;
1414

15-
use rustc_ast::ast::Mutability;
1615
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1716
#[allow(unused)]
1817
use rustc_data_structures::static_assert_size;
@@ -22,7 +21,7 @@ use rustc_middle::{
2221
ty::{
2322
self,
2423
layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout},
25-
Instance, Ty, TyCtxt, TypeAndMut,
24+
Instance, Ty, TyCtxt,
2625
},
2726
};
2827
use rustc_span::def_id::{CrateNum, DefId};

0 commit comments

Comments
 (0)