Skip to content

Commit 9d1792a

Browse files
committed
Auto merge of #3834 - ljedrz:HirIdification_fix, r=phansch
HirIdification fixes Supersedes #3828, enables rust-lang/rust#58836. As usual, requesting a branch.
2 parents 8dfabdf + 68096cf commit 9d1792a

27 files changed

+114
-116
lines changed

clippy_lints/src/copy_iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl LintPass for CopyIterator {
4444
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
4545
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
4646
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
47-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id));
47+
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
4848

4949
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
5050
span_note_and_lint(

clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl LintPass for Derive {
7777
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Derive {
7878
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
7979
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
80-
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id(item.id));
80+
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
8181
let is_automatically_derived = is_automatically_derived(&*item.attrs);
8282

8383
check_hash_peq(cx, item.span, trait_ref, ty, is_automatically_derived);

clippy_lints/src/empty_enum.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl LintPass for EmptyEnum {
3838

3939
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
4040
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
41-
let did = cx.tcx.hir().local_def_id(item.id);
41+
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
4242
if let ItemKind::Enum(..) = item.node {
4343
let ty = cx.tcx.type_of(did);
4444
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

clippy_lints/src/escape.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use rustc::middle::expr_use_visitor::*;
66
use rustc::middle::mem_categorization::{cmt_, Categorization};
77
use rustc::ty::layout::LayoutOf;
88
use rustc::ty::{self, Ty};
9-
use rustc::util::nodemap::NodeSet;
9+
use rustc::util::nodemap::HirIdSet;
1010
use rustc::{declare_tool_lint, lint_array};
11-
use syntax::ast::NodeId;
1211
use syntax::source_map::Span;
1312

1413
pub struct Pass {
@@ -44,7 +43,7 @@ fn is_non_trait_box(ty: Ty<'_>) -> bool {
4443

4544
struct EscapeDelegate<'a, 'tcx: 'a> {
4645
cx: &'a LateContext<'a, 'tcx>,
47-
set: NodeSet,
46+
set: HirIdSet,
4847
too_large_for_stack: u64,
4948
}
5049

@@ -80,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
8079

8180
let mut v = EscapeDelegate {
8281
cx,
83-
set: NodeSet::default(),
82+
set: HirIdSet::default(),
8483
too_large_for_stack: self.too_large_for_stack,
8584
};
8685

@@ -92,7 +91,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9291
span_lint(
9392
cx,
9493
BOXED_LOCAL,
95-
cx.tcx.hir().span(node),
94+
cx.tcx.hir().span_by_hir_id(node),
9695
"local variable doesn't need to be boxed here",
9796
);
9897
}
@@ -111,13 +110,13 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
111110
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
112111
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
113112
let map = &self.cx.tcx.hir();
114-
if map.is_argument(consume_pat.id) {
113+
if map.is_argument(map.hir_to_node_id(consume_pat.hir_id)) {
115114
// Skip closure arguments
116-
if let Some(Node::Expr(..)) = map.find(map.get_parent_node(consume_pat.id)) {
115+
if let Some(Node::Expr(..)) = map.find_by_hir_id(map.get_parent_node_by_hir_id(consume_pat.hir_id)) {
117116
return;
118117
}
119118
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
120-
self.set.insert(consume_pat.id);
119+
self.set.insert(consume_pat.hir_id);
121120
}
122121
return;
123122
}
@@ -129,7 +128,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
129128
if let ExprKind::Box(..) = ex.node {
130129
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
131130
// let x = box (...)
132-
self.set.insert(consume_pat.id);
131+
self.set.insert(consume_pat.hir_id);
133132
}
134133
// TODO Box::new
135134
// TODO vec![]
@@ -143,7 +142,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
143142
if self.set.contains(&lid) {
144143
// let y = x where x is known
145144
// remove x, insert y
146-
self.set.insert(consume_pat.id);
145+
self.set.insert(consume_pat.hir_id);
147146
self.set.remove(&lid);
148147
}
149148
}
@@ -177,7 +176,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
177176
}
178177
}
179178
}
180-
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
179+
fn decl_without_init(&mut self, _: HirId, _: Span) {}
181180
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
182181
}
183182

