]> git.lizzy.rs Git - rust.git/commitdiff
Simplify match.
authorCamille GILLOT <gillot.camille@gmail.com>
Tue, 7 Dec 2021 21:49:07 +0000 (22:49 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Tue, 7 Dec 2021 21:53:42 +0000 (22:53 +0100)
compiler/rustc_infer/src/infer/opaque_types.rs

index 754d5a6ed72514d5406c3b6457fd7b0d0d7994be..c2ef0b41e27bf182761eef46e02d64d33f6b86d9 100644 (file)
@@ -461,39 +461,29 @@ fn instantiate_opaque_types_in_map<T: TypeFoldable<'tcx>>(&mut self, value: T) -
                     if let Some(def_id) = def_id.as_local() {
                         let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
                         let parent_def_id = self.infcx.defining_use_anchor;
-                        let (in_definition_scope, origin) = match tcx.hir().expect_item(def_id).kind
-                        {
+                        let item_kind = &tcx.hir().expect_item(def_id).kind;
+                        let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, ..  }) = item_kind else {
+                            span_bug!(
+                                self.value_span,
+                                "weird opaque type: {:#?}, {:#?}",
+                                ty.kind(),
+                                item_kind
+                            )
+                        };
+                        let in_definition_scope = match *origin {
                             // Async `impl Trait`
-                            hir::ItemKind::OpaqueTy(hir::OpaqueTy {
-                                origin: hir::OpaqueTyOrigin::AsyncFn(parent),
-                                ..
-                            }) => (parent == parent_def_id, hir::OpaqueTyOrigin::AsyncFn(parent)),
+                            hir::OpaqueTyOrigin::AsyncFn(parent) => parent == parent_def_id,
                             // Anonymous `impl Trait`
-                            hir::ItemKind::OpaqueTy(hir::OpaqueTy {
-                                origin: hir::OpaqueTyOrigin::FnReturn(parent),
-                                ..
-                            }) => (parent == parent_def_id, hir::OpaqueTyOrigin::FnReturn(parent)),
+                            hir::OpaqueTyOrigin::FnReturn(parent) => parent == parent_def_id,
                             // Named `type Foo = impl Bar;`
-                            hir::ItemKind::OpaqueTy(hir::OpaqueTy {
-                                origin: hir::OpaqueTyOrigin::TyAlias,
-                                ..
-                            }) => (
-                                may_define_opaque_type(tcx, parent_def_id, opaque_hir_id),
-                                hir::OpaqueTyOrigin::TyAlias,
-                            ),
-                            ref itemkind => {
-                                span_bug!(
-                                    self.value_span,
-                                    "weird opaque type: {:#?}, {:#?}",
-                                    ty.kind(),
-                                    itemkind
-                                )
+                            hir::OpaqueTyOrigin::TyAlias => {
+                                may_define_opaque_type(tcx, parent_def_id, opaque_hir_id)
                             }
                         };
                         if in_definition_scope {
                             let opaque_type_key =
                                 OpaqueTypeKey { def_id: def_id.to_def_id(), substs };
-                            return self.fold_opaque_ty(ty, opaque_type_key, origin);
+                            return self.fold_opaque_ty(ty, opaque_type_key, *origin);
                         }
 
                         debug!(