From 603996c9d5a64e4d9b8a35d5a575b1e04b72d122 Mon Sep 17 00:00:00 2001 From: Tomas Koutsky Date: Wed, 10 Apr 2019 16:18:02 +0200 Subject: [PATCH] Support updated type dependent def ID getter --- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/functions.rs | 2 +- clippy_lints/src/loops.rs | 4 ++-- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/utils/mod.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 425f1e671..d67381660 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -102,7 +102,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) { // Are the expression or the arguments type-adjusted? Then we need the closure if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg))); - let method_def_id = cx.tables.type_dependent_defs()[ex.hir_id].def_id(); + let method_def_id = cx.tables.type_dependent_def_id(ex.hir_id).unwrap(); if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id)); if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter()); diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 4313d0404..307f03c69 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -303,7 +303,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> { } }, hir::ExprKind::MethodCall(_, _, ref args) => { - let def_id = self.tables.type_dependent_defs()[expr.hir_id].def_id(); + let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap(); let base_type = self.cx.tcx.type_of(def_id); if type_is_unsafe_function(self.cx, base_type) { diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index c2b44ee70..11b4d237c 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1369,7 +1369,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex lint_iter_method(cx, args, arg, method_name); } } else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) { - let def_id = cx.tables.type_dependent_defs()[arg.hir_id].def_id(); + let def_id = cx.tables.type_dependent_def_id(arg.hir_id).unwrap(); let substs = cx.tables.node_substs(arg.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); @@ -1904,7 +1904,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { } }, ExprKind::MethodCall(_, _, ref args) => { - let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id(); + let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) { self.prefer_mutable = false; if let ty::Ref(_, _, mutbl) = ty.sty { diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 136fb8b55..7333aa9f5 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed { } }, ExprKind::MethodCall(ref path, _, ref arguments) => { - let def_id = cx.tables.type_dependent_defs()[e.hir_id].def_id(); + let def_id = cx.tables.type_dependent_def_id(e.hir_id).unwrap(); let substs = cx.tables.node_substs(e.hir_id); let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs); check_arguments(cx, arguments, method_type, &path.ident.as_str()) diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 3590b7ae9..542a18635 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -239,8 +239,8 @@ pub fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool { /// Checks if the method call given in `expr` belongs to the given trait. pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr, path: &[&str]) -> bool { - let method_call = cx.tables.type_dependent_defs()[expr.hir_id]; - let trt_id = cx.tcx.trait_of_item(method_call.def_id()); + let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap(); + let trt_id = cx.tcx.trait_of_item(def_id); if let Some(trt_id) = trt_id { match_def_path(cx.tcx, trt_id, path) } else {