clippy_lints/src/fallible_impl_from.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl LintPass for FallibleImplFrom {
4343
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom {
4444
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
4545
// check for `impl From<???> for ..`
46-
let impl_def_id = cx.tcx.hir().local_def_id(item.id);
46+
let impl_def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
4747
if_chain! {
4848
if let hir::ItemKind::Impl(.., ref impl_items) = item.node;
4949
if let Some(impl_trait_ref) = cx.tcx.impl_trait_ref(impl_def_id);
@@ -105,7 +105,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
105105
then {
106106
// check the body for `begin_panic` or `unwrap`
107107
let body = cx.tcx.hir().body(body_id);
108-
let impl_item_def_id = cx.tcx.hir().local_def_id(impl_item.id.node_id);
108+
let impl_item_def_id = cx.tcx.hir().local_def_id_from_hir_id(impl_item.id.hir_id);
109109
let mut fpu = FindPanicUnwrap {
110110
tcx: cx.tcx,
111111
tables: cx.tcx.typeck_tables_of(impl_item_def_id),

clippy_lints/src/functions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
150150
}
151151
}
152152

153-
let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
154-
self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
153+
self.check_raw_ptr(cx, unsafety, decl, body, hir_id);
155154
self.check_line_number(cx, span, body);
156155
}
157156

@@ -164,7 +163,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
164163

165164
if let hir::TraitMethod::Provided(eid) = *eid {
166165
let body = cx.tcx.hir().body(eid);
167-
self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.id);
166+
self.check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id);
168167
}
169168
}
170169
}
@@ -255,10 +254,11 @@ impl<'a, 'tcx> Functions {
255254
unsafety: hir::Unsafety,
256255
decl: &'tcx hir::FnDecl,
257256
body: &'tcx hir::Body,
258-
nodeid: ast::NodeId,
257+
hir_id: hir::HirId,
259258
) {
260259
let expr = &body.value;
261-
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) {
260+
let node_id = cx.tcx.hir().hir_to_node_id(hir_id);
261+
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(node_id) {
262262
let raw_ptrs = iter_input_pats(decl, body)
263263
.zip(decl.inputs.iter())
264264
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))

