diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-11-29 00:21:56 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-20 23:36:31 +0100 |
| commit | c26d965714e38d62b1610780f67bec14dafe25c3 (patch) | |
| tree | e654c3590e355e229d055029deceb5509dd6bd5f /compiler/rustc_query_impl | |
| parent | 3897395787866281e98e3f0e41cf26dab5d94d7b (diff) | |
| download | rust-c26d965714e38d62b1610780f67bec14dafe25c3.tar.gz rust-c26d965714e38d62b1610780f67bec14dafe25c3.zip | |
Move report_cycle to rustc_query_system.
The call to `ty::print::with_forced_impl_filename_line` is done when constructing the description, at the construction of the QueryStackFrame.
Diffstat (limited to 'compiler/rustc_query_impl')
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 62 |
2 files changed, 7 insertions, 57 deletions
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index bfba7c7410e..176c68cf0fc 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -18,7 +18,7 @@ extern crate tracing; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use rustc_errors::{Diagnostic, Handler, Level}; +use rustc_errors::{Diagnostic, DiagnosticBuilder, Handler, Level}; use rustc_hir::def_id::CrateNum; use rustc_index::vec::IndexVec; use rustc_middle::dep_graph; diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index 01fb5a7ba20..00392fbcf56 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -8,15 +8,13 @@ use rustc_middle::ty::query::on_disk_cache; use rustc_middle::ty::tls::{self, ImplicitCtxt}; use rustc_middle::ty::{self, TyCtxt}; use rustc_query_system::dep_graph::HasDepContext; -use rustc_query_system::query::{CycleError, QueryJobId}; -use rustc_query_system::query::{QueryContext, QueryDescription, QueryMap, QueryStackFrame}; +use rustc_query_system::query::{QueryContext, QueryDescription, QueryJobId, QueryMap}; use rustc_data_structures::sync::Lock; use rustc_data_structures::thin_vec::ThinVec; -use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder}; +use rustc_errors::Diagnostic; use rustc_serialize::opaque; use rustc_span::def_id::{DefId, LocalDefId}; -use rustc_span::Span; #[derive(Copy, Clone)] pub struct QueryCtxt<'tcx> { @@ -175,54 +173,6 @@ impl QueryContext for QueryCtxt<'tcx> { } impl<'tcx> QueryCtxt<'tcx> { - #[inline(never)] - #[cold] - pub(super) fn report_cycle( - self, - CycleError { usage, cycle: stack }: CycleError, - ) -> DiagnosticBuilder<'tcx> { - assert!(!stack.is_empty()); - - let fix_span = |span: Span, query: &QueryStackFrame| { - self.sess.source_map().guess_head_span(query.default_span(span)) - }; - - // Disable naming impls with types in this path, since that - // sometimes cycles itself, leading to extra cycle errors. - // (And cycle errors around impls tend to occur during the - // collect/coherence phases anyhow.) - ty::print::with_forced_impl_filename_line(|| { - let span = fix_span(stack[1 % stack.len()].span, &stack[0].query); - let mut err = struct_span_err!( - self.sess, - span, - E0391, - "cycle detected when {}", - stack[0].query.description - ); - - for i in 1..stack.len() { - let query = &stack[i].query; - let span = fix_span(stack[(i + 1) % stack.len()].span, query); - err.span_note(span, &format!("...which requires {}...", query.description)); - } - - err.note(&format!( - "...which again requires {}, completing the cycle", - stack[0].query.description - )); - - if let Some((span, query)) = usage { - err.span_note( - fix_span(span, &query), - &format!("cycle used when {}", query.description), - ); - } - - err - }) - } - pub(super) fn encode_query_results( self, encoder: &mut on_disk_cache::CacheEncoder<'a, 'tcx, opaque::FileEncoder>, @@ -302,16 +252,16 @@ pub struct QueryStruct { macro_rules! handle_cycle_error { ([][$tcx: expr, $error:expr]) => {{ - $tcx.report_cycle($error).emit(); + $error.emit(); Value::from_cycle_error($tcx) }}; ([fatal_cycle $($rest:tt)*][$tcx:expr, $error:expr]) => {{ - $tcx.report_cycle($error).emit(); + $error.emit(); $tcx.sess.abort_if_errors(); unreachable!() }}; ([cycle_delay_bug $($rest:tt)*][$tcx:expr, $error:expr]) => {{ - $tcx.report_cycle($error).delay_as_bug(); + $error.delay_as_bug(); Value::from_cycle_error($tcx) }}; ([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => { @@ -459,7 +409,7 @@ macro_rules! define_queries { fn handle_cycle_error( tcx: QueryCtxt<'tcx>, - error: CycleError, + mut error: DiagnosticBuilder<'_>, ) -> Self::Value { handle_cycle_error!([$($modifiers)*][tcx, error]) } |
