partially HirIdify lints
This commit is contained in:
parent
d61b25419b
commit
1fac380886
@ -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
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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};
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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::*`.
|
||||
@ -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));
|
||||
|
@ -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 {
|
||||
@ -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);
|
||||
|
||||
|
@ -112,9 +112,11 @@ 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
|
||||
@ -146,6 +148,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);
|
||||
}
|
||||
|
@ -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.
|
||||
///
|
||||
@ -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);
|
||||
|
@ -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,
|
||||
@ -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
|
||||
|
@ -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:**
|
||||
@ -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;
|
||||
|
@ -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;
|
||||
@ -103,7 +103,9 @@ 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(..))
|
||||
{
|
||||
@ -122,7 +124,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())
|
||||
|
@ -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,
|
||||
@ -17,7 +17,6 @@ use rustc::{declare_tool_lint, lint_array};
|
||||
use rustc_errors::Applicability;
|
||||
use std::convert::TryFrom;
|
||||
use syntax::{
|
||||
ast::NodeId,
|
||||
source_map::{BytePos, Span},
|
||||
};
|
||||
|
||||
@ -88,7 +87,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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
@ -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;
|
||||
@ -187,7 +186,9 @@ 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(..))
|
||||
{
|
||||
@ -195,7 +196,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
@ -175,9 +174,19 @@ 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;
|
||||
}
|
||||
@ -1336,7 +1345,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexityPass {
|
||||
decl: &'tcx FnDecl,
|
||||
_: &'tcx Body,
|
||||
_: Span,
|
||||
_: NodeId,
|
||||
_: HirId,
|
||||
) {
|
||||
self.check_fndecl(cx, decl);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
@ -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.
|
||||
@ -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;
|
||||
|
@ -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
|
||||
///
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user