clippy_lints/src/large_enum_variant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl LintPass for LargeEnumVariant {
5454

5555
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
5656
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
57-
let did = cx.tcx.hir().local_def_id(item.id);
57+
let did = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
5858
if let ItemKind::Enum(ref def, _) = item.node {
5959
let ty = cx.tcx.type_of(did);
6060
let adt = ty.ty_adt_def().expect("already checked whether this is an enum");

clippy_lints/src/len_zero.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
132132
item.ident.name == name
133133
&& if let AssociatedItemKind::Method { has_self } = item.kind {
134134
has_self && {
135-
let did = cx.tcx.hir().local_def_id(item.id.node_id);
135+
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
136136
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
137137
}
138138
} else {
@@ -149,9 +149,11 @@ fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items
149149
}
150150
}
151151

152-
if cx.access_levels.is_exported(visited_trait.id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
152+
let trait_node_id = cx.tcx.hir().hir_to_node_id(visited_trait.hir_id);
153+
154+
if cx.access_levels.is_exported(trait_node_id) && trait_items.iter().any(|i| is_named_self(cx, i, "len")) {
153155
let mut current_and_super_traits = FxHashSet::default();
154-
let visited_trait_def_id = cx.tcx.hir().local_def_id(visited_trait.id);
156+
let visited_trait_def_id = cx.tcx.hir().local_def_id_from_hir_id(visited_trait.hir_id);
155157
fill_trait_set(visited_trait_def_id, &mut current_and_super_traits, cx);
156158

157159
let is_empty_method_found = current_and_super_traits
@@ -183,7 +185,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
183185
item.ident.name == name
184186
&& if let AssociatedItemKind::Method { has_self } = item.kind {
185187
has_self && {
186-
let did = cx.tcx.hir().local_def_id(item.id.node_id);
188+
let did = cx.tcx.hir().local_def_id_from_hir_id(item.id.hir_id);
187189
cx.tcx.fn_sig(did).inputs().skip_binder().len() == 1
188190
}
189191
} else {
@@ -192,7 +194,10 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
192194
}
193195

194196
let is_empty = if let Some(is_empty) = impl_items.iter().find(|i| is_named_self(cx, i, "is_empty")) {
195-
if cx.access_levels.is_exported(is_empty.id.node_id) {
197+
if cx
198+
.access_levels
199+
.is_exported(cx.tcx.hir().hir_to_node_id(is_empty.id.hir_id))
200+
{
196201
return;
197202
} else {
198203
"a private"
@@ -202,8 +207,8 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
202207
};
203208

204209
if let Some(i) = impl_items.iter().find(|i| is_named_self(cx, i, "len")) {
205-
if cx.access_levels.is_exported(i.id.node_id) {
206-
let def_id = cx.tcx.hir().local_def_id(item.id);
210+
if cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(i.id.hir_id)) {
211+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
207212
let ty = cx.tcx.type_of(def_id);
208213

209214
span_lint(

clippy_lints/src/loops.rs

+23-24
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,8 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
15621562
}
15631563

15641564
struct MutatePairDelegate {
1565-
node_id_low: Option<NodeId>,
1566-
node_id_high: Option<NodeId>,
1565+
hir_id_low: Option<HirId>,
1566+
hir_id_high: Option<HirId>,
15671567
span_low: Option<Span>,
15681568
span_high: Option<Span>,
15691569
}
@@ -1578,10 +1578,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
15781578
fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
15791579
if let ty::BorrowKind::MutBorrow = bk {
15801580
if let Categorization::Local(id) = cmt.cat {
1581-
if Some(id) == self.node_id_low {
1581+
if Some(id) == self.hir_id_low {
15821582
self.span_low = Some(sp)
15831583
}
1584-
if Some(id) == self.node_id_high {
1584+
if Some(id) == self.hir_id_high {
15851585
self.span_high = Some(sp)
15861586
}
15871587
}
@@ -1590,16 +1590,16 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
15901590

15911591
fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
15921592
if let Categorization::Local(id) = cmt.cat {
1593-
if Some(id) == self.node_id_low {
1593+
if Some(id) == self.hir_id_low {
15941594
self.span_low = Some(sp)
15951595
}
1596-
if Some(id) == self.node_id_high {
1596+
if Some(id) == self.hir_id_high {
15971597
self.span_high = Some(sp)
15981598
}
15991599
}
16001600
}
16011601

1602-
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
1602+
fn decl_without_init(&mut self, _: HirId, _: Span) {}
16031603
}
16041604

16051605
impl<'tcx> MutatePairDelegate {
@@ -1635,7 +1635,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option<Span>) {
16351635
}
16361636
}
16371637

1638-
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId> {
1638+
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId> {
16391639
if_chain! {
16401640
if let ExprKind::Path(ref qpath) = bound.node;
16411641
if let QPath::Resolved(None, _) = *qpath;
@@ -1648,7 +1648,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId
16481648
if let PatKind::Binding(bind_ann, ..) = pat.node;
16491649
if let BindingAnnotation::Mutable = bind_ann;
16501650
then {
1651-
return Some(node_id);
1651+
return Some(cx.tcx.hir().node_to_hir_id(node_id));
16521652
}
16531653
}
16541654
}
@@ -1660,11 +1660,11 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId
16601660
fn check_for_mutation(
16611661
cx: &LateContext<'_, '_>,
16621662
body: &Expr,
1663-
bound_ids: &[Option<NodeId>],
1663+
bound_ids: &[Option<HirId>],
16641664
) -> (Option<Span>, Option<Span>) {
16651665
let mut delegate = MutatePairDelegate {
1666-
node_id_low: bound_ids[0],
1667-
node_id_high: bound_ids[1],
1666+
hir_id_low: bound_ids[0],
1667+
hir_id_high: bound_ids[1],
16681668
span_low: None,
16691669
span_high: None,
16701670
};
@@ -1938,16 +1938,15 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
19381938
past_while_let: false,
19391939
var_used_after_while_let: false,
19401940
};
1941-
let def_hir_id = cx.tcx.hir().node_to_hir_id(def_id);
1942-
if let Some(enclosing_block) = get_enclosing_block(cx, def_hir_id) {
1941+
if let Some(enclosing_block) = get_enclosing_block(cx, def_id) {
19431942
walk_block(&mut visitor, enclosing_block);
19441943
}
19451944
visitor.var_used_after_while_let
19461945
}
19471946

19481947
struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> {
19491948
cx: &'a LateContext<'a, 'tcx>,
1950-
def_id: NodeId,
1949+
def_id: HirId,
19511950
iter_expr_id: HirId,
19521951
past_while_let: bool,
19531952
var_used_after_while_let: bool,
@@ -2052,9 +2051,9 @@ enum VarState {
20522051

20532052
/// Scan a for loop for variables that are incremented exactly once.
20542053
struct IncrementVisitor<'a, 'tcx: 'a> {
2055-
cx: &'a LateContext<'a, 'tcx>, // context reference
2056-
states: FxHashMap<NodeId, VarState>, // incremented variables
2057-
depth: u32, // depth of conditional expressions
2054+
cx: &'a LateContext<'a, 'tcx>, // context reference
2055+
states: FxHashMap<HirId, VarState>, // incremented variables
2056+
depth: u32, // depth of conditional expressions
20582057
done: bool,
20592058
}
20602059

@@ -2108,7 +2107,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
21082107
struct InitializeVisitor<'a, 'tcx: 'a> {
21092108
cx: &'a LateContext<'a, 'tcx>, // context reference
21102109
end_expr: &'tcx Expr, // the for loop. Stop scanning here.
2111-
var_id: NodeId,
2110+
var_id: HirId,
21122111
state: VarState,
21132112
name: Option<Name>,
21142113
depth: u32, // depth of conditional expressions
@@ -2119,7 +2118,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21192118
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
21202119
// Look for declarations of the variable
21212120
if let StmtKind::Local(ref local) = stmt.node {
2122-
if local.pat.id == self.var_id {
2121+
if local.pat.hir_id == self.var_id {
21232122
if let PatKind::Binding(.., ident, _) = local.pat.node {
21242123
self.name = Some(ident.name);
21252124

@@ -2191,11 +2190,11 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21912190
}
21922191
}
21932192

2194-
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<NodeId> {
2193+
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
21952194
if let ExprKind::Path(ref qpath) = expr.node {
21962195
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
21972196
if let Def::Local(node_id) = path_res {
2198-
return Some(node_id);
2197+
return Some(cx.tcx.hir().node_to_hir_id(node_id));
21992198
}
22002199
}
22012200
None
@@ -2376,7 +2375,7 @@ fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, e
23762375
/// All variables definition IDs are collected
23772376
struct VarCollectorVisitor<'a, 'tcx: 'a> {
23782377
cx: &'a LateContext<'a, 'tcx>,
2379-
ids: FxHashSet<NodeId>,
2378+
ids: FxHashSet<HirId>,
23802379
def_ids: FxHashMap<def_id::DefId, bool>,
23812380
skip: bool,
23822381
}
@@ -2390,7 +2389,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
23902389
then {
23912390
match def {
23922391
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
2393-
self.ids.insert(node_id);
2392+
self.ids.insert(self.cx.tcx.hir().node_to_hir_id(node_id));
23942393
},
23952394
Def::Static(def_id, mutable) => {
23962395
self.def_ids.insert(def_id, mutable);

0 commit comments

Comments
 (0)