diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-06-29 07:24:04 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-07-07 13:17:00 +0000 |
| commit | dcacfe7395cae68ecf8f8efe6803a121f4b74e99 (patch) | |
| tree | 917a003fba89c4cd7cc1216a63db58f46cce6595 | |
| parent | 18f3d8658815f260909b3485b20baa16ffbddde9 (diff) | |
| download | rust-dcacfe7395cae68ecf8f8efe6803a121f4b74e99.tar.gz rust-dcacfe7395cae68ecf8f8efe6803a121f4b74e99.zip | |
Only match on the `DefKind` once.
| -rw-r--r-- | compiler/rustc_ty_utils/src/opaque_types.rs | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 981919b7313..2a706d72843 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -268,41 +268,31 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ trace!(?kind); let mut collector = OpaqueTypeCollector::new(tcx, item); match kind { - // We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds` + // Walk over the signature of the function-like to find the opaques. + DefKind::AssocFn | DefKind::Fn => { + let ty_sig = tcx.fn_sig(item).subst_identity(); + let hir_sig = tcx.hir().get_by_def_id(item).fn_sig().unwrap(); + // Walk over the inputs and outputs manually in order to get good spans for them. + collector.visit_spanned(hir_sig.decl.output.span(), ty_sig.output()); + for (hir, ty) in hir_sig.decl.inputs.iter().zip(ty_sig.inputs().iter()) { + collector.visit_spanned(hir.span, ty.map_bound(|x| *x)); + } + collector.collect_body_and_predicate_taits(); + } + // Walk over the type of the item to find opaques. DefKind::Static(_) | DefKind::Const | DefKind::AssocConst - | DefKind::AssocFn | DefKind::AnonConst - | DefKind::InlineConst - | DefKind::Fn => { - match kind { - // Walk over the signature of the function-like to find the opaques. - DefKind::AssocFn | DefKind::Fn => { - let ty_sig = tcx.fn_sig(item).subst_identity(); - let hir_sig = tcx.hir().get_by_def_id(item).fn_sig().unwrap(); - // Walk over the inputs and outputs manually in order to get good spans for them. - collector.visit_spanned(hir_sig.decl.output.span(), ty_sig.output()); - for (hir, ty) in hir_sig.decl.inputs.iter().zip(ty_sig.inputs().iter()) { - collector.visit_spanned(hir.span, ty.map_bound(|x| *x)); - } - } - // Walk over the type of the item to find opaques. - DefKind::Static(_) - | DefKind::Const - | DefKind::AssocConst - | DefKind::AnonConst - | DefKind::InlineConst => { - let span = match tcx.hir().get_by_def_id(item).ty() { - Some(ty) => ty.span, - _ => tcx.def_span(item), - }; - collector.visit_spanned(span, tcx.type_of(item).subst_identity()); - } - _ => unreachable!(), - } + | DefKind::InlineConst => { + let span = match tcx.hir().get_by_def_id(item).ty() { + Some(ty) => ty.span, + _ => tcx.def_span(item), + }; + collector.visit_spanned(span, tcx.type_of(item).subst_identity()); collector.collect_body_and_predicate_taits(); } + // We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds` DefKind::TyAlias | DefKind::AssocTy => { tcx.type_of(item).subst_identity().visit_with(&mut collector); } |
