Skip to content

Commit 273b977

Browse files
use opaque_ty_origin_unchecked instead of destructuring HIR
1 parent 0bbcf09 commit 273b977

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,9 @@ pub(crate) fn type_check<'mir, 'tcx>(
227227
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
228228
// Check that RPITs are only constrained in their outermost
229229
// function, otherwise report a mismatched types error.
230-
if let hir::Node::Item(hir::Item {
231-
kind:
232-
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
233-
origin:
234-
hir::OpaqueTyOrigin::AsyncFn(parent)
235-
| hir::OpaqueTyOrigin::FnReturn(parent),
236-
..
237-
}),
238-
..
239-
}) = infcx.tcx.hir().get_by_def_id(opaque_type_key.def_id.expect_local()) &&
240-
parent.to_def_id() != body.source.def_id()
230+
if let OpaqueTyOrigin::FnReturn(parent) | OpaqueTyOrigin::AsyncFn(parent)
231+
= infcx.opaque_ty_origin_unchecked(opaque_type_key.def_id, hidden_type.span)
232+
&& parent.to_def_id() != body.source.def_id()
241233
{
242234
infcx
243235
.report_mismatched_types(

compiler/rustc_infer/src/infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
428428
}
429429

430430
#[instrument(skip(self), level = "trace")]
431-
fn opaque_ty_origin_unchecked(&self, opaque_def_id: DefId, span: Span) -> OpaqueTyOrigin {
431+
pub fn opaque_ty_origin_unchecked(&self, opaque_def_id: DefId, span: Span) -> OpaqueTyOrigin {
432432
let def_id = opaque_def_id.as_local().unwrap();
433433
let origin = match self.tcx.hir().expect_item(def_id).kind {
434434
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,

0 commit comments

Comments
 (0)