Skip to content

Commit 412d41a

Browse files
committed
Auto merge of #3814 - ljedrz:HirIdification_lockstep_upgrade, r=phansch
HirIdify some lints Unblocks rust-lang/rust#58561 (a part of [rust-lang/rust#57578](rust-lang/rust#57578)). Can we branch it like with #3790? I can rebase on a different commit if need be. Haven't had time to run tests yet, so I'd wait for Travis 🙈.
2 parents d0717d1 + c1b65ec commit 412d41a

27 files changed

+131
-126
lines changed

clippy_lints/src/assign_ops.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
88
use rustc_errors::Applicability;
9-
use syntax::ast;
109

1110
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
1211
/// patterns.
@@ -140,12 +139,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
140139
return; // useless if the trait doesn't exist
141140
};
142141
// check that we are not inside an `impl AssignOp` of this exact operation
143-
let parent_fn = cx.tcx.hir().get_parent(e.id);
144-
let parent_impl = cx.tcx.hir().get_parent(parent_fn);
142+
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
143+
let parent_impl = cx.tcx.hir().get_parent_item(parent_fn);
145144
// the crate node is the only one that is not in the map
146145
if_chain! {
147-
if parent_impl != ast::CRATE_NODE_ID;
148-
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
146+
if parent_impl != hir::CRATE_HIR_ID;
147+
if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
149148
if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) =
150149
&item.node;
151150
if trait_ref.path.def.def_id() == trait_id;

clippy_lints/src/booleans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
88
use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::Applicability;
10-
use syntax::ast::{LitKind, DUMMY_NODE_ID};
10+
use syntax::ast::LitKind;
1111
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
1212

1313
/// **What it does:** Checks for boolean expressions that can be written more
@@ -132,7 +132,6 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
132132
}
133133

