Skip to content

Commit 79475f5

Browse files
committed
Auto merge of rust-lang#107206 - cjgillot:no-h2l-map, r=WaffleLapkin
Remove HirId -> LocalDefId map from HIR. Having this map in HIR prevents the creating of new definitions after HIR has been built. Thankfully, we do not need it. Based on rust-lang#103902
2 parents 75c8179 + 3e32533 commit 79475f5

Some content is hidden

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

43 files changed

+184
-161
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/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/dereference.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -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)).subst_identity().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
)

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,10 +1,11 @@
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};
77
use rustc_span::Span;
8+
use rustc_span::def_id::LocalDefId;
89
use rustc_target::spec::abi::Abi;
910

1011
declare_clippy_lint! {
@@ -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/functions/misnamed_getters.rs

+1-2
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;
@@ -16,7 +16,6 @@ pub fn check_fn(
1616
decl: &FnDecl<'_>,
1717
body: &Body<'_>,
1818
span: Span,
19-
_hir_id: HirId,
2019
) {
2120
let FnKind::Method(ref ident, sig) = kind else {
2221
return;

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<'_>) {

clippy_lints/src/functions/must_use.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::ast::Attribute;
22
use rustc_errors::Applicability;
3-
use rustc_hir::def_id::{DefIdSet, LocalDefId};
3+
use rustc_hir::def_id::DefIdSet;
44
use rustc_hir::{self as hir, def::Res, QPath};
55
use rustc_lint::{LateContext, LintContext};
66
use rustc_middle::{
@@ -27,14 +27,14 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
2727
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
2828
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
2929
if let Some(attr) = attr {
30-
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
30+
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
3131
} else if is_public && !is_proc_macro(cx.sess(), attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
3232
check_must_use_candidate(
3333
cx,
3434
sig.decl,
3535
cx.tcx.hir().body(*body_id),
3636
item.span,
37-
item.owner_id.def_id,
37+
item.owner_id,
3838
item.span.with_hi(sig.decl.output.span().hi()),
3939
"this function could have a `#[must_use]` attribute",
4040
);
@@ -49,7 +49,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
4949
let attrs = cx.tcx.hir().attrs(item.hir_id());
5050
let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
5151
if let Some(attr) = attr {
52-
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
52+
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
5353
} else if is_public
5454
&& !is_proc_macro(cx.sess(), attrs)
5555
&& trait_ref_of_method(cx, item.owner_id.def_id).is_none()
@@ -59,7 +59,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
5959
sig.decl,
6060
cx.tcx.hir().body(*body_id),
6161
item.span,
62-
item.owner_id.def_id,
62+
item.owner_id,
6363
item.span.with_hi(sig.decl.output.span().hi()),
6464
"this method could have a `#[must_use]` attribute",
6565
);
@@ -75,7 +75,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
7575
let attrs = cx.tcx.hir().attrs(item.hir_id());
7676
let attr = cx.tcx.get_attr(item.owner_id.to_def_id(), sym::must_use);
7777
if let Some(attr) = attr {
78-
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
78+
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr);
7979
} else if let hir::TraitFn::Provided(eid) = *eid {
8080
let body = cx.tcx.hir().body(eid);
8181
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) {
@@ -84,7 +84,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
8484
sig.decl,
8585
body,
8686
item.span,
87-
item.owner_id.def_id,
87+
item.owner_id,
8888
item.span.with_hi(sig.decl.output.span().hi()),
8989
"this method could have a `#[must_use]` attribute",
9090
);
@@ -96,7 +96,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
9696
fn check_needless_must_use(
9797
cx: &LateContext<'_>,
9898
decl: &hir::FnDecl<'_>,
99-
item_id: hir::HirId,
99+
item_id: hir::OwnerId,
100100
item_span: Span,
101101
fn_header_span: Span,
102102
attr: &Attribute,
@@ -131,16 +131,16 @@ fn check_must_use_candidate<'tcx>(
131131
decl: &'tcx hir::FnDecl<'_>,
132132
body: &'tcx hir::Body<'_>,
133133
item_span: Span,
134-
item_id: LocalDefId,
134+
item_id: hir::OwnerId,
135135
fn_span: Span,
136136
msg: &str,
137137
) {
138138
if has_mutable_arg(cx, body)
139139
|| mutates_static(cx, body)
140140
|| in_external_macro(cx.sess(), item_span)
141141
|| returns_unit(decl)
142-
|| !cx.effective_visibilities.is_exported(item_id)
143-
|| is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id)))
142+
|| !cx.effective_visibilities.is_exported(item_id.def_id)
143+
|| is_must_use_ty(cx, return_ty(cx, item_id))
144144
{
145145
return;
146146
}

0 commit comments

Comments
 (0)