Skip to content

Commit a7fecd6

Browse files
committed
Auto merge of rust-lang#10313 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 5adeebf + 19c07f8 commit a7fecd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+285
-244
lines changed

clippy_lints/src/booleans.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use if_chain::if_chain;
66
use rustc_ast::ast::LitKind;
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
9-
use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, UnOp};
9+
use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, UnOp};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
12+
use rustc_span::def_id::LocalDefId;
1213
use rustc_span::source_map::Span;
1314
use rustc_span::sym;
1415

@@ -82,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for NonminimalBool {
8283
_: &'tcx FnDecl<'_>,
8384
body: &'tcx Body<'_>,
8485
_: Span,
85-
_: HirId,
86+
_: LocalDefId,
8687
) {
8788
NonminimalBoolVisitor { cx }.visit_body(body);
8889
}

clippy_lints/src/casts/as_ptr_cast_mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
1717
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
1818
&& method_name.ident.name == rustc_span::sym::as_ptr
1919
&& let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
20-
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did)
20+
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).subst_identity()
2121
&& let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
2222
&& let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
2323
&& let Some(recv) = snippet_opt(cx, receiver.span)

clippy_lints/src/cognitive_complexity.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use clippy_utils::{get_async_fn_body, is_async_fn, LimitStack};
88
use core::ops::ControlFlow;
99
use rustc_ast::ast::Attribute;
1010
use rustc_hir::intravisit::FnKind;
11-
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId};
11+
use rustc_hir::{Body, Expr, ExprKind, FnDecl};
1212
use rustc_lint::{LateContext, LateLintPass, LintContext};
1313
use rustc_session::{declare_tool_lint, impl_lint_pass};
14+
use rustc_span::def_id::LocalDefId;
1415
use rustc_span::source_map::Span;
1516
use rustc_span::{sym, BytePos};
1617

@@ -140,9 +141,8 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
140141
decl: &'tcx FnDecl<'_>,
141142
body: &'tcx Body<'_>,
142143
span: Span,
143-
hir_id: HirId,
144+
def_id: LocalDefId,
144145
) {
145-
let def_id = cx.tcx.hir().local_def_id(hir_id);
146146
if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) {
147147
let expr = if is_async_fn(kind) {
148148
match get_async_fn_body(cx.tcx, body) {

clippy_lints/src/default_numeric_fallback.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
141141

142142
ExprKind::MethodCall(_, receiver, args, _) => {
143143
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
144-
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
144+
let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder();
145145
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
146146
self.ty_bounds.push((*bound).into());
147147
self.visit_expr(expr);
@@ -215,7 +215,7 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'
215215
let node_ty = cx.typeck_results().node_type_opt(hir_id)?;
216216
// We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs.
217217
match node_ty.kind() {
218-
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id)),
218+
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).subst_identity()),
219219
ty::FnPtr(fn_sig) => Some(*fn_sig),
220220
_ => None,
221221
}

clippy_lints/src/dereference.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn walk_parents<'tcx>(
759759
}) if span.ctxt() == ctxt => {
760760
let output = cx
761761
.tcx
762-
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id.to_def_id()).output());
762+
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output());
763763
Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx))
764764
},
765765

@@ -778,20 +778,20 @@ fn walk_parents<'tcx>(
778778

779779
Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind {
780780
ExprKind::Ret(_) => {
781-
let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap());
781+
let owner_id = cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap());
782782
Some(
783783
if let Node::Expr(
784784
closure_expr @ Expr {
785785
kind: ExprKind::Closure(closure),
786786
..
787787
},
788-
) = cx.tcx.hir().get(owner_id)
788+
) = cx.tcx.hir().get_by_def_id(owner_id)
789789
{
790790
closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence)
791791
} else {
792792
let output = cx
793793
.tcx
794-
.erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).output());
794+
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output());
795795
ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)
796796
},
797797
)
@@ -858,7 +858,7 @@ fn walk_parents<'tcx>(
858858
&& let subs = cx
859859
.typeck_results()
860860
.node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default()
861-
&& let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() {
861+
&& let impl_ty = if cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[0].is_ref() {
862862
// Trait methods taking `&self`
863863
sub_ty
864864
} else {
@@ -879,7 +879,7 @@ fn walk_parents<'tcx>(
879879
return Some(Position::MethodReceiver);
880880
}
881881
args.iter().position(|arg| arg.hir_id == child_id).map(|i| {
882-
let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i + 1];
882+
let ty = cx.tcx.fn_sig(id).subst_identity().skip_binder().inputs()[i + 1];
883883
// `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739
884884
// `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782
885885
if e.hir_id == child_id && method.args.is_none() && let ty::Param(param_ty) = ty.kind() {
@@ -896,7 +896,7 @@ fn walk_parents<'tcx>(
896896
} else {
897897
ty_auto_deref_stability(
898898
cx,
899-
cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i + 1)),
899+
cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).subst_identity().input(i + 1)),
900900
precedence,
901901
)
902902
.position_for_arg()
@@ -1093,7 +1093,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
10931093
let sized_trait_def_id = cx.tcx.lang_items().sized_trait();
10941094

