rustc_query_system/
values.rs

1use rustc_span::ErrorGuaranteed;
2
3use crate::dep_graph::DepContext;
4use crate::query::CycleError;
5
6pub trait Value<Tcx: DepContext>: Sized {
7    fn from_cycle_error(tcx: Tcx, cycle_error: &CycleError, guar: ErrorGuaranteed) -> Self;
8}
9
10impl<Tcx: DepContext, T> Value<Tcx> for T {
11    default fn from_cycle_error(tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed) -> T {
12        tcx.sess().dcx().abort_if_errors();
13        // Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
14        // non-trivial to define it earlier.
15        panic!(
16            "<{} as Value>::from_cycle_error called without errors: {:#?}",
17            std::any::type_name::<T>(),
18            cycle_error.cycle,
19        );
20    }
21}