Skip to content

Commit 9c9aa2d

Browse files
committed
Auto merge of #6222 - JohnTitor:redundant-local-def-id, r=flip1995
Remove redundant `expect_local()` call The field `owner` of `HirId` is `LocalDefId` and `hir_id.owner.to_def_id().expect_local()` is redundant. I wonder they were introduced in some rustups. changelog: none
2 parents 718bb28 + d571389 commit 9c9aa2d

File tree

4 files changed

+7
-11
lines changed

4 files changed

+7
-11
lines changed

clippy_lints/src/functions.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -579,9 +579,8 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<
579579
if let hir::PatKind::Wild = pat.kind {
580580
return false; // ignore `_` patterns
581581
}
582-
let def_id = pat.hir_id.owner.to_def_id();
583-
if cx.tcx.has_typeck_results(def_id) {
584-
is_mutable_ty(cx, &cx.tcx.typeck(def_id.expect_local()).pat_ty(pat), pat.span, tys)
582+
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
583+
is_mutable_ty(cx, &cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
585584
} else {
586585
false
587586
}
@@ -694,11 +693,10 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
694693
Call(_, args) | MethodCall(_, _, args, _) => {
695694
let mut tys = FxHashSet::default();
696695
for arg in args {
697-
let def_id = arg.hir_id.owner.to_def_id();
698-
if self.cx.tcx.has_typeck_results(def_id)
696+
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
699697
&& is_mutable_ty(
700698
self.cx,
701-
self.cx.tcx.typeck(def_id.expect_local()).expr_ty(arg),
699+
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
702700
arg.span,
703701
&mut tys,
704702
)

clippy_lints/src/loops.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2051,12 +2051,11 @@ fn check_for_mutation<'tcx>(
20512051
span_low: None,
20522052
span_high: None,
20532053
};
2054-
let def_id = body.hir_id.owner.to_def_id();
20552054
cx.tcx.infer_ctxt().enter(|infcx| {
20562055
ExprUseVisitor::new(
20572056
&mut delegate,
20582057
&infcx,
2059-
def_id.expect_local(),
2058+
body.hir_id.owner,
20602059
cx.param_env,
20612060
cx.typeck_results(),
20622061
)

clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -
299299
hir::QPath::Resolved(_, path) => path.res,
300300
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => {
301301
if cx.tcx.has_typeck_results(id.owner.to_def_id()) {
302-
cx.tcx.typeck(id.owner.to_def_id().expect_local()).qpath_res(qpath, id)
302+
cx.tcx.typeck(id.owner).qpath_res(qpath, id)
303303
} else {
304304
Res::Err
305305
}

clippy_lints/src/utils/usage.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
1919
used_mutably: FxHashSet::default(),
2020
skip: false,
2121
};
22-
let def_id = expr.hir_id.owner.to_def_id();
2322
cx.tcx.infer_ctxt().enter(|infcx| {
2423
ExprUseVisitor::new(
2524
&mut delegate,
2625
&infcx,
27-
def_id.expect_local(),
26+
expr.hir_id.owner,
2827
cx.param_env,
2928
cx.typeck_results(),
3029
)

0 commit comments

Comments
 (0)