Skip to content

Commit

Permalink
Auto merge of #3790 - ljedrz:HirIdify_intravisit, r=phansch
Browse files Browse the repository at this point in the history
partially HirIdify lints

Enables rust-lang/rust#58232 (a part of rust-lang/rust#57578).
  • Loading branch information
bors committed Feb 24, 2019
2 parents 68114c4 + 601cbc6 commit 1ce961f
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 46 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Applicability;
use syntax::ast::{LitKind, NodeId, DUMMY_NODE_ID};
use syntax::ast::{LitKind, DUMMY_NODE_ID};
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};

/// **What it does:** Checks for boolean expressions that can be written more
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
_: &'tcx FnDecl,
body: &'tcx Body,
_: Span,
_: NodeId,
_: HirId,
) {
NonminimalBoolVisitor { cx }.visit_body(body)
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/cyclomatic_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::{Attribute, NodeId};
use syntax::ast::Attribute;
use syntax::source_map::Span;

use crate::utils::{in_macro, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
Expand Down Expand Up @@ -123,9 +123,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CyclomaticComplexity {
_: &'tcx FnDecl,
body: &'tcx Body,
span: Span,
node_id: NodeId,
hir_id: HirId,
) {
let def_id = cx.tcx.hir().local_def_id(node_id);
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
if !cx.tcx.has_attr(def_id, "test") {
self.check(cx, body, span);
}
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/enum_glob_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc::hir::def::Def;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::NodeId;
use syntax::source_map::Span;

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

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: NodeId) {
fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod, _: Span, _: HirId) {
// only check top level `use` statements
for item in &m.item_ids {
self.lint_item(cx, cx.tcx.hir().expect_item(item.id));
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
_: &'tcx FnDecl,
body: &'tcx Body,
_: Span,
node_id: NodeId,
hir_id: HirId,
) {
// If the method is an impl for a trait, don't warn
let parent_id = cx.tcx.hir().get_parent(node_id);
let parent_node = cx.tcx.hir().find(parent_id);
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
let parent_node = cx.tcx.hir().find_by_hir_id(parent_id);

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

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

Expand Down
9 changes: 7 additions & 2 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
decl: &'tcx hir::FnDecl,
body: &'tcx hir::Body,
span: Span,
nodeid: ast::NodeId,
hir_id: hir::HirId,
) {
let is_impl = if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(nodeid)) {
let is_impl = if let Some(hir::Node::Item(item)) = cx
.tcx
.hir()
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
{
matches!(item.node, hir::ItemKind::Impl(_, _, _, _, Some(_), _, _))
} else {
false
Expand Down Expand Up @@ -146,6 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
}
}

let nodeid = cx.tcx.hir().hir_to_node_id(hir_id);
self.check_raw_ptr(cx, unsafety, decl, body, nodeid);
self.check_line_number(cx, span);
}
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/implicit_return.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::utils::{in_macro, is_expn_of, snippet_opt, span_lint_and_then};
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, MatchSource};
use rustc::hir::{intravisit::FnKind, Body, ExprKind, FnDecl, HirId, MatchSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::{ast::NodeId, source_map::Span};
use syntax::source_map::Span;

/// **What it does:** Checks for missing return statements at the end of a block.
///
Expand Down Expand Up @@ -128,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
_: &'tcx FnDecl,
body: &'tcx Body,
span: Span,
_: NodeId,
_: HirId,
) {
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
let mir = cx.tcx.optimized_mir(def_id);
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::consts::{constant, Constant};
use crate::reexport::*;
use crate::utils::sugg::Sugg;
use crate::utils::{
get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal, iter_input_pats,
Expand Down Expand Up @@ -256,7 +255,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
decl: &'tcx FnDecl,
body: &'tcx Body,
_: Span,
_: NodeId,
_: HirId,
) {
if let FnKind::Closure(_) = k {
// Does not apply to closures
Expand Down
7 changes: 3 additions & 4 deletions clippy_lints/src/missing_const_for_fn.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::utils::{is_entrypoint_fn, span_lint};
use rustc::hir;
use rustc::hir::intravisit::FnKind;
use rustc::hir::{Body, Constness, FnDecl};
use rustc::hir::{Body, Constness, FnDecl, HirId};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_mir::transform::qualify_min_const_fn::is_min_const_fn;
use syntax::ast::NodeId;
use syntax_pos::Span;

/// **What it does:**
Expand Down Expand Up @@ -79,9 +78,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingConstForFn {
_: &FnDecl,
_: &Body,
span: Span,
node_id: NodeId,
hir_id: HirId,
) {
let def_id = cx.tcx.hir().local_def_id(node_id);
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);

if is_entrypoint_fn(cx, def_id) {
return;
Expand Down
10 changes: 7 additions & 3 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
decl: &'tcx FnDecl,
body: &'tcx Body,
span: Span,
node_id: NodeId,
hir_id: HirId,
) {
if in_macro(span) {
return;
Expand All @@ -103,7 +103,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
}

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

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

let fn_def_id = cx.tcx.hir().local_def_id(node_id);
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);

let preds = traits::elaborate_predicates(cx.tcx, cx.param_env.caller_bounds.to_vec())
.filter(|p| !p.is_global())
Expand Down
9 changes: 3 additions & 6 deletions clippy_lints/src/redundant_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::utils::{
use if_chain::if_chain;
use matches::matches;
use rustc::hir::intravisit::FnKind;
use rustc::hir::{def_id, Body, FnDecl};
use rustc::hir::{def_id, Body, FnDecl, HirId};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::mir::{
self, traversal,
Expand All @@ -16,10 +16,7 @@ use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use std::convert::TryFrom;
use syntax::{
ast::NodeId,
source_map::{BytePos, Span},
};
use syntax::source_map::{BytePos, Span};

macro_rules! unwrap_or_continue {
($x:expr) => {
Expand Down Expand Up @@ -88,7 +85,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
_: &'tcx FnDecl,
body: &'tcx Body,
_: Span,
_: NodeId,
_: HirId,
) {
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
let mir = cx.tcx.optimized_mir(def_id);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
decl: &'tcx FnDecl,
body: &'tcx Body,
_: Span,
_: NodeId,
_: HirId,
) {
if in_external_macro(cx.sess(), body.value.span) {
return;
Expand Down
11 changes: 7 additions & 4 deletions clippy_lints/src/trivially_copy_pass_by_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use rustc_target::abi::LayoutOf;
use rustc_target::spec::abi::Abi;
use syntax::ast::NodeId;
use syntax_pos::Span;

/// **What it does:** Checks for functions taking arguments by reference, where
Expand Down Expand Up @@ -165,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
decl: &'tcx FnDecl,
_body: &'tcx Body,
span: Span,
node_id: NodeId,
hir_id: HirId,
) {
if in_macro(span) {
return;
Expand All @@ -187,15 +186,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
}

// Exclude non-inherent impls
if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(node_id)) {
if let Some(Node::Item(item)) = cx
.tcx
.hir()
.find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(hir_id))
{
if matches!(item.node, ItemKind::Impl(_, _, _, _, Some(_), _, _) |
ItemKind::Trait(..))
{
return;
}
}

let fn_def_id = cx.tcx.hir().local_def_id(node_id);
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);

let fn_sig = cx.tcx.fn_sig(fn_def_id);
let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);
Expand Down
7 changes: 3 additions & 4 deletions clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(clippy::default_hash_types)]

use crate::consts::{constant, Constant};
use crate::reexport::*;
use crate::utils::paths;
use crate::utils::{
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment,
Expand Down Expand Up @@ -175,9 +174,9 @@ impl LintPass for TypePass {
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypePass {
fn check_fn(&mut self, cx: &LateContext<'_, '_>, _: FnKind<'_>, decl: &FnDecl, _: &Body, _: Span, id: NodeId) {
fn check_fn(&mut self, cx: &LateContext<'_, '_>, _: FnKind<'_>, decl: &FnDecl, _: &Body, _: Span, id: HirId) {
// skip trait implementations, see #605
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent(id)) {
if let Some(hir::Node::Item(item)) = cx.tcx.hir().find_by_hir_id(cx.tcx.hir().get_parent_item(id)) {
if let ItemKind::Impl(_, _, _, _, Some(..), _, _) = item.node {
return;
}
Expand Down Expand Up @@ -1336,7 +1335,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
decl: &'tcx FnDecl,
_: &'tcx Body,
_: Span,
_: NodeId,
_: HirId,
) {
self.check_fndecl(cx, decl);
}
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/unused_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rustc::hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visit
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashMap;
use syntax::ast;
use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;

Expand Down Expand Up @@ -53,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
decl: &'tcx hir::FnDecl,
body: &'tcx hir::Body,
span: Span,
fn_id: ast::NodeId,
fn_id: hir::HirId,
) {
if in_macro(span) {
return;
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use rustc::{declare_tool_lint, lint_array};
use crate::utils::{in_macro, match_type, paths, span_lint_and_then, usage::is_potentially_mutated};
use rustc::hir::intravisit::*;
use rustc::hir::*;
use syntax::ast::NodeId;
use syntax::source_map::Span;

/// **What it does:** Checks for calls of `unwrap[_err]()` that cannot fail.
Expand Down Expand Up @@ -198,7 +197,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
decl: &'tcx FnDecl,
body: &'tcx Body,
span: Span,
fn_id: NodeId,
fn_id: HirId,
) {
if in_macro(span) {
return;
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc::hir::{BindingAnnotation, Expr, ExprKind, Pat, PatKind, QPath, Stmt, S
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashMap;
use syntax::ast::{Attribute, LitKind, DUMMY_NODE_ID};
use syntax::ast::{Attribute, LitKind};

/// **What it does:** Generates clippy code that detects the offending pattern
///
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
return;
}
prelude();
PrintVisitor::new("var").visit_variant(var, generics, DUMMY_NODE_ID);
PrintVisitor::new("var").visit_variant(var, generics, hir::DUMMY_HIR_ID);
done();
}

Expand Down

0 comments on commit 1ce961f

Please sign in to comment.