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
This commit is contained in:
bors
2020-10-25 11:58:51 +00:00
4 changed files with 7 additions and 11 deletions
+4 -6
View File
@@ -579,9 +579,8 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<
if let hir::PatKind::Wild = pat.kind {
return false; // ignore `_` patterns
}
let def_id = pat.hir_id.owner.to_def_id();
if cx.tcx.has_typeck_results(def_id) {
is_mutable_ty(cx, &cx.tcx.typeck(def_id.expect_local()).pat_ty(pat), pat.span, tys)
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
is_mutable_ty(cx, &cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
} else {
false
}
@@ -694,11 +693,10 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
Call(_, args) | MethodCall(_, _, args, _) => {
let mut tys = FxHashSet::default();
for arg in args {
let def_id = arg.hir_id.owner.to_def_id();
if self.cx.tcx.has_typeck_results(def_id)
if self.cx.tcx.has_typeck_results(arg.hir_id.owner.to_def_id())
&& is_mutable_ty(
self.cx,
self.cx.tcx.typeck(def_id.expect_local()).expr_ty(arg),
self.cx.tcx.typeck(arg.hir_id.owner).expr_ty(arg),
arg.span,
&mut tys,
)
+1 -2
View File
@@ -2051,12 +2051,11 @@ fn check_for_mutation<'tcx>(
span_low: None,
span_high: None,
};
let def_id = body.hir_id.owner.to_def_id();
cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(
&mut delegate,
&infcx,
def_id.expect_local(),
body.hir_id.owner,
cx.param_env,
cx.typeck_results(),
)
+1 -1
View File
@@ -299,7 +299,7 @@ pub fn qpath_res(cx: &LateContext<'_>, qpath: &hir::QPath<'_>, id: hir::HirId) -
hir::QPath::Resolved(_, path) => path.res,
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => {
if cx.tcx.has_typeck_results(id.owner.to_def_id()) {
cx.tcx.typeck(id.owner.to_def_id().expect_local()).qpath_res(qpath, id)
cx.tcx.typeck(id.owner).qpath_res(qpath, id)
} else {
Res::Err
}
+1 -2
View File
@@ -19,12 +19,11 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
used_mutably: FxHashSet::default(),
skip: false,
};
let def_id = expr.hir_id.owner.to_def_id();
cx.tcx.infer_ctxt().enter(|infcx| {
ExprUseVisitor::new(
&mut delegate,
&infcx,
def_id.expect_local(),
expr.hir_id.owner,
cx.param_env,
cx.typeck_results(),
)