diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-08-19 20:30:33 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2021-08-27 14:50:51 -0700 |
| commit | cd0fc444fb0edb4df0bd8091706d3819313a9df4 (patch) | |
| tree | a27934154a2d45e254f98fca1c13aa3bac3ea79d /compiler/rustc_query_system/src/query/job.rs | |
| parent | 2f48bfa88c1c742ed058fc8af096d8cedc138434 (diff) | |
| download | rust-cd0fc444fb0edb4df0bd8091706d3819313a9df4.tar.gz rust-cd0fc444fb0edb4df0bd8091706d3819313a9df4.zip | |
Note that type aliases cannot be recursive
Diffstat (limited to 'compiler/rustc_query_system/src/query/job.rs')
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index b7ac42546dd..f8ba0babab0 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -1,6 +1,6 @@ use crate::dep_graph::DepContext; use crate::query::plumbing::CycleError; -use crate::query::{QueryContext, QueryStackFrame}; +use crate::query::{QueryContext, QueryStackFrame, SimpleDefKind}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, Handler, Level}; @@ -600,6 +600,18 @@ 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) + }) + }) + { + 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 let Some((span, query)) = usage { err.span_note(fix_span(span, &query), &format!("cycle used when {}", query.description)); } |
