diff options
| author | Yuanheng Li <520dhh@gmail.com> | 2022-08-21 21:37:05 +0800 |
|---|---|---|
| committer | Li Yuanheng <520dhh@gmail.com> | 2022-08-31 19:33:51 +0800 |
| commit | b8075e4550a3ec9110930b41e09e77266482e54f (patch) | |
| tree | 7c00a0bc626ab45b7937332a03f2b5ece4f3e4e1 /compiler/rustc_query_system/src/query | |
| parent | 12e4fd0755d7d976d4ee0f2004dc938290752ff7 (diff) | |
| download | rust-b8075e4550a3ec9110930b41e09e77266482e54f.tar.gz rust-b8075e4550a3ec9110930b41e09e77266482e54f.zip | |
migrate rustc_query_system to use SessionDiagnostic
with manual impl SessionDiagnostic
Diffstat (limited to 'compiler/rustc_query_system/src/query')
| -rw-r--r-- | compiler/rustc_query_system/src/query/job.rs | 55 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 14 |
2 files changed, 23 insertions, 46 deletions
diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 6d2aff38172..718ec14db36 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -1,12 +1,10 @@ use crate::query::plumbing::CycleError; use crate::query::{QueryContext, QueryStackFrame}; -use rustc_hir::def::DefKind; use rustc_data_structures::fx::FxHashMap; -use rustc_errors::{ - struct_span_err, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level, -}; -use rustc_session::Session; +use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed, Handler, Level}; +use rustc_hir::def::DefKind; +use rustc_session::{Session, SessionDiagnostic}; use rustc_span::Span; use std::hash::Hash; @@ -536,46 +534,29 @@ pub(crate) fn report_cycle<'a>( assert!(!stack.is_empty()); let span = stack[0].query.default_span(stack[1 % stack.len()].span); - let mut err = - struct_span_err!(sess, span, E0391, "cycle detected when {}", stack[0].query.description); + + let mut cycle_diag = crate::error::Cycle { + span, + upper_stack_info: Vec::with_capacity(stack.len() - 1), + stack_bottom: stack[0].query.description.to_owned(), + recursive_ty_alias: false, + recursive_trait_alias: false, + cycle_usage: usage.map(|(span, query)| (query.default_span(span), query.description)), + }; for i in 1..stack.len() { let query = &stack[i].query; let span = query.default_span(stack[(i + 1) % stack.len()].span); - err.span_note(span, &format!("...which requires {}...", query.description)); - } - - if stack.len() == 1 { - err.note(&format!("...which immediately requires {} again", stack[0].query.description)); - } else { - err.note(&format!( - "...which again requires {}, completing the cycle", - stack[0].query.description - )); - } - - if stack.iter().all(|entry| { - entry - .query - .def_kind - .map_or(false, |def_kind| matches!(def_kind, DefKind::TyAlias | DefKind::TraitAlias)) - }) { - if stack.iter().all(|entry| { - entry.query.def_kind.map_or(false, |def_kind| matches!(def_kind, DefKind::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"); - } + cycle_diag.upper_stack_info.push((span, query.description.to_owned())); } - if let Some((span, query)) = usage { - err.span_note(query.default_span(span), &format!("cycle used when {}", query.description)); + if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TyAlias)) { + cycle_diag.recursive_ty_alias = true; + } else if stack.iter().all(|entry| entry.query.def_kind == Some(DefKind::TraitAlias)) { + cycle_diag.recursive_trait_alias = true; } - err + cycle_diag.into_diagnostic(&sess.parse_sess) } pub fn print_query_stack<CTX: QueryContext>( diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 6ae9147ff77..e97411b777b 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -618,16 +618,12 @@ fn incremental_verify_ich_cold(sess: &Session, dep_node: DebugArg<'_>, result: D let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true)); if old_in_panic { - sess.struct_err( - "internal compiler error: re-entrant incremental verify failure, suppressing message", - ) - .emit(); + sess.emit_err(crate::error::Reentrant); } else { - sess.struct_err(&format!("internal compiler error: encountered incremental compilation error with {:?}", dep_node)) - .help(&format!("This is a known issue with the compiler. Run {} to allow your project to compile", run_cmd)) - .note("Please follow the instructions below to create a bug report with the provided information") - .note("See <https://github.com/rust-lang/rust/issues/84970> for more information") - .emit(); + sess.emit_err(crate::error::IncrementCompilation { + run_cmd, + dep_node: format!("{:?}", dep_node), + }); panic!("Found unstable fingerprints for {:?}: {:?}", dep_node, result); } |
