Auto merge of #4061 - rust-lang:rustup, r=phansch

Rustup to rustc 1.36.0-nightly (13fde05b1 2019-05-03)

Trying to deal with changes from https://github.com/rust-lang/rust/pull/60462

Moved from https://github.com/rust-lang/rust-clippy/pull/4060 so everyone can collab on the rustup branch.
This commit is contained in:
bors 2019-05-04 08:17:03 +00:00
commit fc96aa0368
39 changed files with 121 additions and 117 deletions

View file

@ -99,7 +99,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
let parent_fn = cx.tcx.hir().get_parent_item(e.hir_id);
if_chain! {
if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn);
if trait_ref.path.def.def_id() == trait_id;
if trait_ref.path.res.def_id() == trait_id;
then { return; }
}
implements_trait($cx, $ty, trait_id, &[$rty])

View file

@ -394,7 +394,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
ExprKind::Call(path_expr, _) => {
if let ExprKind::Path(qpath) = &path_expr.node {
if let Some(fun_id) = tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
!cx.match_def_path(fun_id, &paths::BEGIN_PANIC)
} else {
true

View file

@ -2,7 +2,7 @@
use crate::utils::{clip, sext, unsext};
use if_chain::if_chain;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::*;
use rustc::lint::LateContext;
use rustc::ty::subst::{Subst, SubstsRef};
@ -247,8 +247,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
if_chain! {
if args.is_empty();
if let ExprKind::Path(qpath) = &callee.node;
let def = self.tables.qpath_def(qpath, callee.hir_id);
if let Some(def_id) = def.opt_def_id();
let res = self.tables.qpath_res(qpath, callee.hir_id);
if let Some(def_id) = res.opt_def_id();
let def_path = self.lcx.get_def_path(def_id)
.iter()
.map(LocalInternedString::get)
@ -322,9 +322,9 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
fn fetch_path(&mut self, qpath: &QPath, id: HirId) -> Option<Constant> {
use rustc::mir::interpret::GlobalId;
let def = self.tables.qpath_def(qpath, id);
match def {
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
let res = self.tables.qpath_res(qpath, id);
match res {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssociatedConst, def_id) => {
let substs = self.tables.node_substs(id);
let substs = if self.substs.is_empty() {
substs
@ -338,11 +338,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
};
let result = self.lcx.tcx.const_eval(self.param_env.and(gid)).ok()?;
let ret = miri_to_const(self.lcx.tcx, &result);
if ret.is_some() {
let result = miri_to_const(self.lcx.tcx, &result);
if result.is_some() {
self.needed_resolution = true;
}
ret
result
},
// FIXME: cover all usable cases.
_ => None,

View file

@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
if let ExprKind::Call(ref path, ..) = expr.node;
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
if let ExprKind::Path(ref qpath) = path.node;
if let Some(def_id) = cx.tables.qpath_def(qpath, path.hir_id).opt_def_id();
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
if cx.match_def_path(def_id, &paths::DEFAULT_TRAIT_METHOD);
then {
match qpath {

View file

@ -55,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropBounds {
fn lint_bound<'a, 'tcx>(cx: &rustc::lint::LateContext<'a, 'tcx>, bound: &'tcx GenericBound) {
if_chain! {
if let GenericBound::Trait(t, _) = bound;
if let Some(def_id) = t.trait_ref.path.def.opt_def_id();
if let Some(def_id) = t.trait_ref.path.res.opt_def_id();
if cx.match_def_path(def_id, &paths::DROP_TRAIT);
then {
span_lint(

View file

@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
if let ExprKind::Call(ref path, ref args) = expr.node;
if let ExprKind::Path(ref qpath) = path.node;
if args.len() == 1;
if let Some(def_id) = cx.tables.qpath_def(qpath, path.hir_id).opt_def_id();
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
then {
let lint;
let msg;

View file

@ -1,7 +1,7 @@
//! lint on `use`ing all variants of an enum
use crate::utils::span_lint;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -43,7 +43,7 @@ impl EnumGlobUse {
return; // re-exports are fine
}
if let ItemKind::Use(ref path, UseKind::Glob) = item.node {
if let Def::Enum(_) = path.def {
if let Res::Def(DefKind::Enum, _) = path.res {
span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants");
}
}

View file

@ -63,7 +63,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
if let ExprKind::Path(ref qpath) = lhs.node {
if let QPath::Resolved(_, ref path) = *qpath {
if path.segments.len() == 1 {
if let def::Def::Local(var) = cx.tables.qpath_def(qpath, lhs.hir_id) {
if let def::Res::Local(var) = cx.tables.qpath_res(qpath, lhs.hir_id) {
let mut visitor = ReadVisitor {
cx,
var,
@ -295,7 +295,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
if_chain! {
if let QPath::Resolved(None, ref path) = *qpath;
if path.segments.len() == 1;
if let def::Def::Local(local_id) = self.cx.tables.qpath_def(qpath, expr.hir_id);
if let def::Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id);
if local_id == self.var;
// Check that this is a read, not a write.
if !is_in_assignment_position(self.cx, expr);

View file

@ -61,7 +61,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
if_chain! {
if let ExprKind::Call(ref func_expr, _) = expr.node;
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.node;
if let Some(path_def_id) = path.def.opt_def_id();
if let Some(path_def_id) = path.res.opt_def_id();
if self.lcx.match_def_path(path_def_id, &BEGIN_PANIC) ||
self.lcx.match_def_path(path_def_id, &BEGIN_PANIC_FMT);
if is_expn_of(expr.span, "unreachable").is_none();

View file

@ -3,7 +3,7 @@ use std::convert::TryFrom;
use crate::utils::{iter_input_pats, snippet, snippet_opt, span_lint, type_is_unsafe_function};
use matches::matches;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::Res;
use rustc::hir::intravisit;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty;
@ -333,7 +333,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
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 let Res::Local(id) = self.cx.tables.qpath_res(qpath, ptr.hir_id) {
if self.ptrs.contains(&id) {
span_lint(
self.cx,

View file

@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef {
if let ExprKind::Path(ref qpath) = path.node;
if args.len() == 0;
if let ty::Ref(..) = cx.tables.expr_ty(expr).sty;
if let Some(def_id) = cx.tables.qpath_def(qpath, path.hir_id).opt_def_id();
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
then {
let msg = if cx.match_def_path(def_id, &paths::MEM_ZEROED) |
cx.match_def_path(def_id, &paths::INIT)

View file

@ -1,7 +1,7 @@
use crate::utils::{snippet, span_lint_and_then};
use if_chain::if_chain;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::Res;
use rustc::hir::BindingAnnotation;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -145,7 +145,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
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 let Res::Local(local_id) = self.cx.tables.qpath_res(qpath, expr.hir_id);
if self.id == local_id;
then {
self.used = true;
@ -170,7 +170,7 @@ fn check_assign<'a, 'tcx>(
if let hir::StmtKind::Semi(ref expr) = expr.node;
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 let Res::Local(local_id) = cx.tables.qpath_res(qpath, var.hir_id);
if decl == local_id;
then {
let mut v = UsedVisitor {

View file

@ -1,5 +1,5 @@
use matches::matches;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::intravisit::*;
use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
@ -310,14 +310,14 @@ impl<'v, 't> RefVisitor<'v, 't> {
})
{
let hir_id = ty.hir_id;
match self.cx.tables.qpath_def(qpath, hir_id) {
Def::TyAlias(def_id) | Def::Struct(def_id) => {
match self.cx.tables.qpath_res(qpath, hir_id) {
Res::Def(DefKind::TyAlias, def_id) | Res::Def(DefKind::Struct, def_id) => {
let generics = self.cx.tcx.generics_of(def_id);
for _ in generics.params.as_slice() {
self.record(&None);
}
},
Def::Trait(def_id) => {
Res::Def(DefKind::Trait, def_id) => {
let trait_def = self.cx.tcx.trait_def(def_id);
for _ in &self.cx.tcx.generics_of(trait_def.def_id).params {
self.record(&None);

View file

@ -1,7 +1,7 @@
use crate::reexport::*;
use if_chain::if_chain;
use itertools::Itertools;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::def_id;
use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
use rustc::hir::*;
@ -778,7 +778,7 @@ fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bo
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);
if let Res::Local(local_id) = cx.tables.qpath_res(qpath, expr.hir_id);
// our variable!
if local_id == var;
then {
@ -1637,8 +1637,8 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
if let ExprKind::Path(ref qpath) = bound.node;
if let QPath::Resolved(None, _) = *qpath;
then {
let def = cx.tables.qpath_def(qpath, bound.hir_id);
if let Def::Local(node_id) = def {
let res = cx.tables.qpath_res(qpath, bound.hir_id);
if let Res::Local(node_id) = res {
let node_str = cx.tcx.hir().get_by_hir_id(node_id);
if_chain! {
if let Node::Binding(pat) = node_str;
@ -1772,9 +1772,9 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
if self.prefer_mutable {
self.indexed_mut.insert(seqvar.segments[0].ident.name);
}
let def = self.cx.tables.qpath_def(seqpath, seqexpr.hir_id);
match def {
Def::Local(hir_id) | Def::Upvar(hir_id, ..) => {
let res = self.cx.tables.qpath_res(seqpath, seqexpr.hir_id);
match res {
Res::Local(hir_id) | Res::Upvar(hir_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);
@ -1789,7 +1789,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
}
return false; // no need to walk further *on the variable*
}
Def::Static(..) | Def::Const(..) => {
Res::Def(DefKind::Static, ..) | Res::Def(DefKind::Const, ..) => {
if indexed_indirectly {
self.indexed_indirectly.insert(seqvar.segments[0].ident.name, None);
}
@ -1834,14 +1834,14 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
if let QPath::Resolved(None, ref path) = *qpath;
if path.segments.len() == 1;
then {
match self.cx.tables.qpath_def(qpath, expr.hir_id) {
Def::Upvar(local_id, ..) => {
match self.cx.tables.qpath_res(qpath, expr.hir_id) {
Res::Upvar(local_id, ..) => {
if local_id == self.var {
// we are not indexing anything, record that
self.nonindex = true;
}
}
Def::Local(local_id) =>
Res::Local(local_id) =>
{
if local_id == self.var {
@ -2187,8 +2187,8 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
if let ExprKind::Path(ref qpath) = expr.node {
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
if let Def::Local(node_id) = path_res {
let path_res = cx.tables.qpath_res(qpath, expr.hir_id);
if let Res::Local(node_id) = path_res {
return Some(node_id);
}
}
@ -2380,13 +2380,13 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
if_chain! {
if let ExprKind::Path(ref qpath) = ex.node;
if let QPath::Resolved(None, _) = *qpath;
let def = self.cx.tables.qpath_def(qpath, ex.hir_id);
let res = self.cx.tables.qpath_res(qpath, ex.hir_id);
then {
match def {
Def::Local(node_id) | Def::Upvar(node_id, ..) => {
match res {
Res::Local(node_id) | Res::Upvar(node_id, ..) => {
self.ids.insert(node_id);
},
Def::Static(def_id) => {
Res::Def(DefKind::Static, def_id) => {
let mutable = self.cx.tcx.is_mutable_static(def_id);
self.def_ids.insert(def_id, mutable);
},

View file

@ -505,11 +505,11 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
for pat in &arm.pats {
if let PatKind::Path(ref path) = pat.deref().node {
if let QPath::Resolved(_, p) = path {
missing_variants.retain(|e| e.ctor_def_id != Some(p.def.def_id()));
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
}
} else if let PatKind::TupleStruct(ref path, ..) = pat.deref().node {
if let QPath::Resolved(_, p) = path {
missing_variants.retain(|e| e.ctor_def_id != Some(p.def.def_id()));
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
}
}
}

View file

@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
if let ExprKind::Call(ref func, ref func_args) = expr.node;
// is `mem::discriminant`
if let ExprKind::Path(ref func_qpath) = func.node;
if let Some(def_id) = cx.tables.qpath_def(func_qpath, func.hir_id).opt_def_id();
if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id();
if cx.match_def_path(def_id, &paths::MEM_DISCRIMINANT);
// type is non-enum
let ty_param = cx.tables.node_substs(func.hir_id).type_at(0);

View file

@ -27,7 +27,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Call(ref path_expr, ref args) = e.node {
if let ExprKind::Path(ref qpath) = path_expr.node {
if let Some(def_id) = cx.tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
if let Some(def_id) = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
if cx.match_def_path(def_id, &paths::MEM_FORGET) {
let forgot_ty = cx.tables.expr_ty(&args[0]);

View file

@ -41,7 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
if let ExprKind::Call(ref func, ref func_args) = expr.node;
if func_args.len() == 2;
if let ExprKind::Path(ref func_qpath) = func.node;
if let Some(def_id) = cx.tables.qpath_def(func_qpath, func.hir_id).opt_def_id();
if let Some(def_id) = cx.tables.qpath_res(func_qpath, func.hir_id).opt_def_id();
if cx.match_def_path(def_id, &paths::MEM_REPLACE);
// Check that second argument is `Option::None`

View file

@ -8,7 +8,7 @@ use std::iter;
use if_chain::if_chain;
use matches::matches;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass};
use rustc::ty::{self, Predicate, Ty};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -1504,7 +1504,7 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, new: &hir::Ex
if let hir::ExprKind::Call(ref fun, ref args) = new.node;
if args.len() == 1;
if let hir::ExprKind::Path(ref path) = fun.node;
if let Def::Method(did) = cx.tables.qpath_def(path, fun.hir_id);
if let Res::Def(DefKind::Method, did) = cx.tables.qpath_res(path, fun.hir_id);
if cx.match_def_path(did, &paths::CSTRING_NEW);
then {
span_lint_and_then(

View file

@ -2,7 +2,7 @@ use crate::utils::paths;
use crate::utils::usage::mutated_variables;
use crate::utils::{match_qpath, match_trait_method, span_lint};
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::Res;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::LateContext;
@ -66,7 +66,7 @@ fn check_expression<'a, 'tcx: 'a>(
if match_qpath(path, &paths::OPTION_SOME) {
if_chain! {
if let hir::ExprKind::Path(path) = &args[0].node;
if let Def::Local(ref local) = cx.tables.qpath_def(path, args[0].hir_id);
if let Res::Local(ref local) = cx.tables.qpath_res(path, args[0].hir_id);
then {
if arg_id == *local {
return (false, false)

View file

@ -62,7 +62,7 @@ enum MinMax {
fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> {
if let ExprKind::Call(ref path, ref args) = expr.node {
if let ExprKind::Path(ref qpath) = path.node {
cx.tables.qpath_def(qpath, path.hir_id).opt_def_id().and_then(|def_id| {
cx.tables.qpath_res(qpath, path.hir_id).opt_def_id().and_then(|def_id| {
if cx.match_def_path(def_id, &paths::CMP_MIN) {
fetch_const(cx, args, MinMax::Min)
} else if cx.match_def_path(def_id, &paths::CMP_MAX) {

View file

@ -410,7 +410,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
binding != "_result" && // FIXME: #944
is_used(cx, expr) &&
// don't lint if the declaration is in a macro
non_macro_local(cx, &cx.tables.qpath_def(qpath, expr.hir_id))
non_macro_local(cx, cx.tables.qpath_res(qpath, expr.hir_id))
{
Some(binding)
} else {
@ -599,10 +599,10 @@ fn in_attributes_expansion(expr: &Expr) -> bool {
.map_or(false, |info| matches!(info.format, ExpnFormat::MacroAttribute(_)))
}
/// Tests whether `def` is a variable defined outside a macro.
fn non_macro_local(cx: &LateContext<'_, '_>, def: &def::Def) -> bool {
match *def {
def::Def::Local(id) | def::Def::Upvar(id, _, _) => !in_macro(cx.tcx.hir().span_by_hir_id(id)),
/// Tests whether `res` is a variable defined outside a macro.
fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
match res {
def::Res::Local(id) | def::Res::Upvar(id, ..) => !in_macro(cx.tcx.hir().span_by_hir_id(id)),
_ => false,
}
}

View file

@ -1,5 +1,5 @@
use crate::utils::{has_drop, in_macro, snippet_opt, span_lint, span_lint_and_sugg};
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -70,9 +70,9 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
},
ExprKind::Call(ref callee, ref args) => {
if let ExprKind::Path(ref qpath) = callee.node {
let def = cx.tables.qpath_def(qpath, callee.hir_id);
match def {
Def::Struct(..) | Def::Variant(..) | Def::Ctor(..) => {
let res = cx.tables.qpath_res(qpath, callee.hir_id);
match res {
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _) => {
!has_drop(cx, cx.tables.expr_ty(expr)) && args.iter().all(|arg| has_no_effect(cx, arg))
},
_ => false,
@ -153,9 +153,11 @@ fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec
},
ExprKind::Call(ref callee, ref args) => {
if let ExprKind::Path(ref qpath) = callee.node {
let def = cx.tables.qpath_def(qpath, callee.hir_id);
match def {
Def::Struct(..) | Def::Variant(..) | Def::Ctor(..) if !has_drop(cx, cx.tables.expr_ty(expr)) => {
let res = cx.tables.qpath_res(qpath, callee.hir_id);
match res {
Res::Def(DefKind::Struct, ..) | Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
if !has_drop(cx, cx.tables.expr_ty(expr)) =>
{
Some(args.iter().collect())
},
_ => None,

View file

@ -4,7 +4,7 @@
use std::ptr;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::ty::adjustment::Adjust;
@ -194,8 +194,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
}
// Make sure it is a const item.
match cx.tables.qpath_def(qpath, expr.hir_id) {
Def::Const(_) | Def::AssociatedConst(_) => {},
match cx.tables.qpath_res(qpath, expr.hir_id) {
Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssociatedConst, _) => {},
_ => return,
};

View file

@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;
if !is_automatically_derived(&*item.attrs);
if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
if trait_ref.path.def.def_id() == eq_trait;
if trait_ref.path.res.def_id() == eq_trait;
then {
for impl_item in impl_items {
if impl_item.ident.name == "ne" {

View file

@ -1,5 +1,5 @@
use if_chain::if_chain;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -117,7 +117,9 @@ impl QuestionMark {
},
ExprKind::Ret(Some(ref expr)) => Self::expression_returns_none(cx, expr),
ExprKind::Path(ref qp) => {
if let Def::Ctor(def_id, def::CtorOf::Variant, _) = cx.tables.qpath_def(qp, expression.hir_id) {
if let Res::Def(DefKind::Ctor(def::CtorOf::Variant, def::CtorKind::Const), def_id) =
cx.tables.qpath_res(qp, expression.hir_id)
{
return cx.match_def_path(def_id, &OPTION_NONE);
}

View file

@ -110,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
if let ExprKind::Call(ref fun, ref args) = expr.node;
if let ExprKind::Path(ref qpath) = fun.node;
if args.len() == 1;
if let Some(def_id) = cx.tables.qpath_def(qpath, fun.hir_id).opt_def_id();
if let Some(def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id();
then {
if cx.match_def_path(def_id, &paths::REGEX_NEW) ||
cx.match_def_path(def_id, &paths::REGEX_BUILDER_NEW) {

View file

@ -1,7 +1,7 @@
use crate::utils::span_lint_and_sugg;
use if_chain::if_chain;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
@ -35,7 +35,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if_chain! {
if let hir::ExprKind::Path(ref qp) = expr.node;
if let Def::Const(def_id) = cx.tables.qpath_def(qp, expr.hir_id);
if let Res::Def(DefKind::Const, def_id) = cx.tables.qpath_res(qp, expr.hir_id);
then {
for &(const_path, repl_snip) in REPLACEMENTS {
if cx.match_def_path(def_id, const_path) {

View file

@ -23,7 +23,7 @@ declare_lint_pass!(SerdeAPI => [SERDE_API_MISUSE]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SerdeAPI {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref items) = item.node {
let did = trait_ref.path.def.def_id();
let did = trait_ref.path.res.def_id();
if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) {
if did == visit_did {
let mut seen_str = None;

View file

@ -169,7 +169,7 @@ fn check_binop<'a>(
if_chain! {
if let Some(trait_ref) = trait_ref_of_method(cx, parent_fn);
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.res.def_id());
if binop != expected_ops[idx];
then{
return Some(traits[idx])

View file

@ -1,6 +1,6 @@
use crate::utils::is_adjusted;
use crate::utils::span_lint;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::{Expr, ExprKind};
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
@ -27,7 +27,7 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
match &expr.node {
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
ExprKind::Path(qpath) => {
if let Def::Const(..) = cx.tables.qpath_def(qpath, expr.hir_id) {
if let Res::Def(DefKind::Const, ..) = cx.tables.qpath_res(qpath, expr.hir_id) {
true
} else {
false

View file

@ -220,7 +220,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Call(ref path_expr, ref args) = e.node {
if let ExprKind::Path(ref qpath) = path_expr.node {
if let Some(def_id) = cx.tables.qpath_def(qpath, path_expr.hir_id).opt_def_id() {
if let Some(def_id) = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
if cx.match_def_path(def_id, &paths::TRANSMUTE) {
let from_ty = cx.tables.expr_ty(&args[0]);
let to_ty = cx.tables.expr_ty(e);

View file

@ -216,7 +216,7 @@ fn match_type_parameter(cx: &LateContext<'_, '_>, qpath: &QPath, path: &[&str])
_ => None,
});
if let TyKind::Path(ref qpath) = ty.node;
if let Some(did) = cx.tables.qpath_def(qpath, ty.hir_id).opt_def_id();
if let Some(did) = cx.tables.qpath_res(qpath, ty.hir_id).opt_def_id();
if cx.match_def_path(did, path);
then {
return true;
@ -238,8 +238,8 @@ 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 = hir_ty.hir_id;
let def = cx.tables.qpath_def(qpath, hir_id);
if let Some(def_id) = def.opt_def_id() {
let res = cx.tables.qpath_res(qpath, hir_id);
if let Some(def_id) = res.opt_def_id() {
if Some(def_id) == cx.tcx.lang_items().owned_box() {
if match_type_parameter(cx, qpath, &paths::VEC) {
span_help_and_lint(
@ -261,8 +261,8 @@ fn check_ty(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool) {
});
// ty is now _ at this point
if let TyKind::Path(ref ty_qpath) = ty.node;
let def = cx.tables.qpath_def(ty_qpath, ty.hir_id);
if let Some(def_id) = def.opt_def_id();
let res = cx.tables.qpath_res(ty_qpath, ty.hir_id);
if let Some(def_id) = res.opt_def_id();
if Some(def_id) == cx.tcx.lang_items().owned_box();
// At this point, we know ty is Box<T>, now get T
if let Some(ref last) = last_path_segment(ty_qpath).args;
@ -367,7 +367,7 @@ fn check_ty_rptr(cx: &LateContext<'_, '_>, hir_ty: &hir::Ty, is_local: bool, lt:
match mut_ty.ty.node {
TyKind::Path(ref qpath) => {
let hir_id = mut_ty.ty.hir_id;
let def = cx.tables.qpath_def(qpath, hir_id);
let def = cx.tables.qpath_res(qpath, hir_id);
if_chain! {
if let Some(def_id) = def.opt_def_id();
if Some(def_id) == cx.tcx.lang_items().owned_box();

View file

@ -144,7 +144,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
if ["unwrap", "unwrap_err"].contains(&&*method_name.ident.as_str());
let call_to_unwrap = method_name.ident.name == "unwrap";
if let Some(unwrappable) = self.unwrappables.iter()
.find(|u| u.ident.def == path.def);
.find(|u| u.ident.res == path.res);
then {
if call_to_unwrap == unwrappable.safe_to_unwrap {
span_lint_and_then(

View file

@ -1,6 +1,6 @@
use if_chain::if_chain;
use rustc::hir;
use rustc::hir::def::{CtorKind, Def};
use rustc::hir::def::{CtorKind, DefKind, Res};
use rustc::hir::intravisit::{walk_item, walk_path, walk_ty, NestedVisitorMap, Visitor};
use rustc::hir::*;
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
@ -86,7 +86,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TraitImplTyVisitor<'a, 'tcx> {
if impl_ty != trait_ty {
if let Some(impl_ty) = impl_ty {
if self.item_type == impl_ty {
let is_self_ty = if let def::Def::SelfTy(..) = path.def {
let is_self_ty = if let def::Res::SelfTy(..) = path.res {
true
} else {
false
@ -221,10 +221,10 @@ struct UseSelfVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> Visitor<'tcx> for UseSelfVisitor<'a, 'tcx> {
fn visit_path(&mut self, path: &'tcx Path, _id: HirId) {
if path.segments.last().expect(SEGMENTS_MSG).ident.name != SelfUpper.name() {
if self.item_path.def == path.def {
if self.item_path.res == path.res {
span_use_self_lint(self.cx, path);
} else if let Def::Ctor(ctor_did, def::CtorOf::Struct, CtorKind::Fn) = path.def {
if self.item_path.def.opt_def_id() == self.cx.tcx.parent(ctor_did) {
} else if let Res::Def(DefKind::Ctor(def::CtorOf::Struct, CtorKind::Fn), ctor_did) = path.res {
if self.item_path.res.opt_def_id() == self.cx.tcx.parent(ctor_did) {
span_use_self_lint(self.cx, path);
}
}

View file

@ -634,7 +634,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
self.hash_name(path.ident.name);
},
}
// self.cx.tables.qpath_def(p, id).hash(&mut self.s);
// self.cx.tables.qpath_res(p, id).hash(&mut self.s);
}
pub fn hash_path(&mut self, p: &Path) {

View file

@ -1,7 +1,7 @@
use crate::utils::{match_type, paths, span_help_and_lint, span_lint, walk_ptrs_ty};
use if_chain::if_chain;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::hir::*;
use rustc::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintPass};
@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
} else if let hir::ItemKind::Impl(.., Some(ref trait_ref), _, ref impl_item_refs) = item.node {
if_chain! {
if let hir::TraitRef{path, ..} = trait_ref;
if let Def::Trait(def_id) = path.def;
if let Res::Def(DefKind::Trait, def_id) = path.res;
if cx.match_def_path(def_id, &paths::LINT_PASS);
then {
let mut collector = LintCollector {
@ -178,7 +178,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty) -> bool {
) = ty.node
{
if let TyKind::Path(ref path) = inner.node {
if let Def::Struct(def_id) = cx.tables.qpath_def(path, inner.hir_id) {
if let Res::Def(DefKind::Struct, def_id) = cx.tables.qpath_res(path, inner.hir_id) {
return cx.match_def_path(def_id, &paths::LINT);
}
}

View file

@ -23,7 +23,7 @@ use std::mem;
use if_chain::if_chain;
use matches::matches;
use rustc::hir;
use rustc::hir::def::Def;
use rustc::hir::def::{DefKind, Res};
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
use rustc::hir::Node;
@ -213,7 +213,7 @@ pub fn match_path_ast(path: &ast::Path, segments: &[&str]) -> bool {
}
/// Gets the definition associated to a path.
pub fn path_to_def(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<def::Def> {
pub fn path_to_res(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<(def::Res)> {
let crates = cx.tcx.crates();
let krate = crates.iter().find(|&&krate| cx.tcx.crate_name(krate) == path[0]);
if let Some(krate) = krate {
@ -233,10 +233,10 @@ pub fn path_to_def(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<def::Def>
for item in mem::replace(&mut items, Lrc::new(vec![])).iter() {
if item.ident.name == *segment {
if path_it.peek().is_none() {
return Some(item.def);
return Some(item.res);
}
items = cx.tcx.item_children(item.def.def_id());
items = cx.tcx.item_children(item.res.def_id());
break;
}
}
@ -248,13 +248,13 @@ pub fn path_to_def(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<def::Def>
/// Convenience function to get the `DefId` of a trait by path.
pub fn get_trait_def_id(cx: &LateContext<'_, '_>, path: &[&str]) -> Option<DefId> {
let def = match path_to_def(cx, path) {
Some(def) => def,
let res = match path_to_res(cx, path) {
Some(res) => res,
None => return None,
};
match def {
def::Def::Trait(trait_id) => Some(trait_id),
match res {
def::Res::Def(DefKind::Trait, trait_id) => Some(trait_id),
_ => None,
}
}
@ -317,8 +317,8 @@ pub fn has_drop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
}
/// Resolves the definition of a node from its `HirId`.
pub fn resolve_node(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> def::Def {
cx.tables.qpath_def(qpath, id)
pub fn resolve_node(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> Res {
cx.tables.qpath_res(qpath, id)
}
/// Returns the method names and argument list of nested method call expressions that make up
@ -746,8 +746,8 @@ pub fn is_ctor_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
if let ExprKind::Call(ref fun, _) = expr.node {
if let ExprKind::Path(ref qp) = fun.node {
return matches!(
cx.tables.qpath_def(qp, fun.hir_id),
def::Def::Variant(..) | def::Def::Ctor(..)
cx.tables.qpath_res(qp, fun.hir_id),
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(..), _)
);
}
}
@ -758,8 +758,8 @@ pub fn is_ctor_function(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
pub fn is_refutable(cx: &LateContext<'_, '_>, pat: &Pat) -> bool {
fn is_enum_variant(cx: &LateContext<'_, '_>, qpath: &QPath, id: HirId) -> bool {
matches!(
cx.tables.qpath_def(qpath, id),
def::Def::Variant(..) | def::Def::Ctor(_, def::CtorOf::Variant, _)
cx.tables.qpath_res(qpath, id),
def::Res::Def(DefKind::Variant, ..) | Res::Def(DefKind::Ctor(def::CtorOf::Variant, _), _)
)
}
@ -831,7 +831,7 @@ pub fn is_self_ty(slf: &hir::Ty) -> bool {
if_chain! {
if let TyKind::Path(ref qp) = slf.node;
if let QPath::Resolved(None, ref path) = *qp;
if let Def::SelfTy(..) = path.def;
if let Res::SelfTy(..) = path.res;
then {
return true
}
@ -852,7 +852,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
if match_qpath(path, &paths::RESULT_OK[1..]);
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 let Res::Local(lid) = path.res;
if lid == hir_id;
then {
return true;

View file

@ -1,4 +1,4 @@
use rustc::hir::def::Def;
use rustc::hir::def::Res;
use rustc::hir::*;
use rustc::lint::LateContext;
use rustc::middle::expr_use_visitor::*;
@ -29,8 +29,8 @@ pub fn is_potentially_mutated<'a, 'tcx: 'a>(
expr: &'tcx Expr,
cx: &'a LateContext<'a, 'tcx>,
) -> bool {
let id = match variable.def {
Def::Local(id) | Def::Upvar(id, ..) => id,
let id = match variable.res {
Res::Local(id) | Res::Upvar(id, ..) => id,
_ => return true,
};
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&id))