10951095
let Some(callee_def_id) = fn_def_id(cx, parent) else { return Position::Other(precedence) };
1096-
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
1096+
let fn_sig = cx.tcx.fn_sig(callee_def_id).subst_identity().skip_binder();
10971097
let substs_with_expr_ty = cx
10981098
.typeck_results()
10991099
.node_substs(if let ExprKind::Call(callee, _) = parent.kind {
@@ -1221,7 +1221,7 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
12211221
.in_definition_order()
12221222
.any(|assoc_item| {
12231223
if assoc_item.fn_has_self_parameter {
1224-
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).skip_binder().inputs()[0];
1224+
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0];
12251225
matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut))
12261226
} else {
12271227
false
@@ -1419,6 +1419,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
14191419
| ty::FnDef(..)
14201420
| ty::Generator(..)
14211421
| ty::GeneratorWitness(..)
1422+
| ty::GeneratorWitnessMIR(..)
14221423
| ty::Closure(..)
14231424
| ty::Never
14241425
| ty::Tuple(_)

clippy_lints/src/derive.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_errors::Applicability;
77
use rustc_hir::def_id::DefId;
88
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
99
use rustc_hir::{
10-
self as hir, BlockCheckMode, BodyId, Constness, Expr, ExprKind, FnDecl, HirId, Impl, Item, ItemKind, UnsafeSource,
10+
self as hir, BlockCheckMode, BodyId, Constness, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource,
1111
Unsafety,
1212
};
1313
use rustc_lint::{LateContext, LateLintPass};
@@ -18,6 +18,7 @@ use rustc_middle::ty::{
1818
TraitPredicate, Ty, TyCtxt,
1919
};
2020
use rustc_session::{declare_lint_pass, declare_tool_lint};
21+
use rustc_span::def_id::LocalDefId;
2122
use rustc_span::source_map::Span;
2223
use rustc_span::sym;
2324

@@ -425,7 +426,7 @@ struct UnsafeVisitor<'a, 'tcx> {
425426
impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
426427
type NestedFilter = nested_filter::All;
427428

428-
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: HirId) {
429+
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: LocalDefId) {
429430
if self.has_unsafe {
430431
return;
431432
}

clippy_lints/src/doc.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_parse::maybe_new_parser_from_source_str;
2323
use rustc_parse::parser::ForceCollect;
2424
use rustc_session::parse::ParseSess;
2525
use rustc_session::{declare_tool_lint, impl_lint_pass};
26-
use rustc_span::def_id::LocalDefId;
2726
use rustc_span::edition::Edition;
2827
use rustc_span::source_map::{BytePos, FilePathMapping, SourceMap, Span};
2928
use rustc_span::{sym, FileName, Pos};
@@ -302,7 +301,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
302301
panic_span: None,
303302
};
304303
fpu.visit_expr(body.value);
305-
lint_for_missing_headers(cx, item.owner_id.def_id, sig, headers, Some(body_id), fpu.panic_span);
304+
lint_for_missing_headers(cx, item.owner_id, sig, headers, Some(body_id), fpu.panic_span);
306305
}
307306
},
308307
hir::ItemKind::Impl(impl_) => {
@@ -338,7 +337,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
338337
let Some(headers) = check_attrs(cx, &self.valid_idents, attrs) else { return };
339338
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
340339
if !in_external_macro(cx.tcx.sess, item.span) {
341-
lint_for_missing_headers(cx, item.owner_id.def_id, sig, headers, None, None);
340+
lint_for_missing_headers(cx, item.owner_id, sig, headers, None, None);
342341
}
343342
}
344343
}
@@ -357,34 +356,34 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
357356
panic_span: None,
358357
};
359358
fpu.visit_expr(body.value);
360-
lint_for_missing_headers(cx, item.owner_id.def_id, sig, headers, Some(body_id), fpu.panic_span);
359+
lint_for_missing_headers(cx, item.owner_id, sig, headers, Some(body_id), fpu.panic_span);
361360
}
362361
}
363362
}
364363

