Skip to content

Commit dcacfe7

Browse files
committed
Only match on the DefKind once.
1 parent 18f3d86 commit dcacfe7

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

compiler/rustc_ty_utils/src/opaque_types.rs

+19-29
Original file line numberDiff line numberDiff line change
@@ -268,41 +268,31 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
268268
trace!(?kind);
269269
let mut collector = OpaqueTypeCollector::new(tcx, item);
270270
match kind {
271-
// We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds`
271+
// Walk over the signature of the function-like to find the opaques.
272+
DefKind::AssocFn | DefKind::Fn => {
273+
let ty_sig = tcx.fn_sig(item).subst_identity();
274+
let hir_sig = tcx.hir().get_by_def_id(item).fn_sig().unwrap();
275+
// Walk over the inputs and outputs manually in order to get good spans for them.
276+
collector.visit_spanned(hir_sig.decl.output.span(), ty_sig.output());
277+
for (hir, ty) in hir_sig.decl.inputs.iter().zip(ty_sig.inputs().iter()) {
278+
collector.visit_spanned(hir.span, ty.map_bound(|x| *x));
279+
}
280+
collector.collect_body_and_predicate_taits();
281+
}
282+
// Walk over the type of the item to find opaques.
272283
DefKind::Static(_)
273284
| DefKind::Const
274285
| DefKind::AssocConst
275-
| DefKind::AssocFn
276286
| DefKind::AnonConst
277-
| DefKind::InlineConst
278-
| DefKind::Fn => {
279-
match kind {
280-
// Walk over the signature of the function-like to find the opaques.
281-
DefKind::AssocFn | DefKind::Fn => {
282-
let ty_sig = tcx.fn_sig(item).subst_identity();
283-
let hir_sig = tcx.hir().get_by_def_id(item).fn_sig().unwrap();
284-
// Walk over the inputs and outputs manually in order to get good spans for them.
285-
collector.visit_spanned(hir_sig.decl.output.span(), ty_sig.output());
286-
for (hir, ty) in hir_sig.decl.inputs.iter().zip(ty_sig.inputs().iter()) {
287-
collector.visit_spanned(hir.span, ty.map_bound(|x| *x));
288-
}
289-
}
290-
// Walk over the type of the item to find opaques.
291-
DefKind::Static(_)
292-
| DefKind::Const
293-
| DefKind::AssocConst
294-
| DefKind::AnonConst
295-
| DefKind::InlineConst => {
296-
let span = match tcx.hir().get_by_def_id(item).ty() {
297-
Some(ty) => ty.span,
298-
_ => tcx.def_span(item),
299-
};
300-
collector.visit_spanned(span, tcx.type_of(item).subst_identity());
301-
}
302-
_ => unreachable!(),
303-
}
287+
| DefKind::InlineConst => {
288+
let span = match tcx.hir().get_by_def_id(item).ty() {
289+
Some(ty) => ty.span,
290+
_ => tcx.def_span(item),
291+
};
292+
collector.visit_spanned(span, tcx.type_of(item).subst_identity());
304293
collector.collect_body_and_predicate_taits();
305294
}
295+
// We're also doing this for `AssocTy` for the wf checks in `check_opaque_meets_bounds`
306296
DefKind::TyAlias | DefKind::AssocTy => {
307297
tcx.type_of(item).subst_identity().visit_with(&mut collector);
308298
}

0 commit comments

Comments
 (0)