Make from_cycle_error consume the CycleError.

This makes it clear the `CycleError` is not used after the call.
This commit is contained in:
Nicholas Nethercote
2026-02-27 10:31:32 +11:00
parent cc1b878386
commit c0770baed8
3 changed files with 17 additions and 30 deletions
+2 -2
View File
@@ -151,7 +151,7 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
pub hash_value_fn: Option<fn(&mut StableHashingContext<'_>, &C::Value) -> Fingerprint>,
pub value_from_cycle_error:
fn(tcx: TyCtxt<'tcx>, cycle_error: &CycleError, guar: ErrorGuaranteed) -> C::Value,
fn(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> C::Value,
pub format_value: fn(&C::Value) -> String,
/// Formats a human-readable description of this query and its key, as
@@ -216,7 +216,7 @@ pub fn is_loadable_from_disk(
pub fn value_from_cycle_error(
&self,
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
cycle_error: CycleError,
guar: ErrorGuaranteed,
) -> C::Value {
(self.value_from_cycle_error)(tcx, cycle_error, guar)
+3 -3
View File
@@ -129,7 +129,7 @@ fn mk_cycle<'tcx, C: QueryCache>(
match query.cycle_error_handling {
CycleErrorHandling::Error => {
let guar = error.emit();
query.value_from_cycle_error(tcx, &cycle_error, guar)
query.value_from_cycle_error(tcx, cycle_error, guar)
}
CycleErrorHandling::Fatal => {
error.emit();
@@ -138,7 +138,7 @@ fn mk_cycle<'tcx, C: QueryCache>(
}
CycleErrorHandling::DelayBug => {
let guar = error.delay_as_bug();
query.value_from_cycle_error(tcx, &cycle_error, guar)
query.value_from_cycle_error(tcx, cycle_error, guar)
}
CycleErrorHandling::Stash => {
let guar = if let Some(root) = cycle_error.cycle.first()
@@ -148,7 +148,7 @@ fn mk_cycle<'tcx, C: QueryCache>(
} else {
error.emit()
};
query.value_from_cycle_error(tcx, &cycle_error, guar)
query.value_from_cycle_error(tcx, cycle_error, guar)
}
}
}
+12 -25
View File
@@ -18,14 +18,13 @@
use crate::job::report_cycle;
pub(crate) trait Value<'tcx>: Sized {
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: &CycleError, guar: ErrorGuaranteed)
-> Self;
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self;
}
impl<'tcx, T> Value<'tcx> for T {
default fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
cycle_error: CycleError,
_guar: ErrorGuaranteed,
) -> T {
tcx.sess.dcx().abort_if_errors();
@@ -38,7 +37,7 @@ impl<'tcx, T> Value<'tcx> for T {
}
impl<'tcx> Value<'tcx> for Ty<'_> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) -> Self {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: CycleError, guar: ErrorGuaranteed) -> Self {
// SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
// FIXME: Represent the above fact in the trait system somehow.
unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(Ty::new_error(tcx, guar)) }
@@ -46,13 +45,13 @@ fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) ->
}
impl<'tcx> Value<'tcx> for Result<ty::EarlyBinder<'_, Ty<'_>>, CyclePlaceholder> {
fn from_cycle_error(_tcx: TyCtxt<'tcx>, _: &CycleError, guar: ErrorGuaranteed) -> Self {
fn from_cycle_error(_tcx: TyCtxt<'tcx>, _: CycleError, guar: ErrorGuaranteed) -> Self {
Err(CyclePlaceholder(guar))
}
}
impl<'tcx> Value<'tcx> for ty::SymbolName<'_> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, _guar: ErrorGuaranteed) -> Self {
fn from_cycle_error(tcx: TyCtxt<'tcx>, _: CycleError, _guar: ErrorGuaranteed) -> Self {
// SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`.
// FIXME: Represent the above fact in the trait system somehow.
unsafe {
@@ -64,11 +63,7 @@ fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &CycleError, _guar: ErrorGuaranteed) -
}
impl<'tcx> Value<'tcx> for ty::Binder<'_, ty::FnSig<'_>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
guar: ErrorGuaranteed,
) -> Self {
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self {
let err = Ty::new_error(tcx, guar);
let arity = if let Some(info) = cycle_error.cycle.get(0)
@@ -100,7 +95,7 @@ fn from_cycle_error(
impl<'tcx> Value<'tcx> for Representability {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
cycle_error: CycleError,
_guar: ErrorGuaranteed,
) -> Self {
let mut item_and_field_ids = Vec::new();
@@ -134,21 +129,13 @@ fn from_cycle_error(
}
impl<'tcx> Value<'tcx> for ty::EarlyBinder<'_, Ty<'_>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
guar: ErrorGuaranteed,
) -> Self {
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self {
ty::EarlyBinder::bind(Ty::from_cycle_error(tcx, cycle_error, guar))
}
}
impl<'tcx> Value<'tcx> for ty::EarlyBinder<'_, ty::Binder<'_, ty::FnSig<'_>>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
guar: ErrorGuaranteed,
) -> Self {
fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> Self {
ty::EarlyBinder::bind(ty::Binder::from_cycle_error(tcx, cycle_error, guar))
}
}
@@ -156,7 +143,7 @@ fn from_cycle_error(
impl<'tcx> Value<'tcx> for &[ty::Variance] {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
cycle_error: CycleError,
_guar: ErrorGuaranteed,
) -> Self {
search_for_cycle_permutation(
@@ -204,7 +191,7 @@ fn search_for_cycle_permutation<Q, T>(
impl<'tcx, T> Value<'tcx> for Result<T, &'_ ty::layout::LayoutError<'_>> {
fn from_cycle_error(
tcx: TyCtxt<'tcx>,
cycle_error: &CycleError,
cycle_error: CycleError,
_guar: ErrorGuaranteed,
) -> Self {
let diag = search_for_cycle_permutation(
@@ -280,7 +267,7 @@ fn from_cycle_error(
ControlFlow::Continue(())
}
},
|| report_cycle(tcx.sess, cycle_error),
|| report_cycle(tcx.sess, &cycle_error),
);
let guar = diag.emit();