From 0f323b24b22cdda444749238649518bad68c0c15 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 7 Feb 2024 14:00:21 +0000 Subject: [PATCH] Associated types in traits don't necessarily have a type that we can visit This prevents ICEs from happening in the future when this code path is actually used --- compiler/rustc_ty_utils/src/sig_types.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs index b155a4ac87b..b0389052ccc 100644 --- a/compiler/rustc_ty_utils/src/sig_types.rs +++ b/compiler/rustc_ty_utils/src/sig_types.rs @@ -42,11 +42,10 @@ pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( DefKind::TyAlias {..} | DefKind::AssocTy | // Walk over the type of the item DefKind::Static(_) | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => { - let span = match tcx.hir_node_by_def_id(item).ty() { - Some(ty) => ty.span, - _ => tcx.def_span(item), - }; - visitor.visit(span, tcx.type_of(item).instantiate_identity()); + if let Some(ty) = tcx.hir_node_by_def_id(item).ty() { + // Associated types in traits don't necessarily have a type that we can visit + visitor.visit(ty.span, tcx.type_of(item).instantiate_identity())?; + } for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) { visitor.visit(span, pred)?; }