diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-27 09:38:18 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-27 09:38:18 +0200 |
| commit | c33b4f870e773effd9a339b37b7cd9475f71ba6a (patch) | |
| tree | b3307c0d6bf64a1b2ec05c150fb6110c148bca62 | |
| parent | 496145b9cc023aef4bb1f16c0964a53d0da36c88 (diff) | |
| download | rust-c33b4f870e773effd9a339b37b7cd9475f71ba6a.tar.gz rust-c33b4f870e773effd9a339b37b7cd9475f71ba6a.zip | |
Use `search_for_cycle_permutation` to look for `variances_of`
| -rw-r--r-- | compiler/rustc_middle/src/values.rs | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 39fcc686c55..4d70a708732 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -138,18 +138,26 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] { 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]`" + ) + }, + ) } } |
