Skip to content

Commit 1b2f2be

Browse files
committed
Remove now-unnecessary calls to node_to_hir_id
1 parent 6505794 commit 1b2f2be

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

clippy_lints/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> {
327327
fn check_arg(&self, ptr: &hir::Expr) {
328328
if let hir::ExprKind::Path(ref qpath) = ptr.node {
329329
if let Def::Local(id) = self.cx.tables.qpath_def(qpath, ptr.hir_id) {
330-
if self.ptrs.contains(&self.cx.tcx.hir().node_to_hir_id(id)) {
330+
if self.ptrs.contains(&id) {
331331
span_lint(
332332
self.cx,
333333
NOT_UNSAFE_PTR_ARG_DEREF,

clippy_lints/src/let_if_seq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
150150
if_chain! {
151151
if let hir::ExprKind::Path(ref qpath) = expr.node;
152152
if let Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id);
153-
if self.id == self.cx.tcx.hir().node_to_hir_id(local_id);
153+
if self.id == local_id;
154154
then {
155155
self.used = true;
156156
return;
@@ -175,7 +175,7 @@ fn check_assign<'a, 'tcx>(
175175
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
176176
if let hir::ExprKind::Path(ref qpath) = var.node;
177177
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);
178-
if decl == cx.tcx.hir().node_to_hir_id(local_id);
178+
if decl == local_id;
179179
then {
180180
let mut v = UsedVisitor {
181181
cx,

clippy_lints/src/loops.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bo
790790
if path.segments.len() == 1;
791791
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, expr.hir_id);
792792
// our variable!
793-
if cx.tcx.hir().node_to_hir_id(local_id) == var;
793+
if local_id == var;
794794
then {
795795
return true;
796796
}
@@ -1663,7 +1663,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
16631663
if let PatKind::Binding(bind_ann, ..) = pat.node;
16641664
if let BindingAnnotation::Mutable = bind_ann;
16651665
then {
1666-
return Some(cx.tcx.hir().node_to_hir_id(node_id));
1666+
return Some(node_id);
16671667
}
16681668
}
16691669
}
@@ -1792,9 +1792,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
17921792
}
17931793
let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id);
17941794
match def {
1795-
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
1796-
let hir_id = self.cx.tcx.hir().node_to_hir_id(node_id);
1797-
1795+
Def::Local(hir_id) | Def::Upvar(hir_id, ..) => {
17981796
let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
17991797
let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
18001798
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
@@ -1856,15 +1854,15 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18561854
then {
18571855
match self.cx.tables.qpath_def(qpath, expr.hir_id) {
18581856
Def::Upvar(local_id, ..) => {
1859-
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
1857+
if local_id == self.var {
18601858
// we are not indexing anything, record that
18611859
self.nonindex = true;
18621860
}
18631861
}
18641862
Def::Local(local_id) =>
18651863
{
18661864

1867-
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
1865+
if local_id == self.var {
18681866
self.nonindex = true;
18691867
} else {
18701868
// not the correct variable, but still a variable
@@ -2209,7 +2207,7 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
22092207
if let ExprKind::Path(ref qpath) = expr.node {
22102208
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
22112209
if let Def::Local(node_id) = path_res {
2212-
return Some(cx.tcx.hir().node_to_hir_id(node_id));
2210+
return Some(node_id);
22132211
}
22142212
}
22152213
None
@@ -2404,7 +2402,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
24042402
then {
24052403
match def {
24062404
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
2407-
self.ids.insert(self.cx.tcx.hir().node_to_hir_id(node_id));
2405+
self.ids.insert(node_id);
24082406
},
24092407
Def::Static(def_id, mutable) => {
24102408
self.def_ids.insert(def_id, mutable);

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn check_expression<'a, 'tcx: 'a>(
6868
if let hir::ExprKind::Path(path) = &args[0].node;
6969
if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id);
7070
then {
71-
if arg_id == cx.tcx.hir().node_to_hir_id(*local) {
71+
if arg_id == *local {
7272
return (false, false)
7373
}
7474
}

clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ pub fn is_try<'a>(cx: &'_ LateContext<'_, '_>, expr: &'a Expr) -> Option<&'a Exp
958958
if let PatKind::Binding(_, hir_id, _, None) = pat[0].node;
959959
if let ExprKind::Path(QPath::Resolved(None, ref path)) = arm.body.node;
960960
if let Def::Local(lid) = path.def;
961-
if cx.tcx.hir().node_to_hir_id(lid) == hir_id;
961+
if lid == hir_id;
962962
then {
963963
return true;
964964
}

clippy_lints/src/utils/usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>(
3333
Def::Local(id) | Def::Upvar(id, ..) => id,
3434
_ => return true,
3535
};
36-
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&cx.tcx.hir().node_to_hir_id(id)))
36+
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))
3737
}
3838

3939
struct MutVarsDelegate {

0 commit comments

Comments
 (0)