HirIdify some lints

This commit is contained in:
ljedrz
2019-02-24 19:43:15 +01:00
parent e99611bc39
commit 8dac8a6ba4
27 changed files with 130 additions and 126 deletions

View File

@@ -6,7 +6,6 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast;
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a` /// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
/// patterns. /// patterns.
@@ -140,12 +139,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
return; // useless if the trait doesn't exist return; // useless if the trait doesn't exist
}; };
// check that we are not inside an `impl AssignOp` of this exact operation // check that we are not inside an `impl AssignOp` of this exact operation
let parent_fn = cx.tcx.hir().get_parent(e.id); let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
let parent_impl = cx.tcx.hir().get_parent(parent_fn); let parent_impl = cx.tcx.hir().get_parent_item(parent_fn);
// the crate node is the only one that is not in the map // the crate node is the only one that is not in the map
if_chain! { if_chain! {
if parent_impl != ast::CRATE_NODE_ID; if parent_impl != hir::CRATE_HIR_ID;
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl); if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) = if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) =
&item.node; &item.node;
if trait_ref.path.def.def_id() == trait_id; if trait_ref.path.def.def_id() == trait_id;

View File

@@ -7,7 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::{LitKind, DUMMY_NODE_ID}; use syntax::ast::LitKind;
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP}; use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
/// **What it does:** Checks for boolean expressions that can be written more /// **What it does:** Checks for boolean expressions that can be written more
@@ -132,7 +132,6 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
} }
let mk_expr = |op| Expr { let mk_expr = |op| Expr {
id: DUMMY_NODE_ID,
hir_id: DUMMY_HIR_ID, hir_id: DUMMY_HIR_ID,
span: DUMMY_SP, span: DUMMY_SP,
attrs: ThinVec::new(), attrs: ThinVec::new(),

View File

@@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
.. ..
}) = get_parent_expr(cx, expr) }) = get_parent_expr(cx, expr)
{ {
if else_expr.id == expr.id { if else_expr.hir_id == expr.hir_id {
return; return;
} }
} }

View File

@@ -222,8 +222,7 @@ fn report_cc_bug(
span: Span, span: Span,
id: HirId, id: HirId,
) { ) {
let node_id = cx.tcx.hir().hir_to_node_id(id); if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, node_id) {
cx.sess().span_note_without_error( cx.sess().span_note_without_error(
span, span,
&format!( &format!(

View File

@@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! { if_chain! {
if let ExprKind::Call(ref path, ..) = expr.node; if let ExprKind::Call(ref path, ..) = expr.node;
if !any_parent_is_automatically_derived(cx.tcx, expr.id); if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
if let ExprKind::Path(ref qpath) = path.node; if let ExprKind::Path(ref qpath) = path.node;
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id)); if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD); if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);

View File

@@ -100,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) { fn consume(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
if let Categorization::Local(lid) = cmt.cat { if let Categorization::Local(lid) = cmt.cat {
if let Move(DirectRefMove) = mode { if let Move(DirectRefMove) = mode {
// moved out or in. clearly can't be localized // moved out or in. clearly can't be localized
@@ -150,7 +150,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
} }
fn borrow( fn borrow(
&mut self, &mut self,
_: NodeId, _: HirId,
_: Span, _: Span,
cmt: &cmt_<'tcx>, cmt: &cmt_<'tcx>,
_: ty::Region<'_>, _: ty::Region<'_>,
@@ -178,7 +178,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
} }
} }
fn decl_without_init(&mut self, _: NodeId, _: Span) {} fn decl_without_init(&mut self, _: NodeId, _: Span) {}
fn mutate(&mut self, _: NodeId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {} fn mutate(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: MutateMode) {}
} }
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> { impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {

View File

@@ -186,13 +186,13 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
/// When such a read is found, the lint is triggered. /// When such a read is found, the lint is triggered.
fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) { fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
let map = &vis.cx.tcx.hir(); let map = &vis.cx.tcx.hir();
let mut cur_id = vis.write_expr.id; let mut cur_id = vis.write_expr.hir_id;
loop { loop {
let parent_id = map.get_parent_node(cur_id); let parent_id = map.get_parent_node_by_hir_id(cur_id);
if parent_id == cur_id { if parent_id == cur_id {
break; break;
} }
let parent_node = match map.find(parent_id) { let parent_node = match map.find_by_hir_id(parent_id) {
Some(parent) => parent, Some(parent) => parent,
None => break, None => break,
}; };
@@ -224,7 +224,7 @@ enum StopEarly {
} }
fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> StopEarly { fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> StopEarly {
if expr.id == vis.last_expr.id { if expr.hir_id == vis.last_expr.hir_id {
return StopEarly::KeepGoing; return StopEarly::KeepGoing;
} }
@@ -298,7 +298,7 @@ struct ReadVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr) { fn visit_expr(&mut self, expr: &'tcx Expr) {
if expr.id == self.last_expr.id { if expr.hir_id == self.last_expr.hir_id {
return; return;
} }
@@ -355,7 +355,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool { fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
if let Some(parent) = get_parent_expr(cx, expr) { if let Some(parent) = get_parent_expr(cx, expr) {
if let ExprKind::Assign(ref lhs, _) = parent.node { if let ExprKind::Assign(ref lhs, _) = parent.node {
return lhs.id == expr.id; return lhs.hir_id == expr.hir_id;
} }
} }
false false

View File

@@ -6,7 +6,6 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::NodeId;
/// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions. /// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions.
/// ///
@@ -27,7 +26,7 @@ declare_clippy_lint! {
#[derive(Default)] #[derive(Default)]
pub struct IdentityConversion { pub struct IdentityConversion {
try_desugar_arm: Vec<NodeId>, try_desugar_arm: Vec<HirId>,
} }
impl LintPass for IdentityConversion { impl LintPass for IdentityConversion {
@@ -46,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
return; return;
} }
if Some(&e.id) == self.try_desugar_arm.last() { if Some(&e.hir_id) == self.try_desugar_arm.last() {
return; return;
} }
@@ -57,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
_ => return, _ => return,
}; };
if let ExprKind::Call(_, ref args) = e.node { if let ExprKind::Call(_, ref args) = e.node {
self.try_desugar_arm.push(args[0].id); self.try_desugar_arm.push(args[0].hir_id);
} else { } else {
return; return;
} }
@@ -126,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
} }
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr) { fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if Some(&e.id) == self.try_desugar_arm.last() { if Some(&e.hir_id) == self.try_desugar_arm.last() {
self.try_desugar_arm.pop(); self.try_desugar_arm.pop();
} }
} }

View File

@@ -319,7 +319,7 @@ impl<'v, 't> RefVisitor<'v, 't> {
_ => false, _ => false,
}) })
{ {
let hir_id = self.cx.tcx.hir().node_to_hir_id(ty.id); let hir_id = ty.hir_id;
match self.cx.tables.qpath_def(qpath, hir_id) { match self.cx.tables.qpath_def(qpath, hir_id) {
Def::TyAlias(def_id) | Def::Struct(def_id) => { Def::TyAlias(def_id) | Def::Struct(def_id) => {
let generics = self.cx.tcx.generics_of(def_id); let generics = self.cx.tcx.generics_of(def_id);

View File

@@ -486,7 +486,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
// check for never_loop // check for never_loop
match expr.node { match expr.node {
ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => { ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => {
match never_loop_block(block, expr.id) { let node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id);
match never_loop_block(block, node_id) {
NeverLoopResult::AlwaysBreak => { NeverLoopResult::AlwaysBreak => {
span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops") span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
}, },
@@ -1109,8 +1110,8 @@ fn check_for_loop_range<'a, 'tcx>(
// ensure that the indexed variable was declared before the loop, see #601 // ensure that the indexed variable was declared before the loop, see #601
if let Some(indexed_extent) = indexed_extent { if let Some(indexed_extent) = indexed_extent {
let parent_id = cx.tcx.hir().get_parent(expr.id); let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = cx.tcx.hir().local_def_id(parent_id); let parent_def_id = cx.tcx.hir().local_def_id_from_hir_id(parent_id);
let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id); let region_scope_tree = cx.tcx.region_scope_tree(parent_def_id);
let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id); let pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) { if region_scope_tree.is_subscope_of(indexed_extent, pat_extent) {
@@ -1469,8 +1470,9 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
// For each candidate, check the parent block to see if // For each candidate, check the parent block to see if
// it's initialized to zero at the start of the loop. // it's initialized to zero at the start of the loop.
let map = &cx.tcx.hir(); let map = &cx.tcx.hir();
let expr_node_id = map.hir_to_node_id(expr.hir_id);
let parent_scope = map let parent_scope = map
.get_enclosing_scope(expr.id) .get_enclosing_scope(expr_node_id)
.and_then(|id| map.get_enclosing_scope(id)); .and_then(|id| map.get_enclosing_scope(id));
if let Some(parent_id) = parent_scope { if let Some(parent_id) = parent_scope {
if let Node::Block(block) = map.get(parent_id) { if let Node::Block(block) = map.get(parent_id) {
@@ -1567,13 +1569,13 @@ struct MutatePairDelegate {
} }
impl<'tcx> Delegate<'tcx> for MutatePairDelegate { impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
fn consume(&mut self, _: NodeId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {} fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {} fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn borrow(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) { fn borrow(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
if let ty::BorrowKind::MutBorrow = bk { if let ty::BorrowKind::MutBorrow = bk {
if let Categorization::Local(id) = cmt.cat { if let Categorization::Local(id) = cmt.cat {
if Some(id) == self.node_id_low { if Some(id) == self.node_id_low {
@@ -1586,7 +1588,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
} }
} }
fn mutate(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) { fn mutate(&mut self, _: HirId, sp: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
if let Categorization::Local(id) = cmt.cat { if let Categorization::Local(id) = cmt.cat {
if Some(id) == self.node_id_low { if Some(id) == self.node_id_low {
self.span_low = Some(sp) self.span_low = Some(sp)
@@ -1778,8 +1780,8 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
Def::Local(node_id) | Def::Upvar(node_id, ..) => { Def::Local(node_id) | Def::Upvar(node_id, ..) => {
let hir_id = self.cx.tcx.hir().node_to_hir_id(node_id); let hir_id = self.cx.tcx.hir().node_to_hir_id(node_id);
let parent_id = self.cx.tcx.hir().get_parent(expr.id); let parent_id = self.cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_def_id = self.cx.tcx.hir().local_def_id(parent_id); let parent_def_id = self.cx.tcx.hir().local_def_id_from_hir_id(parent_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id); let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
if indexed_indirectly { if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent)); self.indexed_indirectly.insert(seqvar.segments[0].ident.name, Some(extent));
@@ -1932,11 +1934,12 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
let mut visitor = VarUsedAfterLoopVisitor { let mut visitor = VarUsedAfterLoopVisitor {
cx, cx,
def_id, def_id,
iter_expr_id: iter_expr.id, iter_expr_id: iter_expr.hir_id,
past_while_let: false, past_while_let: false,
var_used_after_while_let: false, var_used_after_while_let: false,
}; };
if let Some(enclosing_block) = get_enclosing_block(cx, def_id) { let def_hir_id = cx.tcx.hir().node_to_hir_id(def_id);
if let Some(enclosing_block) = get_enclosing_block(cx, def_hir_id) {
walk_block(&mut visitor, enclosing_block); walk_block(&mut visitor, enclosing_block);
} }
visitor.var_used_after_while_let visitor.var_used_after_while_let
@@ -1945,7 +1948,7 @@ fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, it
struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> { struct VarUsedAfterLoopVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>, cx: &'a LateContext<'a, 'tcx>,
def_id: NodeId, def_id: NodeId,
iter_expr_id: NodeId, iter_expr_id: HirId,
past_while_let: bool, past_while_let: bool,
var_used_after_while_let: bool, var_used_after_while_let: bool,
} }
@@ -1956,7 +1959,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
if Some(self.def_id) == var_def_id(self.cx, expr) { if Some(self.def_id) == var_def_id(self.cx, expr) {
self.var_used_after_while_let = true; self.var_used_after_while_let = true;
} }
} else if self.iter_expr_id == expr.id { } else if self.iter_expr_id == expr.hir_id {
self.past_while_let = true; self.past_while_let = true;
} }
walk_expr(self, expr); walk_expr(self, expr);
@@ -2068,7 +2071,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
match parent.node { match parent.node {
ExprKind::AssignOp(op, ref lhs, ref rhs) => { ExprKind::AssignOp(op, ref lhs, ref rhs) => {
if lhs.id == expr.id { if lhs.hir_id == expr.hir_id {
if op.node == BinOpKind::Add && is_integer_literal(rhs, 1) { if op.node == BinOpKind::Add && is_integer_literal(rhs, 1) {
*state = match *state { *state = match *state {
VarState::Initial if self.depth == 0 => VarState::IncrOnce, VarState::Initial if self.depth == 0 => VarState::IncrOnce,
@@ -2080,7 +2083,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
} }
} }
}, },
ExprKind::Assign(ref lhs, _) if lhs.id == expr.id => *state = VarState::DontWarn, ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
ExprKind::AddrOf(mutability, _) if mutability == MutMutable => *state = VarState::DontWarn, ExprKind::AddrOf(mutability, _) if mutability == MutMutable => *state = VarState::DontWarn,
_ => (), _ => (),
} }
@@ -2153,10 +2156,10 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
if var_def_id(self.cx, expr) == Some(self.var_id) { if var_def_id(self.cx, expr) == Some(self.var_id) {
if let Some(parent) = get_parent_expr(self.cx, expr) { if let Some(parent) = get_parent_expr(self.cx, expr) {
match parent.node { match parent.node {
ExprKind::AssignOp(_, ref lhs, _) if lhs.id == expr.id => { ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => {
self.state = VarState::DontWarn; self.state = VarState::DontWarn;
}, },
ExprKind::Assign(ref lhs, ref rhs) if lhs.id == expr.id => { ExprKind::Assign(ref lhs, ref rhs) if lhs.hir_id == expr.hir_id => {
self.state = if is_integer_literal(rhs, 0) && self.depth == 0 { self.state = if is_integer_literal(rhs, 0) && self.depth == 0 {
VarState::Warn VarState::Warn
} else { } else {
@@ -2214,8 +2217,8 @@ fn is_conditional(expr: &Expr) -> bool {
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool { fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
if_chain! { if_chain! {
if let Some(loop_block) = get_enclosing_block(cx, match_expr.id); if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id);
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(loop_block.id)); if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find_by_hir_id(cx.tcx.hir().get_parent_node_by_hir_id(loop_block.hir_id));
then { then {
return is_loop_nested(cx, loop_expr, iter_expr) return is_loop_nested(cx, loop_expr, iter_expr)
} }
@@ -2224,18 +2227,18 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> b
} }
fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr) -> bool { fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr) -> bool {
let mut id = loop_expr.id; let mut id = loop_expr.hir_id;
let iter_name = if let Some(name) = path_name(iter_expr) { let iter_name = if let Some(name) = path_name(iter_expr) {
name name
} else { } else {
return true; return true;
}; };
loop { loop {
let parent = cx.tcx.hir().get_parent_node(id); let parent = cx.tcx.hir().get_parent_node_by_hir_id(id);
if parent == id { if parent == id {
return false; return false;
} }
match cx.tcx.hir().find(parent) { match cx.tcx.hir().find_by_hir_id(parent) {
Some(Node::Expr(expr)) => match expr.node { Some(Node::Expr(expr)) => match expr.node {
ExprKind::Loop(..) | ExprKind::While(..) => { ExprKind::Loop(..) | ExprKind::While(..) => {
return true; return true;
@@ -2244,7 +2247,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
}, },
Some(Node::Block(block)) => { Some(Node::Block(block)) => {
let mut block_visitor = LoopNestVisitor { let mut block_visitor = LoopNestVisitor {
id, hir_id: id,
iterator: iter_name, iterator: iter_name,
nesting: Unknown, nesting: Unknown,
}; };
@@ -2272,14 +2275,14 @@ enum Nesting {
use self::Nesting::{LookFurther, RuledOut, Unknown}; use self::Nesting::{LookFurther, RuledOut, Unknown};
struct LoopNestVisitor { struct LoopNestVisitor {
id: NodeId, hir_id: HirId,
iterator: Name, iterator: Name,
nesting: Nesting, nesting: Nesting,
} }
impl<'tcx> Visitor<'tcx> for LoopNestVisitor { impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
fn visit_stmt(&mut self, stmt: &'tcx Stmt) { fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
if stmt.id == self.id { if stmt.hir_id == self.hir_id {
self.nesting = LookFurther; self.nesting = LookFurther;
} else if self.nesting == Unknown { } else if self.nesting == Unknown {
walk_stmt(self, stmt); walk_stmt(self, stmt);
@@ -2290,7 +2293,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
if self.nesting != Unknown { if self.nesting != Unknown {
return; return;
} }
if expr.id == self.id { if expr.hir_id == self.hir_id {
self.nesting = LookFurther; self.nesting = LookFurther;
return; return;
} }

View File

@@ -266,7 +266,7 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
return; return;
}; };
let ty = cx.tables.expr_ty(ex); let ty = cx.tables.expr_ty(ex);
if ty.sty != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.id) { if ty.sty != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) {
check_single_match_single_pattern(cx, ex, arms, expr, els); check_single_match_single_pattern(cx, ex, arms, expr, els);
check_single_match_opt_like(cx, ex, arms, expr, ty, els); check_single_match_opt_like(cx, ex, arms, expr, ty, els);
} }

View File

@@ -1082,7 +1082,7 @@ fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Spa
} }
// don't lint for constant values // don't lint for constant values
let owner_def = cx.tcx.hir().get_parent_did(arg.id); let owner_def = cx.tcx.hir().get_parent_did_by_hir_id(arg.hir_id);
let promotable = cx.tcx.rvalue_promotable_map(owner_def).contains(&arg.hir_id.local_id); let promotable = cx.tcx.rvalue_promotable_map(owner_def).contains(&arg.hir_id.local_id);
if promotable { if promotable {
return; return;
@@ -1341,8 +1341,8 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
if cx.tables.expr_ty(arg) == ty { if cx.tables.expr_ty(arg) == ty {
snip = Some(("try removing the `clone` call", format!("{}", snippet))); snip = Some(("try removing the `clone` call", format!("{}", snippet)));
} else { } else {
let parent = cx.tcx.hir().get_parent_node(expr.id); let parent = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
match cx.tcx.hir().get(parent) { match cx.tcx.hir().get_by_hir_id(parent) {
hir::Node::Expr(parent) => match parent.node { hir::Node::Expr(parent) => match parent.node {
// &*x is a nop, &x.clone() is not // &*x is a nop, &x.clone() is not
hir::ExprKind::AddrOf(..) | hir::ExprKind::AddrOf(..) |

View File

@@ -460,7 +460,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
fn check_nan(cx: &LateContext<'_, '_>, path: &Path, expr: &Expr) { fn check_nan(cx: &LateContext<'_, '_>, path: &Path, expr: &Expr) {
if !in_constant(cx, expr.id) { if !in_constant(cx, expr.hir_id) {
if let Some(seg) = path.segments.last() { if let Some(seg) = path.segments.last() {
if seg.ident.name == "NAN" { if seg.ident.name == "NAN" {
span_lint( span_lint(
@@ -615,7 +615,7 @@ fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
if let ExprKind::Lit(ref lit) = e.node; if let ExprKind::Lit(ref lit) = e.node;
if let LitKind::Int(value, ..) = lit.node; if let LitKind::Int(value, ..) = lit.node;
if value == 0; if value == 0;
if !in_constant(cx, e.id); if !in_constant(cx, e.hir_id);
then { then {
let msg = match mutbl { let msg = match mutbl {
Mutability::MutMutable => "`0 as *mut _` detected. Consider using `ptr::null_mut()`", Mutability::MutMutable => "`0 as *mut _` detected. Consider using `ptr::null_mut()`",

View File

@@ -126,8 +126,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
} }
fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool { fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool {
let parent_id = cx.tcx.hir().get_parent_node(expr.id); let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
let parent_node = cx.tcx.hir().get(parent_id); let parent_node = cx.tcx.hir().get_by_hir_id(parent_id);
if let rustc::hir::Node::Expr(e) = parent_node { if let rustc::hir::Node::Expr(e) = parent_node {
if let ExprKind::If(_, _, _) = e.node { if let ExprKind::If(_, _, _) = e.node {

View File

@@ -341,7 +341,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
} }
} }
fn move_common(&mut self, _consume_id: NodeId, _span: Span, cmt: &mc::cmt_<'tcx>) { fn move_common(&mut self, _consume_id: HirId, _span: Span, cmt: &mc::cmt_<'tcx>) {
let cmt = unwrap_downcast_or_interior(cmt); let cmt = unwrap_downcast_or_interior(cmt);
if let mc::Categorization::Local(vid) = cmt.cat { if let mc::Categorization::Local(vid) = cmt.cat {
@@ -399,7 +399,7 @@ impl<'a, 'tcx> MovedVariablesCtxt<'a, 'tcx> {
} }
impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> { impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
fn consume(&mut self, consume_id: NodeId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { fn consume(&mut self, consume_id: HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
if let euv::ConsumeMode::Move(_) = mode { if let euv::ConsumeMode::Move(_) = mode {
self.move_common(consume_id, consume_span, cmt); self.move_common(consume_id, consume_span, cmt);
} }
@@ -407,7 +407,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
fn matched_pat(&mut self, matched_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::MatchMode) { fn matched_pat(&mut self, matched_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::MatchMode) {
if let euv::MatchMode::MovingMatch = mode { if let euv::MatchMode::MovingMatch = mode {
self.move_common(matched_pat.id, matched_pat.span, cmt); self.move_common(matched_pat.hir_id, matched_pat.span, cmt);
} else { } else {
self.non_moving_pat(matched_pat, cmt); self.non_moving_pat(matched_pat, cmt);
} }
@@ -415,13 +415,13 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { fn consume_pat(&mut self, consume_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
if let euv::ConsumeMode::Move(_) = mode { if let euv::ConsumeMode::Move(_) = mode {
self.move_common(consume_pat.id, consume_pat.span, cmt); self.move_common(consume_pat.hir_id, consume_pat.span, cmt);
} }
} }
fn borrow( fn borrow(
&mut self, &mut self,
_: NodeId, _: HirId,
_: Span, _: Span,
_: &mc::cmt_<'tcx>, _: &mc::cmt_<'tcx>,
_: ty::Region<'_>, _: ty::Region<'_>,
@@ -430,7 +430,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
) { ) {
} }
fn mutate(&mut self, _: NodeId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {} fn mutate(&mut self, _: HirId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {}
fn decl_without_init(&mut self, _: NodeId, _: Span) {} fn decl_without_init(&mut self, _: NodeId, _: Span) {}
} }

View File

@@ -110,7 +110,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
} }
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
let name = impl_item.ident.name; let name = impl_item.ident.name;
let id = impl_item.id; let id = impl_item.hir_id;
let node_id = cx.tcx.hir().hir_to_node_id(id);
if sig.header.constness == hir::Constness::Const { if sig.header.constness == hir::Constness::Const {
// can't be implemented by default // can't be implemented by default
return; return;
@@ -128,11 +129,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
// impl of `Default` // impl of `Default`
return; return;
} }
if sig.decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) { if sig.decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(node_id) {
let self_did = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent(id)); let self_did = cx.tcx.hir().local_def_id_from_hir_id(cx.tcx.hir().get_parent_item(id));
let self_ty = cx.tcx.type_of(self_did); let self_ty = cx.tcx.type_of(self_did);
if_chain! { if_chain! {
if same_tys(cx, self_ty, return_ty(cx, id)); if same_tys(cx, self_ty, return_ty(cx, node_id));
if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT); if let Some(default_trait_id) = get_trait_def_id(cx, &paths::DEFAULT_TRAIT);
then { then {
if self.impling_types.is_none() { if self.impling_types.is_none() {

View File

@@ -197,7 +197,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Path(qpath) = &expr.node { if let ExprKind::Path(qpath) = &expr.node {
// Only lint if we use the const item inside a function. // Only lint if we use the const item inside a function.
if in_constant(cx, expr.id) { if in_constant(cx, expr.hir_id) {
return; return;
} }
@@ -212,11 +212,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
let mut dereferenced_expr = expr; let mut dereferenced_expr = expr;
let mut needs_check_adjustment = true; let mut needs_check_adjustment = true;
loop { loop {
let parent_id = cx.tcx.hir().get_parent_node(cur_expr.id); let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(cur_expr.hir_id);
if parent_id == cur_expr.id { if parent_id == cur_expr.hir_id {
break; break;
} }
if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find(parent_id) { if let Some(Node::Expr(parent_expr)) = cx.tcx.hir().find_by_hir_id(parent_id) {
match &parent_expr.node { match &parent_expr.node {
ExprKind::AddrOf(..) => { ExprKind::AddrOf(..) => {
// `&e` => `e` must be referenced // `&e` => `e` must be referenced

View File

@@ -51,10 +51,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
then { then {
for impl_item in impl_items { for impl_item in impl_items {
if impl_item.ident.name == "ne" { if impl_item.ident.name == "ne" {
let hir_id = cx.tcx.hir().node_to_hir_id(impl_item.id.node_id);
span_lint_node( span_lint_node(
cx, cx,
PARTIALEQ_NE_IMPL, PARTIALEQ_NE_IMPL,
impl_item.id.node_id, hir_id,
impl_item.span, impl_item.span,
"re-implementing `PartialEq::ne` is unnecessary", "re-implementing `PartialEq::ne` is unnecessary",
); );

View File

@@ -7,7 +7,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use std::convert::TryFrom; use std::convert::TryFrom;
use syntax::ast::{LitKind, NodeId, StrStyle}; use syntax::ast::{LitKind, StrStyle};
use syntax::source_map::{BytePos, Span}; use syntax::source_map::{BytePos, Span};
/// **What it does:** Checks [regex](https://crates.io/crates/regex) creation /// **What it does:** Checks [regex](https://crates.io/crates/regex) creation
@@ -69,7 +69,7 @@ declare_clippy_lint! {
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct Pass { pub struct Pass {
spans: FxHashSet<Span>, spans: FxHashSet<Span>,
last: Option<NodeId>, last: Option<HirId>,
} }
impl LintPass for Pass { impl LintPass for Pass {
@@ -102,13 +102,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
Please use `Regex::new(_)`, which is faster for now."); Please use `Regex::new(_)`, which is faster for now.");
self.spans.insert(span); self.spans.insert(span);
} }
self.last = Some(block.id); self.last = Some(block.hir_id);
} }
} }
} }
fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block) { fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block) {
if self.last.map_or(false, |id| block.id == id) { if self.last.map_or(false, |id| block.hir_id == id) {
self.last = None; self.last = None;
} }
} }

View File

@@ -6,7 +6,7 @@ use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use syntax::ast::{LitKind, NodeId}; use syntax::ast::LitKind;
use syntax_pos::symbol::Symbol; use syntax_pos::symbol::Symbol;
/// **What it does:** Checks slow zero-filled vector initialization /// **What it does:** Checks slow zero-filled vector initialization
@@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
len_expr: len_arg, len_expr: len_arg,
}; };
Self::search_initialization(cx, vi, expr.id); Self::search_initialization(cx, vi, expr.hir_id);
} }
} }
} }
@@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
len_expr: len_arg, len_expr: len_arg,
}; };
Self::search_initialization(cx, vi, stmt.id); Self::search_initialization(cx, vi, stmt.hir_id);
} }
} }
} }
@@ -132,7 +132,7 @@ impl Pass {
} }
/// Search initialization for the given vector /// Search initialization for the given vector
fn search_initialization<'tcx>(cx: &LateContext<'_, 'tcx>, vec_alloc: VecAllocation<'tcx>, parent_node: NodeId) { fn search_initialization<'tcx>(cx: &LateContext<'_, 'tcx>, vec_alloc: VecAllocation<'tcx>, parent_node: HirId) {
let enclosing_body = get_enclosing_block(cx, parent_node); let enclosing_body = get_enclosing_block(cx, parent_node);
if enclosing_body.is_none() { if enclosing_body.is_none() {
@@ -317,7 +317,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr) { fn visit_expr(&mut self, expr: &'tcx Expr) {
// Skip all the expressions previous to the vector initialization // Skip all the expressions previous to the vector initialization
if self.vec_alloc.allocation_expr.id == expr.id { if self.vec_alloc.allocation_expr.hir_id == expr.hir_id {
self.initialization_found = true; self.initialization_found = true;
} }

View File

@@ -96,7 +96,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
) = e.node ) = e.node
{ {
if is_string(cx, left) { if is_string(cx, left) {
if !is_allowed(cx, STRING_ADD_ASSIGN, e.id) { if !is_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) {
let parent = get_parent_expr(cx, e); let parent = get_parent_expr(cx, e);
if let Some(p) = parent { if let Some(p) = parent {
if let ExprKind::Assign(ref target, _) = p.node { if let ExprKind::Assign(ref target, _) = p.node {

View File

@@ -4,7 +4,6 @@ use rustc::hir;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
/// **What it does:** Lints for suspicious operations in impls of arithmetic operators, e.g. /// **What it does:** Lints for suspicious operations in impls of arithmetic operators, e.g.
/// subtracting elements in an Add impl. /// subtracting elements in an Add impl.
@@ -77,9 +76,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
} }
// Check if the binary expression is part of another bi/unary expression // Check if the binary expression is part of another bi/unary expression
// as a child node // as a child node
let mut parent_expr = cx.tcx.hir().get_parent_node(expr.id); let mut parent_expr = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
while parent_expr != ast::CRATE_NODE_ID { while parent_expr != hir::CRATE_HIR_ID {
if let hir::Node::Expr(e) = cx.tcx.hir().get(parent_expr) { if let hir::Node::Expr(e) = cx.tcx.hir().get_by_hir_id(parent_expr) {
match e.node { match e.node {
hir::ExprKind::Binary(..) hir::ExprKind::Binary(..)
| hir::ExprKind::Unary(hir::UnOp::UnNot, _) | hir::ExprKind::Unary(hir::UnOp::UnNot, _)
@@ -87,7 +86,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
_ => {}, _ => {},
} }
} }
parent_expr = cx.tcx.hir().get_parent_node(parent_expr); parent_expr = cx.tcx.hir().get_parent_node_by_hir_id(parent_expr);
} }
// as a parent node // as a parent node
let mut visitor = BinaryExprVisitor { in_binary_expr: false }; let mut visitor = BinaryExprVisitor { in_binary_expr: false };
@@ -177,12 +176,12 @@ fn check_binop<'a>(
} }
// Get the actually implemented trait // Get the actually implemented trait
let parent_fn = cx.tcx.hir().get_parent(expr.id); let parent_fn = cx.tcx.hir().get_parent_item(expr.hir_id);
let parent_impl = cx.tcx.hir().get_parent(parent_fn); let parent_impl = cx.tcx.hir().get_parent_item(parent_fn);
if_chain! { if_chain! {
if parent_impl != ast::CRATE_NODE_ID; if parent_impl != hir::CRATE_HIR_ID;
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl); if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node; if let hir::ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node;
if let Some(idx) = trait_ids.iter().position(|&tid| tid == trait_ref.path.def.def_id()); if let Some(idx) = trait_ids.iter().position(|&tid| tid == trait_ref.path.def.def_id());
if binop != expected_ops[idx]; if binop != expected_ops[idx];

View File

@@ -225,7 +225,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
_ => None, _ => None,
}); });
if let TyKind::Path(ref qpath) = ty.node; if let TyKind::Path(ref qpath) = ty.node;
if let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, cx.tcx.hir().node_to_hir_id(ty.id))); if let Some(did) = opt_def_id(cx.tables.qpath_def(qpath, ty.hir_id));
if match_def_path(cx.tcx, did, path); if match_def_path(cx.tcx, did, path);
then { then {
return true; return true;
@@ -246,7 +246,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
} }
match hir_ty.node { match hir_ty.node {
TyKind::Path(ref qpath) if !is_local => { TyKind::Path(ref qpath) if !is_local => {
let hir_id = cx.tcx.hir().node_to_hir_id(hir_ty.id); let hir_id = hir_ty.hir_id;
let def = cx.tables.qpath_def(qpath, hir_id); let def = cx.tables.qpath_def(qpath, hir_id);
if let Some(def_id) = opt_def_id(def) { if let Some(def_id) = opt_def_id(def) {
if Some(def_id) == cx.tcx.lang_items().owned_box() { if Some(def_id) == cx.tcx.lang_items().owned_box() {
@@ -375,7 +375,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) { fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) {
match mut_ty.ty.node { match mut_ty.ty.node {
TyKind::Path(ref qpath) => { TyKind::Path(ref qpath) => {
let hir_id = cx.tcx.hir().node_to_hir_id(mut_ty.ty.id); let hir_id = mut_ty.ty.hir_id;
let def = cx.tables.qpath_def(qpath, hir_id); let def = cx.tables.qpath_def(qpath, hir_id);
if_chain! { if_chain! {
if let Some(def_id) = opt_def_id(def); if let Some(def_id) = opt_def_id(def);
@@ -617,7 +617,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
} }
if_chain! { if_chain! {
let map = &cx.tcx.hir(); let map = &cx.tcx.hir();
let opt_parent_node = map.find(map.get_parent_node(expr.id)); let opt_parent_node = map.find_by_hir_id(map.get_parent_node_by_hir_id(expr.hir_id));
if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node; if let Some(hir::Node::Expr(parent_expr)) = opt_parent_node;
if is_questionmark_desugar_marked_call(parent_expr); if is_questionmark_desugar_marked_call(parent_expr);
then { then {
@@ -961,7 +961,7 @@ fn should_strip_parens(op: &Expr, snip: &str) -> bool {
fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) { fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) {
// Do not suggest using From in consts/statics until it is valid to do so (see #2267). // Do not suggest using From in consts/statics until it is valid to do so (see #2267).
if in_constant(cx, expr.id) { if in_constant(cx, expr.hir_id) {
return; return;
} }
// The suggestion is to use a function call, so if the original expression // The suggestion is to use a function call, so if the original expression

View File

@@ -2,7 +2,7 @@ use crate::utils::{is_allowed, snippet, span_help_and_lint};
use rustc::hir::*; use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array}; use rustc::{declare_tool_lint, lint_array};
use syntax::ast::{LitKind, NodeId}; use syntax::ast::LitKind;
use syntax::source_map::Span; use syntax::source_map::Span;
use unicode_normalization::UnicodeNormalization; use unicode_normalization::UnicodeNormalization;
@@ -75,7 +75,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Unicode {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Lit(ref lit) = expr.node { if let ExprKind::Lit(ref lit) = expr.node {
if let LitKind::Str(_, _) = lit.node { if let LitKind::Str(_, _) = lit.node {
check_str(cx, lit.span, expr.id) check_str(cx, lit.span, expr.hir_id)
} }
} }
} }
@@ -95,7 +95,7 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {
result result
} }
fn check_str(cx: &LateContext<'_, '_>, span: Span, id: NodeId) { fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
let string = snippet(cx, span, ""); let string = snippet(cx, span, "");
if string.contains('\u{200B}') { if string.contains('\u{200B}') {
span_help_and_lint( span_help_and_lint(

View File

@@ -1,6 +1,6 @@
//! Clippy wrappers around rustc's diagnostic functions. //! Clippy wrappers around rustc's diagnostic functions.
use crate::reexport::*; use rustc::hir::HirId;
use rustc::lint::{LateContext, Lint, LintContext}; use rustc::lint::{LateContext, Lint, LintContext};
use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart, SuggestionStyle}; use rustc_errors::{Applicability, CodeSuggestion, Substitution, SubstitutionPart, SuggestionStyle};
use std::env; use std::env;
@@ -134,19 +134,21 @@ pub fn span_lint_and_then<'a, 'tcx: 'a, T: LintContext<'tcx>, F>(
db.docs_link(lint); db.docs_link(lint);
} }
pub fn span_lint_node(cx: &LateContext<'_, '_>, lint: &'static Lint, node: NodeId, sp: Span, msg: &str) { pub fn span_lint_node(cx: &LateContext<'_, '_>, lint: &'static Lint, node: HirId, sp: Span, msg: &str) {
DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node, sp, msg)).docs_link(lint); let node_id = cx.tcx.hir().hir_to_node_id(node);
DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node_id, sp, msg)).docs_link(lint);
} }
pub fn span_lint_node_and_then( pub fn span_lint_node_and_then(
cx: &LateContext<'_, '_>, cx: &LateContext<'_, '_>,
lint: &'static Lint, lint: &'static Lint,
node: NodeId, node: HirId,
sp: Span, sp: Span,
msg: &str, msg: &str,
f: impl FnOnce(&mut DiagnosticBuilder<'_>), f: impl FnOnce(&mut DiagnosticBuilder<'_>),
) { ) {
let mut db = DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node, sp, msg)); let node_id = cx.tcx.hir().hir_to_node_id(node);
let mut db = DiagnosticWrapper(cx.tcx.struct_span_lint_node(lint, node_id, sp, msg));
f(&mut db.0); f(&mut db.0);
db.docs_link(lint); db.docs_link(lint);
} }

View File

@@ -62,9 +62,9 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
/// // Do something /// // Do something
/// } /// }
/// ``` /// ```
pub fn in_constant(cx: &LateContext<'_, '_>, id: NodeId) -> bool { pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
let parent_id = cx.tcx.hir().get_parent(id); let parent_id = cx.tcx.hir().get_parent_item(id);
match cx.tcx.hir().get(parent_id) { match cx.tcx.hir().get_by_hir_id(parent_id) {
Node::Item(&Item { Node::Item(&Item {
node: ItemKind::Const(..), node: ItemKind::Const(..),
.. ..
@@ -378,8 +378,8 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_, '_>, def_id: DefId) -> bool {
/// Get the name of the item the expression is in, if available. /// Get the name of the item the expression is in, if available.
pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<Name> { pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<Name> {
let parent_id = cx.tcx.hir().get_parent(expr.id); let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
match cx.tcx.hir().find(parent_id) { match cx.tcx.hir().find_by_hir_id(parent_id) {
Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name), Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name),
Some(Node::TraitItem(&TraitItem { ident, .. })) | Some(Node::ImplItem(&ImplItem { ident, .. })) => { Some(Node::TraitItem(&TraitItem { ident, .. })) | Some(Node::ImplItem(&ImplItem { ident, .. })) => {
Some(ident.name) Some(ident.name)
@@ -571,12 +571,12 @@ fn trim_multiline_inner(s: Cow<'_, str>, ignore_first: bool, ch: char) -> Cow<'_
/// Get a parent expressions if any this is useful to constrain a lint. /// Get a parent expressions if any this is useful to constrain a lint.
pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> { pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> {
let map = &cx.tcx.hir(); let map = &cx.tcx.hir();
let node_id: NodeId = e.id; let hir_id = e.hir_id;
let parent_id: NodeId = map.get_parent_node(node_id); let parent_id = map.get_parent_node_by_hir_id(hir_id);
if node_id == parent_id { if hir_id == parent_id {
return None; return None;
} }
map.find(parent_id).and_then(|node| { map.find_by_hir_id(hir_id).and_then(|node| {
if let Node::Expr(parent) = node { if let Node::Expr(parent) = node {
Some(parent) Some(parent)
} else { } else {
@@ -585,10 +585,11 @@ pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c
}) })
} }
pub fn get_enclosing_block<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, node: NodeId) -> Option<&'tcx Block> { pub fn get_enclosing_block<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, node: HirId) -> Option<&'tcx Block> {
let map = &cx.tcx.hir(); let map = &cx.tcx.hir();
let node_id = map.hir_to_node_id(node);
let enclosing_node = map let enclosing_node = map
.get_enclosing_scope(node) .get_enclosing_scope(node_id)
.and_then(|enclosing_id| map.find(enclosing_id)); .and_then(|enclosing_id| map.find(enclosing_id));
if let Some(node) = enclosing_node { if let Some(node) = enclosing_node {
match node { match node {
@@ -927,8 +928,9 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
/// Returns true if the lint is allowed in the current context /// Returns true if the lint is allowed in the current context
/// ///
/// Useful for skipping long running code when it's unnecessary /// Useful for skipping long running code when it's unnecessary
pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: NodeId) -> bool { pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> bool {
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow let node_id = cx.tcx.hir().hir_to_node_id(id);
cx.tcx.lint_level_at_node(lint, node_id).0 == Level::Allow
} }
pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> { pub fn get_arg_name(pat: &Pat) -> Option<ast::Name> {
@@ -1001,16 +1003,16 @@ pub fn without_block_comments(lines: Vec<&str>) -> Vec<&str> {
without without
} }
pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_, '_, '_>, node: NodeId) -> bool { pub fn any_parent_is_automatically_derived(tcx: TyCtxt<'_, '_, '_>, node: HirId) -> bool {
let map = &tcx.hir(); let map = &tcx.hir();
let mut prev_enclosing_node = None; let mut prev_enclosing_node = None;
let mut enclosing_node = node; let mut enclosing_node = node;
while Some(enclosing_node) != prev_enclosing_node { while Some(enclosing_node) != prev_enclosing_node {
if is_automatically_derived(map.attrs(enclosing_node)) { if is_automatically_derived(map.attrs_by_hir_id(enclosing_node)) {
return true; return true;
} }
prev_enclosing_node = Some(enclosing_node); prev_enclosing_node = Some(enclosing_node);
enclosing_node = map.get_parent(enclosing_node); enclosing_node = map.get_parent_item(enclosing_node);
} }
false false
} }

View File

@@ -63,19 +63,19 @@ impl<'tcx> MutVarsDelegate {
} }
impl<'tcx> Delegate<'tcx> for MutVarsDelegate { impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
fn consume(&mut self, _: NodeId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {} fn consume(&mut self, _: HirId, _: Span, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {} fn matched_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: MatchMode) {}
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
fn borrow(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) { fn borrow(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
if let ty::BorrowKind::MutBorrow = bk { if let ty::BorrowKind::MutBorrow = bk {
self.update(&cmt.cat) self.update(&cmt.cat)
} }
} }
fn mutate(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, _: MutateMode) { fn mutate(&mut self, _: HirId, _: Span, cmt: &cmt_<'tcx>, _: MutateMode) {
self.update(&cmt.cat) self.update(&cmt.cat)
} }