1
Fork 0

Note that trait aliases cannot be recursive

This commit is contained in:
Noah Lev 2021-08-21 14:19:59 -07:00
parent bf360dc272
commit c861964735
3 changed files with 21 additions and 9 deletions

View file

@ -600,16 +600,23 @@ pub(crate) fn report_cycle<'a>(
));
}
if !stack.is_empty()
&& stack.iter().all(|entry| {
entry.query.def_kind.map_or(false, |def_kind| {
matches!(def_kind, SimpleDefKind::TyAlias | SimpleDefKind::TraitAlias)
})
if stack.iter().all(|entry| {
entry.query.def_kind.map_or(false, |def_kind| {
matches!(def_kind, SimpleDefKind::TyAlias | SimpleDefKind::TraitAlias)
})
{
err.note("type aliases cannot be recursive");
err.help("consider using a struct, enum, or union instead to break the cycle");
err.help("see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information");
}) {
if stack.iter().all(|entry| {
entry
.query
.def_kind
.map_or(false, |def_kind| matches!(def_kind, SimpleDefKind::TyAlias))
}) {
err.note("type aliases cannot be recursive");
err.help("consider using a struct, enum, or union instead to break the cycle");
err.help("see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information");
} else {
err.note("trait aliases cannot be recursive");
}
}
if let Some((span, query)) = usage {