Skip to content

Commit f3363b9

Browse files
committed
align with rust-lang/rust/#58836
1 parent f258770 commit f3363b9

20 files changed

+80
-82
lines changed

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 11 deletions
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,15 @@ 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(
116+
map.get_parent_node_by_hir_id(consume_pat.hir_id))
117+
{
117118
return;
118119
}
119120
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
120-
self.set.insert(consume_pat.id);
121+
self.set.insert(consume_pat.hir_id);
121122
}
122123
return;
123124
}
@@ -129,7 +130,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
129130
if let ExprKind::Box(..) = ex.node {
130131
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
131132
// let x = box (...)
132-
self.set.insert(consume_pat.id);
133+
self.set.insert(consume_pat.hir_id);
133134
}
134135
// TODO Box::new
135136
// TODO vec![]
@@ -143,7 +144,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
143144
if self.set.contains(&lid) {
144145
// let y = x where x is known
145146
// remove x, insert y
146-
self.set.insert(consume_pat.id);
147+
self.set.insert(consume_pat.hir_id);
147148
self.set.remove(&lid);
148149
}
149150
}
@@ -177,7 +178,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
177178
}
178179
}
179180
}
180-
fn decl_without_init(&mut self, _: NodeId, _: Span) {}
181+
fn decl_without_init(&mut self, _: HirId, _: Span) {}
181182
fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
182183
}
183184

clippy_lints/src/fallible_impl_from.rs

Lines changed: 2 additions & 2 deletions
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/large_enum_variant.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 7 deletions
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,7 @@ 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.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(is_empty.id.hir_id)) {
196198
return;
197199
} else {
198200
"a private"
@@ -202,8 +204,8 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplIte
202204
};
203205

204206
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);
207+
if cx.access_levels.is_exported(cx.tcx.hir().hir_to_node_id(i.id.hir_id)) {
208+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(item.hir_id);
207209
let ty = cx.tcx.type_of(def_id);
208210

209211
span_lint(

clippy_lints/src/loops.rs

Lines changed: 21 additions & 22 deletions
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,
@@ -2053,7 +2052,7 @@ enum VarState {
20532052
/// Scan a for loop for variables that are incremented exactly once.
20542053
struct IncrementVisitor<'a, 'tcx: 'a> {
20552054
cx: &'a LateContext<'a, 'tcx>, // context reference
2056-
states: FxHashMap<NodeId, VarState>, // incremented variables
2055+
states: FxHashMap<HirId, VarState>, // incremented variables
20572056
depth: u32, // depth of conditional expressions
20582057
done: bool,
20592058
}
@@ -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);

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::hir;
55
use rustc::hir::def::Def;
66
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
77
use rustc::lint::LateContext;
8-
use syntax::ast;
98

109
use if_chain::if_chain;
1110

@@ -18,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
1817

1918
if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
2019
let body = cx.tcx.hir().body(body_id);
21-
let arg_id = body.arguments[0].pat.id;
20+
let arg_id = body.arguments[0].pat.hir_id;
2221
let mutates_arg = match mutated_variables(&body.value, cx) {
2322
Some(used_mutably) => used_mutably.contains(&arg_id),
2423
None => true,
@@ -56,7 +55,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
5655
// returns (found_mapping, found_filtering)
5756
fn check_expression<'a, 'tcx: 'a>(
5857
cx: &'a LateContext<'a, 'tcx>,
59-
arg_id: ast::NodeId,
58+
arg_id: hir::HirId,
6059
expr: &'tcx hir::Expr,
6160
) -> (bool, bool) {
6261
match &expr.node {
@@ -69,7 +68,7 @@ fn check_expression<'a, 'tcx: 'a>(
6968
if let hir::ExprKind::Path(path) = &args[0].node;
7069
if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id);
7170
then {
72-
if arg_id == *local {
71+
if arg_id == cx.tcx.hir().node_to_hir_id(*local) {
7372
return (false, false)
7473
}
7574
}
@@ -113,15 +112,15 @@ fn check_expression<'a, 'tcx: 'a>(
113112

114113
struct ReturnVisitor<'a, 'tcx: 'a> {
115114
cx: &'a LateContext<'a, 'tcx>,
116-
arg_id: ast::NodeId,
115+
arg_id: hir::HirId,
117116
// Found a non-None return that isn't Some(input)
118117
found_mapping: bool,
119118
// Found a return that isn't Some
120119
found_filtering: bool,
121120
}
122121

123122
impl<'a, 'tcx: 'a> ReturnVisitor<'a, 'tcx> {
124-
fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: ast::NodeId) -> ReturnVisitor<'a, 'tcx> {
123+
fn new(cx: &'a LateContext<'a, 'tcx>, arg_id: hir::HirId) -> ReturnVisitor<'a, 'tcx> {
125124
ReturnVisitor {
126125
cx,
127126
arg_id,

0 commit comments

Comments
 (0)