Skip to content

Commit 0f323b2

Browse files
committedFeb 7, 2024
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
1 parent d4f6f9e commit 0f323b2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed
 

‎compiler/rustc_ty_utils/src/sig_types.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
4242
DefKind::TyAlias {..} | DefKind::AssocTy |
4343
// Walk over the type of the item
4444
DefKind::Static(_) | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => {
45-
let span = match tcx.hir_node_by_def_id(item).ty() {
46-
Some(ty) => ty.span,
47-
_ => tcx.def_span(item),
48-
};
49-
visitor.visit(span, tcx.type_of(item).instantiate_identity());
45+
if let Some(ty) = tcx.hir_node_by_def_id(item).ty() {
46+
// Associated types in traits don't necessarily have a type that we can visit
47+
visitor.visit(ty.span, tcx.type_of(item).instantiate_identity())?;
48+
}
5049
for (pred, span) in tcx.predicates_of(item).instantiate_identity(tcx) {
5150
visitor.visit(span, pred)?;
5251
}

0 commit comments

Comments
 (0)