Rollup merge of #140358 - Zoxc:variance-cycle, r=oli-obk

Use `search_for_cycle_permutation` to look for `variances_of`

This uses `search_for_cycle_permutation` to look for `variances_of` in case `variances_of` is not the first query in the cycle.

This may fix https://github.com/rust-lang/rust/issues/124423 and https://github.com/rust-lang/rust/issues/127971.

r? `@oli-obk`
This commit is contained in:
Matthias Krüger
2025-04-27 16:09:00 +02:00
committed by GitHub
+20 -12
View File
@@ -138,18 +138,26 @@ fn from_cycle_error(
cycle_error: &CycleError,
_guar: ErrorGuaranteed,
) -> Self {
if let Some(frame) = cycle_error.cycle.get(0)
&& frame.query.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = frame.query.def_id
{
let n = tcx.generics_of(def_id).own_params.len();
vec![ty::Bivariant; n].leak()
} else {
span_bug!(
cycle_error.usage.as_ref().unwrap().0,
"only `variances_of` returns `&[ty::Variance]`"
);
}
search_for_cycle_permutation(
&cycle_error.cycle,
|cycle| {
if let Some(frame) = cycle.get(0)
&& frame.query.dep_kind == dep_kinds::variances_of
&& let Some(def_id) = frame.query.def_id
{
let n = tcx.generics_of(def_id).own_params.len();
ControlFlow::Break(vec![ty::Bivariant; n].leak())
} else {
ControlFlow::Continue(())
}
},
|| {
span_bug!(
cycle_error.usage.as_ref().unwrap().0,
"only `variances_of` returns `&[ty::Variance]`"
)
},
)
}
}