134134
let mk_expr = |op| Expr {
135-
id: DUMMY_NODE_ID,
136135
hir_id: DUMMY_HIR_ID,
137136
span: DUMMY_SP,
138137
attrs: ThinVec::new(),

clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
125125
..
126126
}) = get_parent_expr(cx, expr)
127127
{
128-
if else_expr.id == expr.id {
128+
if else_expr.hir_id == expr.hir_id {
129129
return;
130130
}
131131
}

clippy_lints/src/cyclomatic_complexity.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ fn report_cc_bug(
222222
span: Span,
223223
id: HirId,
224224
) {
225-
let node_id = cx.tcx.hir().hir_to_node_id(id);
226-
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, node_id) {
225+
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
227226
cx.sess().span_note_without_error(
228227
span,
229228
&format!(

clippy_lints/src/default_trait_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
4545
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
4646
if_chain! {
4747
if let ExprKind::Call(ref path, ..) = expr.node;
48-
if !any_parent_is_automatically_derived(cx.tcx, expr.id);
48+
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
4949
if let ExprKind::Path(ref qpath) = path.node;
5050
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
5151
if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);

clippy_lints/src/escape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
100100
}
101101

102102
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
103-
fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
103+
fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
104104
if let Categorization::Local(lid) = cmt.cat {
105105
if let Move(DirectRefMove) = mode {
106106
// moved out or in. clearly can't be localized
@@ -150,7 +150,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
150150
}
151151
fn borrow(
152152
&mut self,
153-
_: NodeId,
153+
_: HirId,
154154
_: Span,
155155
cmt: &cmt_<'tcx>,
156156
_: ty::Region<'_>,
@@ -178,7 +178,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
178178
}
179179
}
180180
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
181-
fn mutate(&mut self, _: NodeId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
181+
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
182182
}
183183

184184
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

clippy_lints/src/eval_order_dependence.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
186186
/// When such a read is found, the lint is triggered.
187187
fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
188188
let map = &vis.cx.tcx.hir();
189-
let mut cur_id = vis.write_expr.id;
189+
let mut cur_id = vis.write_expr.hir_id;
190190
loop {
191-
let parent_id = map.get_parent_node(cur_id);
191+
let parent_id = map.get_parent_node_by_hir_id(cur_id);
192192
if parent_id == cur_id {
193193
break;
194194
}
195-
let parent_node = match map.find(parent_id) {
195+
let parent_node = match map.find_by_hir_id(parent_id) {
196196
Some(parent) => parent,
197197
None => break,
198198
};
@@ -224,7 +224,7 @@ enum StopEarly {
224224
}
225225

226226
fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> StopEarly {
227-
if expr.id == vis.last_expr.id {
227+
if expr.hir_id == vis.last_expr.hir_id {
228228
return StopEarly::KeepGoing;
229229
}
230230

@@ -298,7 +298,7 @@ struct ReadVisitor<'a, 'tcx: 'a> {
298298

299299
impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
300300
fn visit_expr(&mut self, expr: &'tcx Expr) {
301-
if expr.id == self.last_expr.id {
301+
if expr.hir_id == self.last_expr.hir_id {
302302
return;
303303
}
304304

@@ -355,7 +355,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
355355
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
356356
if let Some(parent) = get_parent_expr(cx, expr) {
357357
if let ExprKind::Assign(ref lhs, _) = parent.node {
358-
return lhs.id == expr.id;
358+
return lhs.hir_id == expr.hir_id;
359359
}
360360
}
361361
false

clippy_lints/src/identity_conversion.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
88
use rustc_errors::Applicability;
9-
use syntax::ast::NodeId;
109

1110
/// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions.
1211
///
@@ -27,7 +26,7 @@ declare_clippy_lint! {
2726

2827
#[derive(Default)]
2928
pub struct IdentityConversion {
30-
try_desugar_arm: Vec<NodeId>,
29+
try_desugar_arm: Vec<HirId>,
3130
}
3231

3332
impl LintPass for IdentityConversion {
@@ -46,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
4645
return;
4746
}
4847

49-
if Some(&e.id) == self.try_desugar_arm.last() {
48+
if Some(&e.hir_id) == self.try_desugar_arm.last() {
5049
return;
5150
}
5251

@@ -57,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
5756
_ => return,
5857
};
5958
if let ExprKind::Call(_, ref args) = e.node {
60-
self.try_desugar_arm.push(args[0].id);
59+
self.try_desugar_arm.push(args[0].hir_id);
6160
} else {
6261
return;
6362
}
@@ -126,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
126125
}
127126

128127
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
129-
if Some(&e.id) == self.try_desugar_arm.last() {
128+
if Some(&e.hir_id) == self.try_desugar_arm.last() {
130129
self.try_desugar_arm.pop();
131130
}
132131
}

clippy_lints/src/lifetimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
319319
_ => false,
320320
})
321321
{
322-
let hir_id = self.cx.tcx.hir().node_to_hir_id(ty.id);
322+
let hir_id = ty.hir_id;
323323
match self.cx.tables.qpath_def(qpath, hir_id) {
324324
Def::TyAlias(def_id) | Def::Struct(def_id) => {
325325
let generics = self.cx.tcx.generics_of(def_id);

clippy_lints/src/loops.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
486486
// check for never_loop
487487
match expr.node {
488488
ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => {
489-
match never_loop_block(block, expr.id) {
489+
let node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id);
490+
match never_loop_block(block, node_id) {
490491
NeverLoopResult::AlwaysBreak => {
491492
span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
492493
},
@@ -1109,8 +1110,8 @@ fn check_for_loop_range<'a, 'tcx>(
11091110

11101111
// ensure that the indexed variable was declared before the loop, see #601
11111112
if let Some(indexed_extent) = indexed_extent {
1112-
let parent_id = cx.tcx.hir().get_parent(expr.id);
1113-
let parent_def_id = cx.tcx.hir().local_def_id(parent_id);
1113+
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
1114+
let parent_def_id = cx.tcx.hir().local_def_id_from_hir_id(parent_id);
11141115
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
11151116
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
11161117
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
@@ -1469,8 +1470,9 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
14691470
// For each candidate, check the parent block to see if
14701471
// it's initialized to zero at the start of the loop.
14711472
let map = &cx.tcx.hir();
1473+
let expr_node_id = map.hir_to_node_id(expr.hir_id);
14721474
let parent_scope = map
1473-
.get_enclosing_scope(expr.id)
1475+
.get_enclosing_scope(expr_node_id)
14741476
.and_then(|id| map.get_enclosing_scope(id));
14751477
if let Some(parent_id) = parent_scope {
14761478
if let Node::Block(block) = map.get(parent_id) {
@@ -1567,13 +1569,13 @@ struct MutatePairDelegate {
15671569
}
15681570

15691571
impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
1570-
fn consume(&mut self, _: NodeId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
1572+
fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
15711573

15721574
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
15731575

15741576
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
15751577

1576-
fn borrow(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
1578+
fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
15771579
if let ty::BorrowKind::MutBorrow = bk {
15781580
if let Categorization::Local(id) = cmt.cat {
15791581
if Some(id) == self.node_id_low {
@@ -1586,7 +1588,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
15861588
}
15871589
}
15881590

1589-
fn mutate(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
1591+
fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
15901592
if let Categorization::Local(id) = cmt.cat {
15911593
if Some(id) == self.node_id_low {
15921594
self.span_low = Some(sp)
@@ -1778,8 +1780,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17781780
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
17791781
let hir_id = self.cx.tcx.hir().node_to_hir_id(node_id);
17801782

1781-
let parent_id = self.cx.tcx.hir().get_parent(expr.id);
1782-
let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id);
1783+
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
1784+
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
17831785
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
17841786
if indexed_indirectly {
17851787
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));
@@ -1932,11 +1934,12 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
19321934
let mut visitor = VarUsedAfterLoopVisitor {
19331935
cx,
19341936
def_id,
1935-
iter_expr_id: iter_expr.id,
1937+
iter_expr_id: iter_expr.hir_id,
19361938
past_while_let: false,
19371939
var_used_after_while_let: false,
19381940
};
1939-
if let Some(enclosing_block) = get_enclosing_block(cx, def_id) {
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) {
19401943
walk_block(&mut visitor, enclosing_block);
19411944
}
19421945
visitor.var_used_after_while_let
@@ -1945,7 +1948,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
19451948
struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> {
19461949
cx: &'a LateContext<'a, 'tcx>,
19471950
def_id: NodeId,
1948-
iter_expr_id: NodeId,
1951+
iter_expr_id: HirId,
19491952
past_while_let: bool,
19501953
var_used_after_while_let: bool,
19511954
}
@@ -1956,7 +1959,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
19561959
if Some(self.def_id) == var_def_id(self.cx, expr) {
19571960
self.var_used_after_while_let = true;
19581961
}
1959-
} else if self.iter_expr_id == expr.id {
1962+
} else if self.iter_expr_id == expr.hir_id {
19601963
self.past_while_let = true;
19611964
}
19621965
walk_expr(self, expr);
@@ -2068,7 +2071,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20682071

20692072
match parent.node {
20702073
ExprKind::AssignOp(op, ref lhs, ref rhs) => {
2071-
if lhs.id == expr.id {
2074+
if lhs.hir_id == expr.hir_id {
20722075
if op.node == BinOpKind::Add && is_integer_literal(rhs, 1) {
20732076
*state = match *state {
20742077
VarState::Initial if self.depth == 0 => VarState::IncrOnce,
@@ -2080,7 +2083,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20802083
}
20812084
}
20822085
},
2083-
ExprKind::Assign(ref lhs, _) if lhs.id == expr.id => *state = VarState::DontWarn,
2086+
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
20842087
ExprKind::AddrOf(mutability, _) if mutability == MutMutable => *state = VarState::DontWarn,
20852088
_ => (),
20862089
}
@@ -2153,10 +2156,10 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21532156
if var_def_id(self.cx, expr) == Some(self.var_id) {
21542157
if let Some(parent) = get_parent_expr(self.cx, expr) {
21552158
match parent.node {
2156-
ExprKind::AssignOp(_, ref lhs, _) if lhs.id == expr.id => {
2159+
ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => {
21572160
self.state = VarState::DontWarn;
21582161
},
2159-
ExprKind::Assign(ref lhs, ref rhs) if lhs.id == expr.id => {
2162+
ExprKind::Assign(ref lhs, ref rhs) if lhs.hir_id == expr.hir_id => {
21602163
self.state = if is_integer_literal(rhs, 0) && self.depth == 0 {
21612164
VarState::Warn
21622165
} else {
@@ -2214,8 +2217,9 @@ fn is_conditional(expr: &Expr) -> bool {
22142217

22152218
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
22162219
if_chain! {
2217-
if let Some(loop_block) = get_enclosing_block(cx, match_expr.id);
2218-
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(loop_block.id));
2220+
if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id);
2221+
let parent_node = cx.tcx.hir().get_parent_node_by_hir_id(loop_block.hir_id);
2222+
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find_by_hir_id(parent_node);
22192223
then {
22202224
return is_loop_nested(cx, loop_expr, iter_expr)
22212225
}
@@ -2224,18 +2228,18 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> b
22242228
}
22252229

22262230
fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr) -> bool {
2227-
let mut id = loop_expr.id;
2231+
let mut id = loop_expr.hir_id;
22282232
let iter_name = if let Some(name) = path_name(iter_expr) {
22292233
name
22302234
} else {
22312235
return true;
22322236
};
22332237
loop {
2234-
let parent = cx.tcx.hir().get_parent_node(id);
2238+
let parent = cx.tcx.hir().get_parent_node_by_hir_id(id);
22352239
if parent == id {
22362240
return false;
22372241
}
2238-
match cx.tcx.hir().find(parent) {
2242+
match cx.tcx.hir().find_by_hir_id(parent) {
22392243
Some(Node::Expr(expr)) => match expr.node {
22402244
ExprKind::Loop(..) | ExprKind::While(..) => {
22412245
return true;
@@ -2244,7 +2248,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
22442248
},
22452249
Some(Node::Block(block)) => {
22462250
let mut block_visitor = LoopNestVisitor {
2247-
id,
2251+
hir_id: id,
22482252
iterator: iter_name,
22492253
nesting: Unknown,
22502254
};
@@ -2272,14 +2276,14 @@ enum Nesting {
22722276
use self::Nesting::{LookFurther, RuledOut, Unknown};
22732277

22742278
struct LoopNestVisitor {
2275-
id: NodeId,
2279+
hir_id: HirId,
22762280
iterator: Name,
22772281
nesting: Nesting,
22782282
}
22792283

22802284
impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
22812285
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
2282-
if stmt.id == self.id {
2286+
if stmt.hir_id == self.hir_id {
22832287
self.nesting = LookFurther;
22842288
} else if self.nesting == Unknown {
22852289
walk_stmt(self, stmt);
@@ -2290,7 +2294,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
22902294
if self.nesting != Unknown {
22912295
return;
22922296
}
2293-
if expr.id == self.id {
2297+
if expr.hir_id == self.hir_id {
22942298
self.nesting = LookFurther;
22952299
return;
22962300
}

0 commit comments

Comments
 (0)