Skip to content

Commit 1ce961f

Browse files
committed
Auto merge of #3790 - ljedrz:HirIdify_intravisit, r=phansch
partially HirIdify lints Enables rust-lang/rust#58232 (a part of rust-lang/rust#57578).
2 parents 68114c4 + 601cbc6 commit 1ce961f

16 files changed

+49
-46
lines changed

clippy_lints/src/booleans.rs

Lines changed: 2 additions & 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, NodeId, DUMMY_NODE_ID};
10+
use syntax::ast::{LitKind, DUMMY_NODE_ID};
1111
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
1212

1313
/// **What it does:** Checks for boolean expressions that can be written more
@@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
7272
_: &'tcx FnDecl,
7373
body: &'tcx Body,
7474
_: Span,
75-
_: NodeId,
75+
_: HirId,
7676
) {
7777
NonminimalBoolVisitor { cx }.visit_body(body)
7878
}

clippy_lints/src/cyclomatic_complexity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
77
use rustc::ty;
88
use rustc::{declare_tool_lint, lint_array};
9-
use syntax::ast::{Attribute, NodeId};
9+
use syntax::ast::Attribute;
1010
use syntax::source_map::Span;
1111

1212
use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
@@ -123,9 +123,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CyclomaticComplexity {
123123
_: &'tcx FnDecl,
124124
body: &'tcx Body,
125125
span: Span,
126-
node_id: NodeId,
126+
hir_id: HirId,
127127
) {
128-
let def_id = cx.tcx.hir().local_def_id(node_id);
128+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
129129
if !cx.tcx.has_attr(def_id, "test") {
130130
self.check(cx, body, span);
131131
}

clippy_lints/src/enum_glob_use.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::hir::def::Def;
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_tool_lint, lint_array};
8-
use syntax::ast::NodeId;
98
use syntax::source_map::Span;
109

1110
/// **What it does:** Checks for `use Enum::*`.
@@ -39,7 +38,7 @@ impl LintPass for EnumGlobUse {
3938
}
4039

4140
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
42-
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: NodeId) {
41+
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) {
4342
// only check top level `use` statements
4443
for item in &m.item_ids {
4544
self.lint_item(cx, cx.tcx.hir().expect_item(item.id));

clippy_lints/src/escape.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
6666
_: &'tcx FnDecl,
6767
body: &'tcx Body,
6868
_: Span,
69-
node_id: NodeId,
69+
hir_id: HirId,
7070
) {
7171
// If the method is an impl for a trait, don't warn
72-
let parent_id = cx.tcx.hir().get_parent(node_id);
73-
let parent_node = cx.tcx.hir().find(parent_id);
72+
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
73+
let parent_node = cx.tcx.hir().find_by_hir_id(parent_id);
7474

7575
if let Some(Node::Item(item)) = parent_node {
7676
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node {
@@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
8484
too_large_for_stack: self.too_large_for_stack,
8585
};
8686

87-
let fn_def_id = cx.tcx.hir().local_def_id(node_id);
87+
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
8888
let region_scope_tree = &cx.tcx.region_scope_tree(fn_def_id);
8989
ExprUseVisitor::new(&mut v, cx.tcx, cx.param_env, region_scope_tree, cx.tables, None).consume_body(body);
9090

clippy_lints/src/functions.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
112112
decl: &'tcx hir::FnDecl,
113113
body: &'tcx hir::Body,
114114
span: Span,
115-
nodeid: ast::NodeId,
115+
hir_id: hir::HirId,
116116
) {
117-
let is_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(nodeid)) {
117+
let is_impl = if let Some(hir::Node::Item(item)) = cx
118+
.tcx
119+
.hir()
120+
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
121+
{
118122
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
119123
} else {
120124
false
@@ -146,6 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
146150
}
147151
}
148152

153+
let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
149154
self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
150155
self.check_line_number(cx, span);
151156
}

clippy_lints/src/implicit_return.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::utils::{in_macro, is_expn_of, snippet_opt, span_lint_and_then};
2-
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, MatchSource};
2+
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource};
33
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
44
use rustc::{declare_tool_lint, lint_array};
55
use rustc_errors::Applicability;
6-
use syntax::{ast::NodeId, source_map::Span};
6+
use syntax::source_map::Span;
77

