Skip to content

Commit 432bce6

Browse files
authored
Rollup merge of rust-lang#122813 - nnethercote:nicer-quals, r=compiler-errors
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
2 parents c4f14ed + 0aea3ed commit 432bce6

14 files changed

+60
-59
lines changed

clippy_lints/src/derivable_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{
99
};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
12-
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
12+
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults};
1313
use rustc_session::impl_lint_pass;
1414
use rustc_span::sym;
1515

@@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool {
7979
fn contains_trait_object(ty: Ty<'_>) -> bool {
8080
match ty.kind() {
8181
ty::Ref(_, ty, _) => contains_trait_object(*ty),
82-
Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
82+
ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
8383
ty::Dynamic(..) => true,
8484
_ => false,
8585
}
@@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
198198
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
199199
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
200200
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
201-
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
201+
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
202202
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
203203
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
204204
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()

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;
7+
use rustc_middle::ty;
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 RawPtr(ty, _) = arg_kind
47+
&& let ty::RawPtr(ty, _) = arg_kind
4848
&& is_c_void(cx, *ty)
4949
{
5050
let msg = format!("creating a `{type_str}` from a void raw pointer");

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_hir::{self as hir, intravisit, HirIdSet};
1+
use rustc_hir::{self as hir, intravisit, HirId, HirIdSet};
22
use rustc_lint::LateContext;
33
use rustc_middle::ty;
44
use rustc_span::def_id::LocalDefId;
@@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>(
7474
}
7575
}
7676

77-
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> {
77+
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
7878
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
7979
&arg.pat.kind,
8080
cx.maybe_typeck_results()

clippy_lints/src/functions/result.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_errors::Diag;
22
use rustc_hir as hir;
33
use rustc_lint::{LateContext, LintContext};
44
use rustc_middle::lint::in_external_macro;
5-
use rustc_middle::ty::{Adt, Ty};
5+
use rustc_middle::ty::{self, Ty};
66
use rustc_span::{sym, Span};
77

88
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
@@ -25,7 +25,7 @@ fn result_err_ty<'tcx>(
2525
.tcx
2626
.instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output())
2727
&& is_type_diagnostic_item(cx, ty, sym::Result)
28-
&& let Adt(_, args) = ty.kind()
28+
&& let ty::Adt(_, args) = ty.kind()
2929
{
3030
let err_ty = args.type_at(1);
3131
Some((hir_ty, err_ty))
@@ -86,7 +86,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S
8686
}
8787

8888
fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) {
89-
if let Adt(adt, subst) = err_ty.kind()
89+
if let ty::Adt(adt, subst) = err_ty.kind()
9090
&& let Some(local_def_id) = err_ty
9191
.ty_adt_def()
9292
.expect("already checked this is adt")

clippy_lints/src/implicit_saturating_add.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128;
77
use rustc_errors::Applicability;
88
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
99
use rustc_lint::{LateContext, LateLintPass};
10-
use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy};
10+
use rustc_middle::ty::{IntTy, Ty, UintTy};
1111
use rustc_session::declare_lint_pass;
1212

1313
declare_clippy_lint! {
@@ -97,6 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
9797
}
9898

9999
fn get_int_max(ty: Ty<'_>) -> Option<u128> {
100+
use rustc_middle::ty::{Int, Uint};
100101
match ty.peel_refs().kind() {
101102
Int(IntTy::I8) => i8::MAX.try_into().ok(),
102103
Int(IntTy::I16) => i16::MAX.try_into().ok(),

clippy_lints/src/index_refutable_slice.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
77
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
88
use rustc_errors::Applicability;
99
use rustc_hir as hir;
10+
use rustc_hir::HirId;
1011
use rustc_hir::intravisit::{self, Visitor};
1112
use rustc_lint::{LateContext, LateLintPass};
1213
use rustc_middle::hir::nested_filter;
@@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
8788
extract_msrv_attr!(LateContext);
8889
}
8990

90-
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> {
91-
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
92-
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
91+
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<HirId, SliceLintInformation> {
92+
let mut removed_pat: FxHashSet<HirId> = FxHashSet::default();
93+
let mut slices: FxIndexMap<HirId, SliceLintInformation> = FxIndexMap::default();
9394
pat.walk_always(|pat| {
9495
// We'll just ignore mut and ref mut for simplicity sake right now
9596
if let hir::PatKind::Binding(
@@ -206,10 +207,10 @@ impl SliceLintInformation {
206207

207208
fn filter_lintable_slices<'tcx>(
208209
cx: &LateContext<'tcx>,
209-
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
210+
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
210211
max_suggested_slice: u64,
211212
scope: &'tcx hir::Expr<'tcx>,
212-
) -> FxIndexMap<hir::HirId, SliceLintInformation> {
213+
) -> FxIndexMap<HirId, SliceLintInformation> {
213214
let mut visitor = SliceIndexLintingVisitor {
214215
cx,
215216
slice_lint_info,
@@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>(
223224

224225
struct SliceIndexLintingVisitor<'a, 'tcx> {
225226
cx: &'a LateContext<'tcx>,
226-
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
227+
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
227228
max_suggested_slice: u64,
228229
}
229230

clippy_lints/src/large_enum_variant.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::Applicability;
77
use rustc_hir::{Item, ItemKind};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::lint::in_external_macro;
10-
use rustc_middle::ty::{Adt, Ty};
10+
use rustc_middle::ty::{self, Ty};
1111
use rustc_session::impl_lint_pass;
1212
use rustc_span::Span;
1313

@@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
8282
}
8383
if let ItemKind::Enum(ref def, _) = item.kind {
8484
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
85-
let Adt(adt, subst) = ty.kind() else {
85+
let ty::Adt(adt, subst) = ty.kind() else {
8686
panic!("already checked whether this is an enum")
8787
};
8888
if adt.variants().len() <= 1 {
@@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
167167
}
168168

169169
fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
170-
if let Adt(_def, args) = ty.kind()
170+
if let ty::Adt(_def, args) = ty.kind()
171171
&& args.types().next().is_some()
172172
&& let Some(copy_trait) = cx.tcx.lang_items().copy_trait()
173173
{

clippy_lints/src/methods/unnecessary_join.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::ast::LitKind;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind, LangItem};
66
use rustc_lint::LateContext;
7-
use rustc_middle::ty::{Ref, Slice};
7+
use rustc_middle::ty;
88
use rustc_span::Span;
99

1010
use super::UNNECESSARY_JOIN;
@@ -18,9 +18,9 @@ pub(super) fn check<'tcx>(
1818
) {
1919
let applicability = Applicability::MachineApplicable;
2020
let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg);
21-
if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
21+
if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
2222
// the turbofish for collect is ::<Vec<String>>
23-
&& let Slice(slice) = ref_type.kind()
23+
&& let ty::Slice(slice) = ref_type.kind()
2424
&& is_type_lang_item(cx, *slice, LangItem::String)
2525
// the argument for join is ""
2626
&& let ExprKind::Lit(spanned) = &join_arg.kind

clippy_lints/src/mut_key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method};
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_hir as hir;
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{Adt, Ty};
7+
use rustc_middle::ty::{self, Ty};
88
use rustc_session::impl_lint_pass;
99
use rustc_span::def_id::LocalDefId;
1010
use rustc_span::symbol::sym;
@@ -153,7 +153,7 @@ impl MutableKeyType {
153153
// generics (because the compiler cannot ensure immutability for unknown types).
154154
fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
155155
let ty = ty.peel_refs();
156-
if let Adt(def, args) = ty.kind() {
156+
if let ty::Adt(def, args) = ty.kind() {
157157
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
158158
.iter()
159159
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did()));

clippy_lints/src/non_copy_const.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId};
1818
use rustc_middle::ty::adjustment::Adjust;
1919
use rustc_middle::ty::{self, Ty, TyCtxt};
2020
use rustc_session::impl_lint_pass;
21-
use rustc_span::{sym, InnerSpan, Span};
21+
use rustc_span::{sym, DUMMY_SP, InnerSpan, Span};
2222
use rustc_target::abi::VariantIdx;
2323

2424
// FIXME: this is a correctness problem but there's no suitable
@@ -290,9 +290,7 @@ impl NonCopyConst {
290290
promoted: None,
291291
};
292292
let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx);
293-
let result = cx
294-
.tcx
295-
.const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP);
293+
let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP);
296294
self.is_value_unfrozen_raw(cx, result, ty)
297295
}
298296

@@ -303,7 +301,7 @@ impl NonCopyConst {
303301
cx.tcx,
304302
cx.param_env,
305303
ty::UnevaluatedConst::new(def_id, args),
306-
rustc_span::DUMMY_SP,
304+
DUMMY_SP,
307305
);
308306
self.is_value_unfrozen_raw(cx, result, ty)
309307
}

clippy_lints/src/operators/assign_op_pattern.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method};
66
use core::ops::ControlFlow;
77
use rustc_errors::Applicability;
88
use rustc_hir as hir;
9+
use rustc_hir::{HirId, HirIdSet};
910
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1011
use rustc_lint::LateContext;
1112
use rustc_middle::mir::FakeReadCause;
@@ -98,10 +99,10 @@ pub(super) fn check<'tcx>(
9899
}
99100
}
100101

101-
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
102-
struct S(hir::HirIdSet);
102+
fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
103+
struct S(HirIdSet);
103104
impl Delegate<'_> for S {
104-
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) {
105+
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
105106
if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) {
106107
self.0.insert(match place.place.base {
107108
PlaceBase::Local(id) => id,
@@ -111,13 +112,13 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
111112
}
112113
}
113114

114-
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
115-
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
116-
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {}
117-
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
115+
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
116+
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
117+
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
118+
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
118119
}
119120

