Skip to content

Commit 54ff721

Browse files
committed
Simplify match.
1 parent 8576ab4 commit 54ff721

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -461,39 +461,29 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
461461
if let Some(def_id) = def_id.as_local() {
462462
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
463463
let parent_def_id = self.infcx.defining_use_anchor;
464-
let (in_definition_scope, origin) = match tcx.hir().expect_item(def_id).kind
465-
{
464+
let item_kind = &tcx.hir().expect_item(def_id).kind;
465+
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item_kind else {
466+
span_bug!(
467+
self.value_span,
468+
"weird opaque type: {:#?}, {:#?}",
469+
ty.kind(),
470+
item_kind
471+
)
472+
};
473+
let in_definition_scope = match *origin {
466474
// Async `impl Trait`
467-
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
468-
origin: hir::OpaqueTyOrigin::AsyncFn(parent),
469-
..
470-
}) => (parent == parent_def_id, hir::OpaqueTyOrigin::AsyncFn(parent)),
475+
hir::OpaqueTyOrigin::AsyncFn(parent) => parent == parent_def_id,
471476
// Anonymous `impl Trait`
472-
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
473-
origin: hir::OpaqueTyOrigin::FnReturn(parent),
474-
..
475-
}) => (parent == parent_def_id, hir::OpaqueTyOrigin::FnReturn(parent)),
477+
hir::OpaqueTyOrigin::FnReturn(parent) => parent == parent_def_id,
476478
// Named `type Foo = impl Bar;`
477-
hir::ItemKind::OpaqueTy(hir::OpaqueTy {
478-
origin: hir::OpaqueTyOrigin::TyAlias,
479-
..
480-
}) => (
481-
may_define_opaque_type(tcx, parent_def_id, opaque_hir_id),
482-
hir::OpaqueTyOrigin::TyAlias,
483-
),
484-
ref itemkind => {
485-
span_bug!(
486-
self.value_span,
487-
"weird opaque type: {:#?}, {:#?}",
488-
ty.kind(),
489-
itemkind
490-
)
479+
hir::OpaqueTyOrigin::TyAlias => {
480+
may_define_opaque_type(tcx, parent_def_id, opaque_hir_id)
491481
}
492482
};
493483
if in_definition_scope {
494484
let opaque_type_key =
495485
OpaqueTypeKey { def_id: def_id.to_def_id(), substs };
496-
return self.fold_opaque_ty(ty, opaque_type_key, origin);
486+
return self.fold_opaque_ty(ty, opaque_type_key, *origin);
497487
}
498488

499489
debug!(

0 commit comments

Comments
 (0)