88
/// **What it does:** Checks for missing return statements at the end of a block.
99
///
@@ -128,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
128128
_: &'tcx FnDecl,
129129
body: &'tcx Body,
130130
span: Span,
131-
_: NodeId,
131+
_: HirId,
132132
) {
133133
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
134134
let mir = cx.tcx.optimized_mir(def_id);

clippy_lints/src/misc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::consts::{constant, Constant};
2-
use crate::reexport::*;
32
use crate::utils::sugg::Sugg;
43
use crate::utils::{
54
get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal, iter_input_pats,
@@ -256,7 +255,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
256255
decl: &'tcx FnDecl,
257256
body: &'tcx Body,
258257
_: Span,
259-
_: NodeId,
258+
_: HirId,
260259
) {
261260
if let FnKind::Closure(_) = k {
262261
// Does not apply to closures

clippy_lints/src/missing_const_for_fn.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::utils::{is_entrypoint_fn, span_lint};
22
use rustc::hir;
33
use rustc::hir::intravisit::FnKind;
4-
use rustc::hir::{Body, Constness, FnDecl};
4+
use rustc::hir::{Body, Constness, FnDecl, HirId};
55
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
66
use rustc::{declare_tool_lint, lint_array};
77
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
8-
use syntax::ast::NodeId;
98
use syntax_pos::Span;
109

1110
/// **What it does:**
@@ -79,9 +78,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
7978
_: &FnDecl,
8079
_: &Body,
8180
span: Span,
82-
node_id: NodeId,
81+
hir_id: HirId,
8382
) {
84-
let def_id = cx.tcx.hir().local_def_id(node_id);
83+
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
8584

8685
if is_entrypoint_fn(cx, def_id) {
8786
return;

clippy_lints/src/needless_pass_by_value.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
8181
decl: &'tcx FnDecl,
8282
body: &'tcx Body,
8383
span: Span,
84-
node_id: NodeId,
84+
hir_id: HirId,
8585
) {
8686
if in_macro(span) {
8787
return;
@@ -103,7 +103,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
103103
}
104104

105105
// Exclude non-inherent impls
106-
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(node_id)) {
106+
if let Some(Node::Item(item)) = cx
107+
.tcx
108+
.hir()
109+
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
110+
{
107111
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
108112
ItemKind::Trait(..))
109113
{
@@ -122,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
122126

123127
let sized_trait = need!(cx.tcx.lang_items().sized_trait());
124128

125-
let fn_def_id = cx.tcx.hir().local_def_id(node_id);
129+
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
126130

127131
let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec())
128132
.filter(|p| !p.is_global())

clippy_lints/src/redundant_clone.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::utils::{
55
use if_chain::if_chain;
66
use matches::matches;
77
use rustc::hir::intravisit::FnKind;
8-
use rustc::hir::{def_id, Body, FnDecl};
8+
use rustc::hir::{def_id, Body, FnDecl, HirId};
99
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1010
use rustc::mir::{
1111
self, traversal,
@@ -16,10 +16,7 @@ use rustc::ty;
1616
use rustc::{declare_tool_lint, lint_array};
1717
use rustc_errors::Applicability;
1818
use std::convert::TryFrom;
19-
use syntax::{
20-
ast::NodeId,
21-
source_map::{BytePos, Span},
22-
};
19+
use syntax::source_map::{BytePos, Span};
2320

2421
macro_rules! unwrap_or_continue {
2522
($x:expr) => {
@@ -88,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
8885
_: &'tcx FnDecl,
8986
body: &'tcx Body,
9087
_: Span,
91-
_: NodeId,
88+
_: HirId,
9289
) {
9390
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
9491
let mir = cx.tcx.optimized_mir(def_id);

0 commit comments

Comments
 (0)