Skip to content

Commit fdfc7c0

Browse files
authored
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 #124423 and #127971. r? `@oli-obk`
2 parents c006eb7 + c33b4f8 commit fdfc7c0

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

compiler/rustc_middle/src/values.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,26 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
138138
cycle_error: &CycleError,
139139
_guar: ErrorGuaranteed,
140140
) -> Self {
141-
if let Some(frame) = cycle_error.cycle.get(0)
142-
&& frame.query.dep_kind == dep_kinds::variances_of
143-
&& let Some(def_id) = frame.query.def_id
144-
{
145-
let n = tcx.generics_of(def_id).own_params.len();
146-
vec![ty::Bivariant; n].leak()
147-
} else {
148-
span_bug!(
149-
cycle_error.usage.as_ref().unwrap().0,
150-
"only `variances_of` returns `&[ty::Variance]`"
151-
);
152-
}
141+
search_for_cycle_permutation(
142+
&cycle_error.cycle,
143+
|cycle| {
144+
if let Some(frame) = cycle.get(0)
145+
&& frame.query.dep_kind == dep_kinds::variances_of
146+
&& let Some(def_id) = frame.query.def_id
147+
{
148+
let n = tcx.generics_of(def_id).own_params.len();
149+
ControlFlow::Break(vec![ty::Bivariant; n].leak())
150+
} else {
151+
ControlFlow::Continue(())
152+
}
153+
},
154+
|| {
155+
span_bug!(
156+
cycle_error.usage.as_ref().unwrap().0,
157+
"only `variances_of` returns `&[ty::Variance]`"
158+
)
159+
},
160+
)
153161
}
154162
}
155163

0 commit comments

Comments
 (0)