Auto merge of #3814 - ljedrz:HirIdification_lockstep_upgrade, r=phansch

HirIdify some lints

Unblocks https://github.com/rust-lang/rust/pull/58561 (a part of [rust-lang/rust#57578](https://github.com/rust-lang/rust/pull/57578)). Can we branch it like with https://github.com/rust-lang/rust-clippy/pull/3790? I can rebase on a different commit if need be.

Haven't had time to run tests yet, so I'd wait for Travis 🙈.
This commit is contained in:
bors 2019-02-26 10:43:50 +00:00
commit 412d41ae86
27 changed files with 131 additions and 126 deletions

View File

@ -6,7 +6,6 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast;
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
/// patterns.
@ -140,12 +139,12 @@ macro_rules! ops {
return; // useless if the trait doesn't exist
};
// 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_impl = cx.tcx.hir().get_parent(parent_fn);
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
let parent_impl = cx.tcx.hir().get_parent_item(parent_fn);
// the crate node is the only one that is not in the map
if_chain! {
if parent_impl != ast::CRATE_NODE_ID;
if let hir::Node::Item(item) = cx.tcx.hir().get(parent_impl);
if parent_impl != hir::CRATE_HIR_ID;
if let hir::Node::Item(item) = cx.tcx.hir().get_by_hir_id(parent_impl);
if let hir::ItemKind::Impl(_, _, _, _, Some(trait_ref), _, _) =
&item.node;
if trait_ref.path.def.def_id() == trait_id;

View File

@ -7,7 +7,7 @@
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Applicability;
use syntax::ast::{LitKind, DUMMY_NODE_ID};
use syntax::ast::LitKind;
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
/// **What it does:** Checks for boolean expressions that can be written more
@ -132,7 +132,6 @@ fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
}
let mk_expr = |op| Expr {
id: DUMMY_NODE_ID,
hir_id: DUMMY_HIR_ID,
span: DUMMY_SP,
attrs: ThinVec::new(),

View File

@ -125,7 +125,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
..
}) = get_parent_expr(cx, expr)
{
if else_expr.id == expr.id {
if else_expr.hir_id == expr.hir_id {
return;
}
}

View File

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

View File

@ -100,7 +100,7 @@ fn check_fn(
}
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 Move(DirectRefMove) = mode {
// moved out or in. clearly can't be localized
@ -150,7 +150,7 @@ fn consume_pat(&mut self, consume_pat: &Pat, cmt: &cmt_<'tcx>, _: ConsumeMode) {
}
fn borrow(
&mut self,
_: NodeId,
_: HirId,
_: Span,
cmt: &cmt_<'tcx>,
_: ty::Region<'_>,
@ -178,7 +178,7 @@ fn borrow(
}
}
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> {

View File

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

View File

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

View File

@ -319,7 +319,7 @@ fn collect_anonymous_lifetimes(&mut self, qpath: &QPath, ty: &Ty) {
_ => 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) {
Def::TyAlias(def_id) | Def::Struct(def_id) => {
let generics = self.cx.tcx.generics_of(def_id);

View File

@ -486,7 +486,8 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// check for never_loop
match expr.node {
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 => {
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
if let Some(indexed_extent) = indexed_extent {
let parent_id = cx.tcx.hir().get_parent(expr.id);
let parent_def_id = cx.tcx.hir().local_def_id(parent_id);
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_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 pat_extent = region_scope_tree.var_scope(pat.hir_id.local_id);
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
// it's initialized to zero at the start of the loop.
let map = &cx.tcx.hir();
let expr_node_id = map.hir_to_node_id(expr.hir_id);
let parent_scope = map
.get_enclosing_scope(expr.id)
.get_enclosing_scope(expr_node_id)
.and_then(|id| map.get_enclosing_scope(id));
if let Some(parent_id) = parent_scope {
if let Node::Block(block) = map.get(parent_id) {
@ -1567,13 +1569,13 @@ struct 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 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 Categorization::Local(id) = cmt.cat {
if Some(id) == self.node_id_low {
@ -1586,7 +1588,7 @@ fn borrow(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, b
}
}
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 Some(id) == self.node_id_low {
self.span_low = Some(sp)
@ -1778,8 +1780,8 @@ fn check(&mut self, idx: &'tcx Expr, seqexpr: &'tcx Expr, expr: &'tcx Expr) -> b
Def::Local(node_id) | Def::Upvar(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_def_id = self.cx.tcx.hir().local_def_id(parent_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_from_hir_id(parent_id);
let extent = self.cx.tcx.region_scope_tree(parent_def_id).var_scope(hir_id.local_id);
if indexed_indirectly {
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 {
cx,
def_id,
iter_expr_id: iter_expr.id,
iter_expr_id: iter_expr.hir_id,
past_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);
}
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> {
cx: &'a LateContext<'a, 'tcx>,
def_id: NodeId,
iter_expr_id: NodeId,
iter_expr_id: HirId,
past_while_let: bool,
var_used_after_while_let: bool,
}
@ -1956,7 +1959,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
if Some(self.def_id) == var_def_id(self.cx, expr) {
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;
}
walk_expr(self, expr);
@ -2068,7 +2071,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
match parent.node {
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) {
*state = match *state {
VarState::Initial if self.depth == 0 => VarState::IncrOnce,
@ -2080,7 +2083,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
}
}
},
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,
_ => (),
}
@ -2153,10 +2156,10 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
if var_def_id(self.cx, expr) == Some(self.var_id) {
if let Some(parent) = get_parent_expr(self.cx, expr) {
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;
},
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 {
VarState::Warn
} else {
@ -2214,8 +2217,9 @@ fn is_conditional(expr: &Expr) -> bool {
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
if_chain! {
if let Some(loop_block) = get_enclosing_block(cx, match_expr.id);
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_node(loop_block.id));
if let Some(loop_block) = get_enclosing_block(cx, match_expr.hir_id);
let parent_node = cx.tcx.hir().get_parent_node_by_hir_id(loop_block.hir_id);
if let Some(Node::Expr(loop_expr)) = cx.tcx.hir().find_by_hir_id(parent_node);
then {
return is_loop_nested(cx, loop_expr, iter_expr)
}
@ -2224,18 +2228,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 {
let mut id = loop_expr.id;
let mut id = loop_expr.hir_id;
let iter_name = if let Some(name) = path_name(iter_expr) {
name
} else {
return true;
};
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 {
return false;
}
match cx.tcx.hir().find(parent) {
match cx.tcx.hir().find_by_hir_id(parent) {
Some(Node::Expr(expr)) => match expr.node {
ExprKind::Loop(..) | ExprKind::While(..) => {
return true;
@ -2244,7 +2248,7 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
},
Some(Node::Block(block)) => {
let mut block_visitor = LoopNestVisitor {
id,
hir_id: id,
iterator: iter_name,
nesting: Unknown,
};
@ -2272,14 +2276,14 @@ enum Nesting {
use self::Nesting::{LookFurther, RuledOut, Unknown};
struct LoopNestVisitor {
id: NodeId,
hir_id: HirId,
iterator: Name,
nesting: Nesting,
}
impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
if stmt.id == self.id {
if stmt.hir_id == self.hir_id {
self.nesting = LookFurther;
} else if self.nesting == Unknown {
walk_stmt(self, stmt);
@ -2290,7 +2294,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
if self.nesting != Unknown {
return;
}
if expr.id == self.id {
if expr.hir_id == self.hir_id {
self.nesting = LookFurther;
return;
}

View File

@ -266,7 +266,7 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
return;
};
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_opt_like(cx, ex, arms, expr, ty, els);
}

View File

@ -1082,7 +1082,7 @@ fn check_general_case(
}
// 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);
if promotable {
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 {
snip = Some(("try removing the `clone` call", format!("{}", snippet)));
} else {
let parent = cx.tcx.hir().get_parent_node(expr.id);
match cx.tcx.hir().get(parent) {
let parent = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
match cx.tcx.hir().get_by_hir_id(parent) {
hir::Node::Expr(parent) => match parent.node {
// &*x is a nop, &x.clone() is not
hir::ExprKind::AddrOf(..) |

View File

@ -460,7 +460,7 @@ fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
}
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 seg.ident.name == "NAN" {
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 LitKind::Int(value, ..) = lit.node;
if value == 0;
if !in_constant(cx, e.id);
if !in_constant(cx, e.hir_id);
then {
let msg = match mutbl {
Mutability::MutMutable => "`0 as *mut _` detected. Consider using `ptr::null_mut()`",

View File

@ -126,8 +126,8 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
}
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_node = cx.tcx.hir().get(parent_id);
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(expr.hir_id);
let parent_node = cx.tcx.hir().get_by_hir_id(parent_id);
if let rustc::hir::Node::Expr(e) = parent_node {
if let ExprKind::If(_, _, _) = e.node {

View File

@ -341,7 +341,7 @@ fn new(cx: &'a LateContext<'a, 'tcx>) -> Self {
}
}
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);
if let mc::Categorization::Local(vid) = cmt.cat {
@ -399,7 +399,7 @@ fn non_moving_pat(&mut self, matched_pat: &Pat, cmt: &mc::cmt_<'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 {
self.move_common(consume_id, consume_span, cmt);
}
@ -407,7 +407,7 @@ fn consume(&mut self, consume_id: NodeId, consume_span: Span, cmt: &mc::cmt_<'tc
fn matched_pat(&mut self, matched_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::MatchMode) {
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 {
self.non_moving_pat(matched_pat, cmt);
}
@ -415,13 +415,13 @@ fn matched_pat(&mut self, matched_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::Ma
fn consume_pat(&mut self, consume_pat: &Pat, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) {
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(
&mut self,
_: NodeId,
_: HirId,
_: Span,
_: &mc::cmt_<'tcx>,
_: ty::Region<'_>,
@ -430,7 +430,7 @@ fn borrow(
) {
}
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) {}
}

View File

@ -110,7 +110,8 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
}
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
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 {
// can't be implemented by default
return;
@ -128,11 +129,11 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::Item) {
// impl of `Default`
return;
}
if sig.decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) {
let self_did = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent(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_from_hir_id(cx.tcx.hir().get_parent_item(id));
let self_ty = cx.tcx.type_of(self_did);
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);
then {
if self.impling_types.is_none() {

View File

@ -197,7 +197,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplI
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Path(qpath) = &expr.node {
// 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;
}
@ -212,11 +212,11 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
let mut dereferenced_expr = expr;
let mut needs_check_adjustment = true;
loop {
let parent_id = cx.tcx.hir().get_parent_node(cur_expr.id);
if parent_id == cur_expr.id {
let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(cur_expr.hir_id);
if parent_id == cur_expr.hir_id {
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 {
ExprKind::AddrOf(..) => {
// `&e` => `e` must be referenced

View File

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

View File

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

View File

@ -6,7 +6,7 @@
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
use syntax::ast::{LitKind, NodeId};
use syntax::ast::LitKind;
use syntax_pos::symbol::Symbol;
/// **What it does:** Checks slow zero-filled vector initialization
@ -87,7 +87,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
len_expr: len_arg,
};
Self::search_initialization(cx, vi, expr.id);
Self::search_initialization(cx, vi, expr.hir_id);
}
}
}
@ -107,7 +107,7 @@ fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
len_expr: len_arg,
};
Self::search_initialization(cx, vi, stmt.id);
Self::search_initialization(cx, vi, stmt.hir_id);
}
}
}
@ -132,7 +132,7 @@ fn is_vec_with_capacity(expr: &Expr) -> Option<&Expr> {
}
/// 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);
if enclosing_body.is_none() {
@ -317,7 +317,7 @@ fn visit_block(&mut self, block: &'tcx Block) {
fn visit_expr(&mut self, expr: &'tcx Expr) {
// 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;
}

View File

@ -96,7 +96,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
) = e.node
{
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);
if let Some(p) = parent {
if let ExprKind::Assign(ref target, _) = p.node {

View File

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

View File

@ -225,7 +225,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
_ => None,
});
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);
then {
return true;
@ -246,7 +246,7 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
}
match hir_ty.node {
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);
if let Some(def_id) = opt_def_id(def) {
if Some(def_id) == cx.tcx.lang_items().owned_box() {
@ -375,7 +375,7 @@ enum if you need to distinguish all 3 cases",
fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt: &Lifetime, mut_ty: &MutTy) {
match mut_ty.ty.node {
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);
if_chain! {
if let Some(def_id) = opt_def_id(def);
@ -617,7 +617,7 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
}
if_chain! {
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 is_questionmark_desugar_marked_call(parent_expr);
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<'_>) {
// 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;
}
// The suggestion is to use a function call, so if the original expression

View File

@ -2,7 +2,7 @@
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_tool_lint, lint_array};
use syntax::ast::{LitKind, NodeId};
use syntax::ast::LitKind;
use syntax::source_map::Span;
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) {
if let ExprKind::Lit(ref lit) = expr.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
}
fn check_str(cx: &LateContext<'_, '_>, span: Span, id: NodeId) {
fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
let string = snippet(cx, span, "");
if string.contains('\u{200B}') {
span_help_and_lint(

View File

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

View File

@ -62,9 +62,9 @@ pub fn differing_macro_contexts(lhs: Span, rhs: Span) -> bool {
/// // Do something
/// }
/// ```
pub fn in_constant(cx: &LateContext<'_, '_>, id: NodeId) -> bool {
let parent_id = cx.tcx.hir().get_parent(id);
match cx.tcx.hir().get(parent_id) {
pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
let parent_id = cx.tcx.hir().get_parent_item(id);
match cx.tcx.hir().get_by_hir_id(parent_id) {
Node::Item(&Item {
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.
pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<Name> {
let parent_id = cx.tcx.hir().get_parent(expr.id);
match cx.tcx.hir().find(parent_id) {
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
match cx.tcx.hir().find_by_hir_id(parent_id) {
Some(Node::Item(&Item { ref ident, .. })) => Some(ident.name),
Some(Node::TraitItem(&TraitItem { ident, .. })) | Some(Node::ImplItem(&ImplItem { ident, .. })) => {
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.
pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> {
let map = &cx.tcx.hir();
let node_id: NodeId = e.id;
let parent_id: NodeId = map.get_parent_node(node_id);
if node_id == parent_id {
let hir_id = e.hir_id;
let parent_id = map.get_parent_node_by_hir_id(hir_id);
if hir_id == parent_id {
return None;
}
map.find(parent_id).and_then(|node| {
map.find_by_hir_id(parent_id).and_then(|node| {
if let Node::Expr(parent) = node {
Some(parent)
} 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 node_id = map.hir_to_node_id(node);
let enclosing_node = map
.get_enclosing_scope(node)
.get_enclosing_scope(node_id)
.and_then(|enclosing_id| map.find(enclosing_id));
if let Some(node) = enclosing_node {
match node {
@ -927,8 +928,9 @@ fn is_err(arm: &Arm) -> bool {
/// Returns true if the lint is allowed in the current context
///
/// Useful for skipping long running code when it's unnecessary
pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: NodeId) -> bool {
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> bool {
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> {
@ -1001,16 +1003,16 @@ pub fn without_block_comments(lines: Vec<&str>) -> Vec<&str> {
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 mut prev_enclosing_node = None;
let mut enclosing_node = 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;
}
prev_enclosing_node = Some(enclosing_node);
enclosing_node = map.get_parent(enclosing_node);
enclosing_node = map.get_parent_item(enclosing_node);
}
false
}

View File

@ -63,19 +63,19 @@ fn update(&mut self, cat: &'tcx Categorization<'_>) {
}
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 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 {
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)
}