2022-12-23 18:39:49 +05:30
|
|
|
use crate::dep_graph::{DepContext, DepKind};
|
2022-08-15 14:11:11 -05:00
|
|
|
use crate::query::QueryInfo;
|
2022-09-01 20:43:12 -05:00
|
|
|
|
2022-12-23 18:39:49 +05:30
|
|
|
pub trait Value<Tcx: DepContext, D: DepKind>: Sized {
|
|
|
|
fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo<D>]) -> Self;
|
2022-09-01 20:43:12 -05:00
|
|
|
}
|
|
|
|
|
2022-12-23 18:39:49 +05:30
|
|
|
impl<Tcx: DepContext, T, D: DepKind> Value<Tcx, D> for T {
|
2023-07-04 07:56:54 +00:00
|
|
|
default fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo<D>]) -> T {
|
2022-09-01 20:43:12 -05:00
|
|
|
tcx.sess().abort_if_errors();
|
|
|
|
// Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
|
|
|
|
// non-trivial to define it earlier.
|
2023-07-04 07:56:54 +00:00
|
|
|
panic!(
|
|
|
|
"<{} as Value>::from_cycle_error called without errors: {cycle:#?}",
|
|
|
|
std::any::type_name::<T>()
|
|
|
|
);
|
2022-09-01 20:43:12 -05:00
|
|
|
}
|
|
|
|
}
|