Auto merge of #6852 - camsteffen:avoid-mir, r=Manishearth

Remove a couple MIR usages

changelog: none

We use MIR to get the return type of a closure/function in a couple places. But typeck seems like a better approach.

This is the easy part of #6080.

Also did a tiny cleanup with `typeck` -> `typeck_body`.
This commit is contained in:
bors 2021-03-05 17:30:43 +00:00
commit 54def1e145
4 changed files with 11 additions and 19 deletions

View file

@ -50,8 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
let body_id = BodyId { let body_id = BodyId {
hir_id: body.value.hir_id, hir_id: body.value.hir_id,
}; };
let def_id = cx.tcx.hir().body_owner_def_id(body_id); let typeck_results = cx.tcx.typeck_body(body_id);
let typeck_results = cx.tcx.typeck(def_id);
let expr_ty = typeck_results.expr_ty(&body.value); let expr_ty = typeck_results.expr_ty(&body.value);
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) { if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {

View file

@ -97,8 +97,7 @@ impl LateLintPass<'_> for AwaitHolding {
let body_id = BodyId { let body_id = BodyId {
hir_id: body.value.hir_id, hir_id: body.value.hir_id,
}; };
let def_id = cx.tcx.hir().body_owner_def_id(body_id); let typeck_results = cx.tcx.typeck_body(body_id);
let typeck_results = cx.tcx.typeck(def_id);
check_interior_types( check_interior_types(
cx, cx,
&typeck_results.generator_interior_types.as_ref().skip_binder(), &typeck_results.generator_interior_types.as_ref().skip_binder(),

View file

@ -325,9 +325,9 @@ fn lint_for_missing_headers<'tcx>(
if_chain! { if_chain! {
if let Some(body_id) = body_id; if let Some(body_id) = body_id;
if let Some(future) = cx.tcx.lang_items().future_trait(); if let Some(future) = cx.tcx.lang_items().future_trait();
let def_id = cx.tcx.hir().body_owner_def_id(body_id); let typeck = cx.tcx.typeck_body(body_id);
let mir = cx.tcx.optimized_mir(def_id.to_def_id()); let body = cx.tcx.hir().body(body_id);
let ret_ty = mir.return_ty(); let ret_ty = typeck.expr_ty(&body.value);
if implements_trait(cx, ret_ty, future, &[]); if implements_trait(cx, ret_ty, future, &[]);
if let ty::Opaque(_, subs) = ret_ty.kind(); if let ty::Opaque(_, subs) = ret_ty.kind();
if let Some(gen) = subs.types().next(); if let Some(gen) = subs.types().next();

View file

@ -1,4 +1,4 @@
use crate::utils::{fn_has_unsatisfiable_preds, match_panic_def_id, snippet_opt, span_lint_and_then}; use crate::utils::{match_panic_def_id, snippet_opt, span_lint_and_then};
use if_chain::if_chain; use if_chain::if_chain;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
@ -133,19 +133,13 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
span: Span, span: Span,
_: HirId, _: HirId,
) { ) {
let def_id = cx.tcx.hir().body_owner_def_id(body.id()); if span.from_expansion() {
// Building MIR for `fn`s with unsatisfiable preds results in ICE.
if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) {
return; return;
} }
let body = cx.tcx.hir().body(body.id());
let mir = cx.tcx.optimized_mir(def_id.to_def_id()); if cx.typeck_results().expr_ty(&body.value).is_unit() {
return;
// checking return type through MIR, HIR is not able to determine inferred closure return types
// make sure it's not a macro
if !mir.return_ty().is_unit() && !span.from_expansion() {
expr_match(cx, &body.value);
} }
expr_match(cx, &body.value);
} }
} }