Skip to content

Commit f23216d

Browse files
committed
Auto merge of #3937 - stepnivlk:type_dependent_defs-wrappers, r=oli-obk
Support updated type dependent def ID getter This PR changes all the calls to `type_dependent_defs` (with panics via `[]`) to new method `type_dependent_def_id` with more explicit `unwrap` panic. Rust PR: rust-lang/rust#59216 Issue author: @oli-obk
2 parents 3d469f4 + 603996c commit f23216d

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

clippy_lints/src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
102102
// Are the expression or the arguments type-adjusted? Then we need the closure
103103
if !(is_adjusted(cx, ex) || args.iter().skip(1).any(|arg| is_adjusted(cx, arg)));
104104

105-
let method_def_id = cx.tables.type_dependent_defs()[ex.hir_id].def_id();
105+
let method_def_id = cx.tables.type_dependent_def_id(ex.hir_id).unwrap();
106106
if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id));
107107

108108
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter());

clippy_lints/src/functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
303303
}
304304
},
305305
hir::ExprKind::MethodCall(_, _, ref args) => {
306-
let def_id = self.tables.type_dependent_defs()[expr.hir_id].def_id();
306+
let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap();
307307
let base_type = self.cx.tcx.type_of(def_id);
308308

309309
if type_is_unsafe_function(self.cx, base_type) {

clippy_lints/src/loops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
13691369
lint_iter_method(cx, args, arg, method_name);
13701370
}
13711371
} else if method_name == "into_iter" && match_trait_method(cx, arg, &paths::INTO_ITERATOR) {
1372-
let def_id = cx.tables.type_dependent_defs()[arg.hir_id].def_id();
1372+
let def_id = cx.tables.type_dependent_def_id(arg.hir_id).unwrap();
13731373
let substs = cx.tables.node_substs(arg.hir_id);
13741374
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
13751375

@@ -1904,7 +1904,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
19041904
}
19051905
},
19061906
ExprKind::MethodCall(_, _, ref args) => {
1907-
let def_id = self.cx.tables.type_dependent_defs()[expr.hir_id].def_id();
1907+
let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap();
19081908
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
19091909
self.prefer_mutable = false;
19101910
if let ty::Ref(_, _, mutbl) = ty.sty {

clippy_lints/src/mut_reference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
5050
}
5151
},
5252
ExprKind::MethodCall(ref path, _, ref arguments) => {
53-
let def_id = cx.tables.type_dependent_defs()[e.hir_id].def_id();
53+
let def_id = cx.tables.type_dependent_def_id(e.hir_id).unwrap();
5454
let substs = cx.tables.node_substs(e.hir_id);
5555
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
5656
check_arguments(cx, arguments, method_type, &path.ident.as_str())

clippy_lints/src/utils/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ pub fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool {
239239

240240
/// Checks if the method call given in `expr` belongs to the given trait.
241241
pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr, path: &[&str]) -> bool {
242-
let method_call = cx.tables.type_dependent_defs()[expr.hir_id];
243-
let trt_id = cx.tcx.trait_of_item(method_call.def_id());
242+
let def_id = cx.tables.type_dependent_def_id(expr.hir_id).unwrap();
243+
let trt_id = cx.tcx.trait_of_item(def_id);
244244
if let Some(trt_id) = trt_id {
245245
match_def_path(cx.tcx, trt_id, path)
246246
} else {

0 commit comments

Comments
 (0)