Skip to content

Commit 54def1e

Browse files
committed
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`.
2 parents 9e54538 + 5abd8c5 commit 54def1e

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

clippy_lints/src/async_yields_async.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
5050
let body_id = BodyId {
5151
hir_id: body.value.hir_id,
5252
};
53-
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
54-
let typeck_results = cx.tcx.typeck(def_id);
53+
let typeck_results = cx.tcx.typeck_body(body_id);
5554
let expr_ty = typeck_results.expr_ty(&body.value);
5655

5756
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {

clippy_lints/src/await_holding_invalid.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ impl LateLintPass<'_> for AwaitHolding {
9797
let body_id = BodyId {
9898
hir_id: body.value.hir_id,
9999
};
100-
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
101-
let typeck_results = cx.tcx.typeck(def_id);
100+
let typeck_results = cx.tcx.typeck_body(body_id);
102101
check_interior_types(
103102
cx,
104103
&typeck_results.generator_interior_types.as_ref().skip_binder(),

clippy_lints/src/doc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ fn lint_for_missing_headers<'tcx>(
325325
if_chain! {
326326
if let Some(body_id) = body_id;
327327
if let Some(future) = cx.tcx.lang_items().future_trait();
328-
let def_id = cx.tcx.hir().body_owner_def_id(body_id);
329-
let mir = cx.tcx.optimized_mir(def_id.to_def_id());
330-
let ret_ty = mir.return_ty();
328+
let typeck = cx.tcx.typeck_body(body_id);
329+
let body = cx.tcx.hir().body(body_id);
330+
let ret_ty = typeck.expr_ty(&body.value);
331331
if implements_trait(cx, ret_ty, future, &[]);
332332
if let ty::Opaque(_, subs) = ret_ty.kind();
333333
if let Some(gen) = subs.types().next();

clippy_lints/src/implicit_return.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{fn_has_unsatisfiable_preds, match_panic_def_id, snippet_opt, span_lint_and_then};
1+
use crate::utils::{match_panic_def_id, snippet_opt, span_lint_and_then};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_hir::intravisit::FnKind;
@@ -133,19 +133,13 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
133133
span: Span,
134134
_: HirId,
135135
) {
136-
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
137-
138-
// Building MIR for `fn`s with unsatisfiable preds results in ICE.
139-
if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) {
136+
if span.from_expansion() {
140137
return;
141138
}
142-
143-
let mir = cx.tcx.optimized_mir(def_id.to_def_id());
144-
145-
// checking return type through MIR, HIR is not able to determine inferred closure return types
146-
// make sure it's not a macro
147-
if !mir.return_ty().is_unit() && !span.from_expansion() {
148-
expr_match(cx, &body.value);
139+
let body = cx.tcx.hir().body(body.id());
140+
if cx.typeck_results().expr_ty(&body.value).is_unit() {
141+
return;
149142
}
143+
expr_match(cx, &body.value);
150144
}
151145
}

0 commit comments

Comments
 (0)