From 0af4a211be2c9cc345728449a2fe213f64c216b8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 19 Jun 2023 09:55:01 +0000 Subject: [PATCH] Document what is going on in `opaque_types_defined_by` --- compiler/rustc_ty_utils/src/opaque_types.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 5fb5c4ad144..498194a7c10 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -168,14 +168,17 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ DefKind::Fn | DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => { let mut collector = OpaqueTypeCollector::new(tcx, item); 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::AssocTy | DefKind::AssocConst => { let span = match tcx.hir().get_by_def_id(item).ty() { Some(ty) => ty.span,