diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-08-21 14:19:59 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2021-08-27 14:50:52 -0700 |
| commit | c8619647359903a707891e7d40f68264d1e6ed94 (patch) | |
| tree | eb97ff3b00f28ba5296a5f5d66fab91c89d5db3c /compiler | |
| parent | bf360dc2729780084de0035aeb7047288a3b5f9d (diff) | |
| download | rust-c8619647359903a707891e7d40f68264d1e6ed94.tar.gz rust-c8619647359903a707891e7d40f68264d1e6ed94.zip | |
Note that trait aliases cannot be recursive
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_query_impl/src/keys.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 25 |
2 files changed, 20 insertions, 9 deletions
diff --git a/compiler/rustc_query_impl/src/keys.rs b/compiler/rustc_query_impl/src/keys.rs index 40b820c8d8e..88ab7597eac 100644 --- a/compiler/rustc_query_impl/src/keys.rs +++ b/compiler/rustc_query_impl/src/keys.rs @@ -178,6 +178,10 @@ impl Key for (DefId, Option<Ident>) { fn default_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.def_span(self.0) } + #[inline(always)] + fn key_as_def_id(&self) -> Option<DefId> { + Some(self.0) + } } impl Key for (DefId, LocalDefId, Ident) { diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index f8ba0babab0..63a8f062475 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -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 { |