365364
fn lint_for_missing_headers(
366365
cx: &LateContext<'_>,
367-
def_id: LocalDefId,
366+
owner_id: hir::OwnerId,
368367
sig: &hir::FnSig<'_>,
369368
headers: DocHeaders,
370369
body_id: Option<hir::BodyId>,
371370
panic_span: Option<Span>,
372371
) {
373-
if !cx.effective_visibilities.is_exported(def_id) {
372+
if !cx.effective_visibilities.is_exported(owner_id.def_id) {
374373
return; // Private functions do not require doc comments
375374
}
376375

377376
// do not lint if any parent has `#[doc(hidden)]` attribute (#7347)
378377
if cx
379378
.tcx
380379
.hir()
381-
.parent_iter(cx.tcx.hir().local_def_id_to_hir_id(def_id))
380+
.parent_iter(owner_id.into())
382381
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
383382
{
384383
return;
385384
}
386385

387-
let span = cx.tcx.def_span(def_id);
386+
let span = cx.tcx.def_span(owner_id);
388387
match (headers.safety, sig.header.unsafety) {
389388
(false, hir::Unsafety::Unsafe) => span_lint(
390389
cx,
@@ -411,8 +410,7 @@ fn lint_for_missing_headers(
411410
);
412411
}
413412
if !headers.errors {
414-
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
415-
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::Result) {
413+
if is_type_diagnostic_item(cx, return_ty(cx, owner_id), sym::Result) {
416414
span_lint(
417415
cx,
418416
MISSING_ERRORS_DOC,

clippy_lints/src/escape.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_middle::mir::FakeReadCause;
88
use rustc_middle::ty::layout::LayoutOf;
99
use rustc_middle::ty::{self, TraitRef, Ty};
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
11+
use rustc_span::def_id::LocalDefId;
1112
use rustc_span::source_map::Span;
1213
use rustc_span::symbol::kw;
1314
use rustc_target::spec::abi::Abi;
@@ -63,15 +64,19 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
6364
_: &'tcx FnDecl<'_>,
6465
body: &'tcx Body<'_>,
6566
_: Span,
66-
hir_id: HirId,
67+
fn_def_id: LocalDefId,
6768
) {
6869
if let Some(header) = fn_kind.header() {
6970
if header.abi != Abi::Rust {
7071
return;
7172
}
7273
}
7374

74-
let parent_id = cx.tcx.hir().get_parent_item(hir_id).def_id;
75+
let parent_id = cx
76+
.tcx
77+
.hir()
78+
.get_parent_item(cx.tcx.hir().local_def_id_to_hir_id(fn_def_id))
79+
.def_id;
7580
let parent_node = cx.tcx.hir().find_by_def_id(parent_id);
7681

7782
let mut trait_self_ty = None;
@@ -84,7 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
8489
// find `self` ty for this trait if relevant
8590
if let ItemKind::Trait(_, _, _, _, items) = item.kind {
8691
for trait_item in items {
87-
if trait_item.id.hir_id() == hir_id {
92+
if trait_item.id.owner_id.def_id == fn_def_id {
8893
// be sure we have `self` parameter in this function
8994
if trait_item.kind == (AssocItemKind::Fn { has_self: true }) {
9095
trait_self_ty = Some(
@@ -105,7 +110,6 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
105110
too_large_for_stack: self.too_large_for_stack,
106111
};
107112

108-
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
109113
let infcx = cx.tcx.infer_ctxt().build();
110114
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
111115

clippy_lints/src/excessive_bools.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::{get_parent_as_impl, has_repr_attr, is_bool};
33
use rustc_hir::intravisit::FnKind;
4-
use rustc_hir::{Body, FnDecl, HirId, Item, ItemKind, TraitFn, TraitItem, TraitItemKind, Ty};
4+
use rustc_hir::{Body, FnDecl, Item, ItemKind, TraitFn, TraitItem, TraitItemKind, Ty};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_tool_lint, impl_lint_pass};
7+
use rustc_span::def_id::LocalDefId;
78
use rustc_span::Span;
89
use rustc_target::spec::abi::Abi;
910

@@ -168,8 +169,9 @@ impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
168169
fn_decl: &'tcx FnDecl<'tcx>,
169170
_: &'tcx Body<'tcx>,
170171
span: Span,
171-
hir_id: HirId,
172+
def_id: LocalDefId,
172173
) {
174+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
173175
if let Some(fn_header) = fn_kind.header()
174176
&& fn_header.abi == Abi::Rust
175177
&& get_parent_as_impl(cx.tcx, hir_id)

clippy_lints/src/exhaustive_items.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7979
then {
8080
let (lint, msg) = if let ItemKind::Struct(ref v, ..) = item.kind {
8181
if v.fields().iter().any(|f| {
82-
let def_id = cx.tcx.hir().local_def_id(f.hir_id);
83-
!cx.tcx.visibility(def_id).is_public()
82+
!cx.tcx.visibility(f.def_id).is_public()
8483
}) {
8584
// skip structs with private fields
8685
return;

clippy_lints/src/format_args.rs

+4
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,10 @@ fn check_uninlined_args(
311311
// in those cases, make the code suggestion hidden
312312
let multiline_fix = fixes.iter().any(|(span, _)| cx.sess().source_map().is_multiline(*span));
313313

314+
// Suggest removing each argument only once, for example in `format!("{0} {0}", arg)`.
315+
fixes.sort_unstable_by_key(|(span, _)| *span);
316+
fixes.dedup_by_key(|(span, _)| *span);
317+
314318
span_lint_and_then(
315319
cx,
316320
UNINLINED_FORMAT_ARGS,

clippy_lints/src/functions/misnamed_getters.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet;
33
use rustc_errors::Applicability;
4-
use rustc_hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, ImplicitSelfKind, Unsafety};
4+
use rustc_hir::{intravisit::FnKind, Body, ExprKind, FnDecl, ImplicitSelfKind, Unsafety};
55
use rustc_lint::LateContext;
66
use rustc_middle::ty;
77
use rustc_span::Span;
@@ -10,14 +10,7 @@ use std::iter;
1010

1111
use super::MISNAMED_GETTERS;
1212

13-
pub fn check_fn(
14-
cx: &LateContext<'_>,
15-
kind: FnKind<'_>,
16-
decl: &FnDecl<'_>,
17-
body: &Body<'_>,
18-
span: Span,
19-
_hir_id: HirId,
20-
) {
13+
pub fn check_fn(cx: &LateContext<'_>, kind: FnKind<'_>, decl: &FnDecl<'_>, body: &Body<'_>, span: Span) {
2114
let FnKind::Method(ref ident, sig) = kind else {
2215
return;
2316
};

clippy_lints/src/functions/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::intravisit;
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_session::{declare_tool_lint, impl_lint_pass};
12+
use rustc_span::def_id::LocalDefId;
1213
use rustc_span::Span;
1314

1415
declare_clippy_lint! {
@@ -363,12 +364,13 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
363364
decl: &'tcx hir::FnDecl<'_>,
364365
body: &'tcx hir::Body<'_>,
365366
span: Span,
366-
hir_id: hir::HirId,
367+
def_id: LocalDefId,
367368
) {
369+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
368370
too_many_arguments::check_fn(cx, kind, decl, span, hir_id, self.too_many_arguments_threshold);
369371
too_many_lines::check_fn(cx, kind, span, body, self.too_many_lines_threshold);
370-
not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, hir_id);
371-
misnamed_getters::check_fn(cx, kind, decl, body, span, hir_id);
372+
not_unsafe_ptr_arg_deref::check_fn(cx, kind, decl, body, def_id);
373+
misnamed_getters::check_fn(cx, kind, decl, body, span);
372374
}
373375

374376
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {

0 commit comments

Comments
 (0)