120-
let mut s = S(hir::HirIdSet::default());
121+
let mut s = S(HirIdSet::default());
121122
let infcx = cx.tcx.infer_ctxt().build();
122123
let mut v = ExprUseVisitor::new(
123124
&mut s,
@@ -130,10 +131,10 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
130131
s.0
131132
}
132133

133-
fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet {
134-
struct S(hir::HirIdSet);
134+
fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet {
135+
struct S(HirIdSet);
135136
impl Delegate<'_> for S {
136-
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) {
137+
fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) {
137138
if matches!(kind, BorrowKind::MutBorrow) {
138139
self.0.insert(match place.place.base {
139140
PlaceBase::Local(id) => id,
@@ -143,13 +144,13 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
143144
}
144145
}
145146

146-
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
147-
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
148-
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {}
149-
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {}
147+
fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
148+
fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
149+
fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {}
150+
fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {}
150151
}
151152

152-
let mut s = S(hir::HirIdSet::default());
153+
let mut s = S(HirIdSet::default());
153154
let infcx = cx.tcx.infer_ctxt().build();
154155
let mut v = ExprUseVisitor::new(
155156
&mut s,

clippy_lints/src/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_i
88
use hir::LifetimeName;
99
use rustc_errors::{Applicability, MultiSpan};
1010
use rustc_hir::def_id::DefId;
11-
use rustc_hir::hir_id::HirIdMap;
11+
use rustc_hir::hir_id::{HirId, HirIdMap};
1212
use rustc_hir::intravisit::{walk_expr, Visitor};
1313
use rustc_hir::{
1414
self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg,
@@ -324,7 +324,7 @@ struct PtrArgReplacement {
324324

325325
struct PtrArg<'tcx> {
326326
idx: usize,
327-
emission_id: hir::HirId,
327+
emission_id: HirId,
328328
span: Span,
329329
ty_did: DefId,
330330
ty_name: Symbol,

0 commit comments

Comments
 (0)