Skip to content

Commit f1f9705

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

16 files changed

+52
-43
lines changed

clippy_lints/src/booleans.rs

+2-2
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

+3-3
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

+1-2
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

+4-4
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

+5-2
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ 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.tcx.hir().find_by_hir_id(
118+
cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
119+
{
118120
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
119121
} else {
120122
false
@@ -146,6 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
146148
}
147149
}
148150

151+
let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
149152
self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
150153
self.check_line_number(cx, span);
151154
}

clippy_lints/src/implicit_return.rs

+3-3
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

+1-2
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

+3-4
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

+5-3
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,9 @@ 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.tcx.hir().find_by_hir_id(
107+
cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
108+
{
107109
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
108110
ItemKind::Trait(..))
109111
{
@@ -122,7 +124,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
122124

123125
let sized_trait = need!(cx.tcx.lang_items().sized_trait());
124126

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

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

clippy_lints/src/redundant_clone.rs

+2-3
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,
@@ -17,7 +17,6 @@ use rustc::{declare_tool_lint, lint_array};
1717
use rustc_errors::Applicability;
1818
use std::convert::TryFrom;
1919
use syntax::{
20-
ast::NodeId,
2120
source_map::{BytePos, Span},
2221
};
2322

@@ -88,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
8887
_: &'tcx FnDecl,
8988
body: &'tcx Body,
9089
_: Span,
91-
_: NodeId,
90+
_: HirId,
9291
) {
9392
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
9493
let mir = cx.tcx.optimized_mir(def_id);

clippy_lints/src/shadow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
9696
decl: &'tcx FnDecl,
9797
body: &'tcx Body,
9898
_: Span,
99-
_: NodeId,
99+
_: HirId,
100100
) {
101101
if in_external_macro(cx.sess(), body.value.span) {
102102
return;

clippy_lints/src/trivially_copy_pass_by_ref.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc::{declare_tool_lint, lint_array};
1313
use rustc_errors::Applicability;
1414
use rustc_target::abi::LayoutOf;
1515
use rustc_target::spec::abi::Abi;
16-
use syntax::ast::NodeId;
1716
use syntax_pos::Span;
1817

1918
/// **What it does:** Checks for functions taking arguments by reference, where
@@ -165,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
165164
decl: &'tcx FnDecl,
166165
_body: &'tcx Body,
167166
span: Span,
168-
node_id: NodeId,
167+
hir_id: HirId,
169168
) {
170169
if in_macro(span) {
171170
return;
@@ -187,15 +186,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
187186
}
188187

189188
// Exclude non-inherent impls
190-
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(node_id)) {
189+
if let Some(Node::Item(item)) = cx.tcx.hir().find_by_hir_id(
190+
cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
191+
{
191192
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
192193
ItemKind::Trait(..))
193194
{
194195
return;
195196
}
196197
}
197198

198-
let fn_def_id = cx.tcx.hir().local_def_id(node_id);
199+
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
199200

200201
let fn_sig = cx.tcx.fn_sig(fn_def_id);
201202
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);

clippy_lints/src/types.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(clippy::default_hash_types)]
22

33
use crate::consts::{constant, Constant};
4-
use crate::reexport::*;
54
use crate::utils::paths;
65
use crate::utils::{
76
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment,
@@ -175,9 +174,19 @@ impl LintPass for TypePass {
175174
}
176175

177176
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass {
178-
fn check_fn(&mut self, cx: &LateContext<'_, '_>, _: FnKind<'_>, decl: &FnDecl, _: &Body, _: Span, id: NodeId) {
177+
fn check_fn(
178+
&mut self,
179+
cx: &LateContext<'_, '_>,
180+
_: FnKind<'_>,
181+
decl: &FnDecl,
182+
_: &Body,
183+
_: Span,
184+
id: HirId,
185+
) {
179186
// skip trait implementations, see #605
180-
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent(id)) {
187+
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_hir_id(
188+
cx.tcx.hir().get_parent_item(id))
189+
{
181190
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node {
182191
return;
183192
}
@@ -1336,7 +1345,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
13361345
decl: &'tcx FnDecl,
13371346
_: &'tcx Body,
13381347
_: Span,
1339-
_: NodeId,
1348+
_: HirId,
13401349
) {
13411350
self.check_fndecl(cx, decl);
13421351
}

clippy_lints/src/unused_label.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visit
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
55
use rustc::{declare_tool_lint, lint_array};
66
use rustc_data_structures::fx::FxHashMap;
7-
use syntax::ast;
87
use syntax::source_map::Span;
98
use syntax::symbol::LocalInternedString;
109

@@ -53,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
5352
decl: &'tcx hir::FnDecl,
5453
body: &'tcx hir::Body,
5554
span: Span,
56-
fn_id: ast::NodeId,
55+
fn_id: hir::HirId,
5756
) {
5857
if in_macro(span) {
5958
return;

clippy_lints/src/unwrap.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::{declare_tool_lint, lint_array};
55
use crate::utils::{in_macro, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
66
use rustc::hir::intravisit::*;
77
use rustc::hir::*;
8-
use syntax::ast::NodeId;
98
use syntax::source_map::Span;
109

1110
/// **What it does:** Checks for calls of `unwrap[_err]()` that cannot fail.
@@ -198,7 +197,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
198197
decl: &'tcx FnDecl,
199198
body: &'tcx Body,
200199
span: Span,
201-
fn_id: NodeId,
200+
fn_id: HirId,
202201
) {
203202
if in_macro(span) {
204203
return;

clippy_lints/src/utils/author.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc::hir::{BindingAnnotation, Expr, ExprKind, Pat, PatKind, QPath, Stmt, S
88
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
99
use rustc::{declare_tool_lint, lint_array};
1010
use rustc_data_structures::fx::FxHashMap;
11-
use syntax::ast::{Attribute, LitKind, DUMMY_NODE_ID};
11+
use syntax::ast::{Attribute, LitKind};
1212

1313
/// **What it does:** Generates clippy code that detects the offending pattern
1414
///
@@ -103,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
103103
return;
104104
}
105105
prelude();
106-
PrintVisitor::new("var").visit_variant(var, generics, DUMMY_NODE_ID);
106+
PrintVisitor::new("var").visit_variant(var, generics, hir::DUMMY_HIR_ID);
107107
done();
108108
}
109109

0 commit comments

Comments
 (0)