Auto merge of #3854 - ljedrz:rustc_58992, r=phansch

Align with rust-lang/rust/#58992

Some adjustments needed after the most recent round of HirIdification.
This commit is contained in:
bors 2019-03-08 17:10:52 +00:00
commit bd6b5a1a36
11 changed files with 42 additions and 46 deletions

View File

@ -182,7 +182,7 @@ fn get_type_name(cx: &LateContext<'_, '_>, kind: &ty::TyKind<'_>) -> String {
fn compare_inputs(closure_inputs: &mut dyn Iterator<Item = &Arg>, call_args: &mut dyn Iterator<Item = &Expr>) -> bool {
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
if let PatKind::Binding(_, _, _, ident, _) = closure_input.pat.node {
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node {
// XXXManishearth Should I be checking the binding mode here?
if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.node {
if p.segments.len() != 1 {

View File

@ -8,7 +8,6 @@
use rustc::{declare_tool_lint, lint_array};
use rustc_data_structures::fx::FxHashSet;
use rustc_target::spec::abi::Abi;
use syntax::ast;
use syntax::source_map::Span;
declare_clippy_lint! {
@ -278,8 +277,8 @@ fn check_raw_ptr(
}
}
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<ast::NodeId> {
if let (&hir::PatKind::Binding(_, id, _, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::HirId> {
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
Some(id)
} else {
None
@ -288,7 +287,7 @@ fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<ast::NodeId> {
struct DerefVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
ptrs: FxHashSet<ast::NodeId>,
ptrs: FxHashSet<hir::HirId>,
tables: &'a ty::TypeckTables<'tcx>,
}
@ -329,7 +328,7 @@ impl<'a, 'tcx: 'a> DerefVisitor<'a, 'tcx> {
fn check_arg(&self, ptr: &hir::Expr) {
if let hir::ExprKind::Path(ref qpath) = ptr.node {
if let Def::Local(id) = self.cx.tables.qpath_def(qpath, ptr.hir_id) {
if self.ptrs.contains(&id) {
if self.ptrs.contains(&self.cx.tcx.hir().node_to_hir_id(id)) {
span_lint(
self.cx,
NOT_UNSAFE_PTR_ARG_DEREF,

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;
declare_clippy_lint! {
/// **What it does:** Checks for variable declarations immediately followed by a
@ -73,7 +72,7 @@ fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
if_chain! {
if let Some(expr) = it.peek();
if let hir::StmtKind::Local(ref local) = stmt.node;
if let hir::PatKind::Binding(mode, canonical_id, _, ident, None) = local.pat.node;
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
if let hir::StmtKind::Expr(ref if_) = expr.node;
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
if !used_in_expr(cx, canonical_id, cond);
@ -142,7 +141,7 @@ fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
struct UsedVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
id: ast::NodeId,
id: hir::HirId,
used: bool,
}
@ -151,7 +150,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
if_chain! {
if let hir::ExprKind::Path(ref qpath) = expr.node;
if let Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id);
if self.id == local_id;
if self.id == self.cx.tcx.hir().node_to_hir_id(local_id);
then {
self.used = true;
return;
@ -166,7 +165,7 @@ fn nested_visit_map<'this>(&'this mut self) -> hir::intravisit::NestedVisitorMap
fn check_assign<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
decl: ast::NodeId,
decl: hir::HirId,
block: &'tcx hir::Block,
) -> Option<&'tcx hir::Expr> {
if_chain! {
@ -176,7 +175,7 @@ fn check_assign<'a, 'tcx>(
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
if let hir::ExprKind::Path(ref qpath) = var.node;
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);
if decl == local_id;
if decl == cx.tcx.hir().node_to_hir_id(local_id);
then {
let mut v = UsedVisitor {
cx,
@ -199,7 +198,7 @@ fn check_assign<'a, 'tcx>(
None
}
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: ast::NodeId, expr: &'tcx hir::Expr) -> bool {
fn used_in_expr<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr) -> bool {
let mut v = UsedVisitor { cx, id, used: false };
hir::intravisit::walk_expr(&mut v, expr);
v.used

View File

@ -272,7 +272,7 @@ macro_rules! declare_clippy_lint {
pub use crate::utils::conf::Conf;
mod reexport {
crate use syntax::ast::{Name, NodeId};
crate use syntax::ast::Name;
}
/// Register all pre expansion lints

View File

@ -486,8 +486,7 @@ 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, _, _) => {
let node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id);
match never_loop_block(block, node_id) {
match never_loop_block(block, expr.hir_id) {
NeverLoopResult::AlwaysBreak => {
span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
},
@ -664,7 +663,7 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult
}
}
fn never_loop_block(block: &Block, main_loop_id: NodeId) -> NeverLoopResult {
fn never_loop_block(block: &Block, main_loop_id: HirId) -> NeverLoopResult {
let stmts = block.stmts.iter().map(stmt_to_expr);
let expr = once(block.expr.as_ref().map(|p| &**p));
let mut iter = stmts.chain(expr).filter_map(|e| e);
@ -679,7 +678,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
}
}
fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult {
fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
match expr.node {
ExprKind::Box(ref e)
| ExprKind::Unary(_, ref e)
@ -753,17 +752,17 @@ fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult {
}
}
fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: NodeId) -> NeverLoopResult {
fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
es.map(|e| never_loop_expr(e, main_loop_id))
.fold(NeverLoopResult::Otherwise, combine_seq)
}
fn never_loop_expr_all<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: NodeId) -> NeverLoopResult {
fn never_loop_expr_all<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
es.map(|e| never_loop_expr(e, main_loop_id))
.fold(NeverLoopResult::Otherwise, combine_both)
}
fn never_loop_expr_branch<'a, T: Iterator<Item = &'a Expr>>(e: &mut T, main_loop_id: NodeId) -> NeverLoopResult {
fn never_loop_expr_branch<'a, T: Iterator<Item = &'a Expr>>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult {
e.map(|e| never_loop_expr(e, main_loop_id))
.fold(NeverLoopResult::AlwaysBreak, combine_branches)
}
@ -784,14 +783,14 @@ fn check_for_loop<'a, 'tcx>(
detect_manual_memcpy(cx, pat, arg, body, expr);
}
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: ast::NodeId) -> bool {
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bool {
if_chain! {
if let ExprKind::Path(ref qpath) = expr.node;
if let QPath::Resolved(None, ref path) = *qpath;
if path.segments.len() == 1;
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, expr.hir_id);
// our variable!
if local_id == var;
if cx.tcx.hir().node_to_hir_id(local_id) == var;
then {
return true;
}
@ -833,8 +832,8 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
is_slice || match_type(cx, ty, &paths::VEC) || match_type(cx, ty, &paths::VEC_DEQUE)
}
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: ast::NodeId) -> Option<FixedOffsetVar> {
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: ast::NodeId) -> Option<String> {
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> Option<FixedOffsetVar> {
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: HirId) -> Option<String> {
match e.node {
ExprKind::Lit(ref l) => match l.node {
ast::LitKind::Int(x, _ty) => Some(x.to_string()),
@ -889,7 +888,7 @@ fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: ast::Node
fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
expr: &Expr,
var: ast::NodeId,
var: HirId,
) -> Option<FixedOffsetVar> {
if_chain! {
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node;
@ -907,12 +906,12 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
fn get_indexed_assignments<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
body: &Expr,
var: ast::NodeId,
var: HirId,
) -> Vec<(FixedOffsetVar, FixedOffsetVar)> {
fn get_assignment<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
e: &Expr,
var: ast::NodeId,
var: HirId,
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
if let ExprKind::Assign(ref lhs, ref rhs) = e.node {
match (
@ -970,7 +969,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
}) = higher::range(cx, arg)
{
// the var must be a single name
if let PatKind::Binding(_, canonical_id, _, _, _) = pat.node {
if let PatKind::Binding(_, canonical_id, _, _) = pat.node {
let print_sum = |arg1: &Offset, arg2: &Offset| -> String {
match (&arg1.value[..], arg1.negate, &arg2.value[..], arg2.negate) {
("0", _, "0", _) => "".into(),
@ -1087,7 +1086,7 @@ fn check_for_loop_range<'a, 'tcx>(
}) = higher::range(cx, arg)
{
// the var must be a single name
if let PatKind::Binding(_, canonical_id, _, ident, _) = pat.node {
if let PatKind::Binding(_, canonical_id, ident, _) = pat.node {
let mut visitor = VarVisitor {
cx,
var: canonical_id,
@ -1711,7 +1710,7 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
struct LocalUsedVisitor<'a, 'tcx: 'a> {
cx: &'a LateContext<'a, 'tcx>,
local: ast::NodeId,
local: HirId,
used: bool,
}
@ -1733,7 +1732,7 @@ struct VarVisitor<'a, 'tcx: 'a> {
/// context reference
cx: &'a LateContext<'a, 'tcx>,
/// var name to look for as index
var: ast::NodeId,
var: HirId,
/// indexed variables that are used mutably
indexed_mut: FxHashSet<Name>,
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
@ -1841,7 +1840,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
then {
match self.cx.tables.qpath_def(qpath, expr.hir_id) {
Def::Upvar(local_id, ..) => {
if local_id == self.var {
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
// we are not indexing anything, record that
self.nonindex = true;
}
@ -1849,7 +1848,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
Def::Local(local_id) =>
{
if local_id == self.var {
if self.cx.tcx.hir().node_to_hir_id(local_id) == self.var {
self.nonindex = true;
} else {
// not the correct variable, but still a variable

View File

@ -482,7 +482,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
for pat in &arm.pats {
if let PatKind::Wild = pat.node {
wildcard_span = Some(pat.span);
} else if let PatKind::Binding(_, _, _, ident, None) = pat.node {
} else if let PatKind::Binding(_, _, ident, None) = pat.node {
wildcard_span = Some(pat.span);
wildcard_ident = Some(ident);
}

View File

@ -115,7 +115,7 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, it: &'tcx hir::Item) {
// trait method with default body needs inline in case
// an impl is not provided
let desc = "a default trait method";
let item = cx.tcx.hir().expect_trait_item_by_hir_id(tit.id.hir_id);
let item = cx.tcx.hir().expect_trait_item(tit.id.hir_id);
check_missing_inline_attrs(cx, &item.attrs, item.span, desc);
}
},

View File

@ -209,7 +209,7 @@ fn check_fn(
if !implements_borrow_trait;
if !all_borrowable_trait;
if let PatKind::Binding(mode, _, canonical_id, ..) = arg.pat.node;
if let PatKind::Binding(mode, canonical_id, ..) = arg.pat.node;
if !moved_vars.contains(&canonical_id);
then {
if mode == BindingAnnotation::Mutable || mode == BindingAnnotation::RefMut {

View File

@ -50,7 +50,7 @@ fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
};
match expr.node {
hir::ExprKind::Match(ref res, _, _) if is_try(expr).is_some() => {
hir::ExprKind::Match(ref res, _, _) if is_try(cx, expr).is_some() => {
if let hir::ExprKind::Call(ref func, ref args) = res.node {
if let hir::ExprKind::Path(ref path) = func.node {
if match_qpath(path, &paths::TRY_INTO_RESULT) && args.len() == 1 {

View File

@ -164,8 +164,7 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
output: &mut self.registered_lints,
cx,
};
let node_id = cx.tcx.hir().hir_to_node_id(impl_item_refs[0].id.hir_id);
let body_id = cx.tcx.hir().body_owned_by(node_id);
let body_id = cx.tcx.hir().body_owned_by(impl_item_refs[0].id.hir_id);
collector.visit_expr(&cx.tcx.hir().body(body_id).value);
}
}

View File

@ -829,15 +829,15 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<I
/// Check if a given expression is a match expression
/// expanded from `?` operator or `try` macro.
pub fn is_try(expr: &Expr) -> Option<&Expr> {
fn is_ok(arm: &Arm) -> bool {
pub fn is_try<'a>(cx: &'_ LateContext<'_, '_>, expr: &'a Expr) -> Option<&'a Expr> {
fn is_ok(cx: &'_ LateContext<'_, '_>, arm: &Arm) -> bool {
if_chain! {
if let PatKind::TupleStruct(ref path, ref pat, None) = arm.pats[0].node;
if match_qpath(path, &paths::RESULT_OK[1..]);
if let PatKind::Binding(_, defid, _, _, None) = pat[0].node;
if let PatKind::Binding(_, hir_id, _, None) = pat[0].node;
if let ExprKind::Path(QPath::Resolved(None, ref path)) = arm.body.node;
if let Def::Local(lid) = path.def;
if lid == defid;
if cx.tcx.hir().node_to_hir_id(lid) == hir_id;
then {
return true;
}
@ -863,8 +863,8 @@ fn is_err(arm: &Arm) -> bool {
if arms.len() == 2;
if arms[0].pats.len() == 1 && arms[0].guard.is_none();
if arms[1].pats.len() == 1 && arms[1].guard.is_none();
if (is_ok(&arms[0]) && is_err(&arms[1])) ||
(is_ok(&arms[1]) && is_err(&arms[0]));
if (is_ok(cx, &arms[0]) && is_err(&arms[1])) ||
(is_ok(cx, &arms[1]) && is_err(&arms[0]));
then {
return Some(expr);
}