Skip to content

Commit 3bd4372

Browse files
authored
Rollup merge of rust-lang#153709 - zetanumbers:from_cycle_error_cleanup, r=nnethercote
Fix hypothetical ICE in `variances_of` A cleanup based on rust-lang#153694. ~~This PR changes panic messages in `fn_sig`'s `value_from_cycle_error` to more fitting ones.~~ Also this PR makes `variances_of`'s `value_from_cycle_error` to utilize new query key argument instead of extracting it from `CycleError`. Closes rust-lang#127971 r? @nnethercote
2 parents ed170cc + 567f8bd commit 3bd4372

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

compiler/rustc_query_impl/src/from_cycle_error.rs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use rustc_errors::codes::*;
88
use rustc_errors::{Applicability, Diag, MultiSpan, pluralize, struct_span_code_err};
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, Res};
11+
use rustc_middle::bug;
1112
use rustc_middle::dep_graph::DepKind;
1213
use rustc_middle::queries::{QueryVTables, TaggedQueryKey};
1314
use rustc_middle::query::CycleError;
1415
use rustc_middle::query::erase::erase_val;
1516
use rustc_middle::ty::layout::LayoutError;
1617
use rustc_middle::ty::{self, Ty, TyCtxt};
17-
use rustc_middle::{bug, span_bug};
1818
use rustc_span::def_id::{DefId, LocalDefId};
1919
use rustc_span::{ErrorGuaranteed, Span};
2020

@@ -32,9 +32,9 @@ pub(crate) fn specialize_query_vtables<'tcx>(vtables: &mut QueryVTables<'tcx>) {
3232
vtables.check_representability_adt_ty.value_from_cycle_error =
3333
|tcx, _, cycle, _err| check_representability(tcx, cycle);
3434

35-
vtables.variances_of.value_from_cycle_error = |tcx, _, cycle, err| {
35+
vtables.variances_of.value_from_cycle_error = |tcx, key, _, err| {
3636
let _guar = err.delay_as_bug();
37-
erase_val(variances_of(tcx, cycle))
37+
erase_val(variances_of(tcx, key))
3838
};
3939

4040
vtables.layout_of.value_from_cycle_error = |tcx, _, cycle, err| {
@@ -105,27 +105,9 @@ fn check_representability<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>
105105
guar.raise_fatal()
106106
}
107107

108-
fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError<'tcx>) -> &'tcx [ty::Variance] {
109-
search_for_cycle_permutation(
110-
&cycle_error.cycle,
111-
|cycle| {
112-
if let Some(frame) = cycle.get(0)
113-
&& frame.node.dep_kind == DepKind::variances_of
114-
&& let Some(def_id) = frame.node.def_id
115-
{
116-
let n = tcx.generics_of(def_id).own_params.len();
117-
ControlFlow::Break(tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n)))
118-
} else {
119-
ControlFlow::Continue(())
120-
}
121-
},
122-
|| {
123-
span_bug!(
124-
cycle_error.usage.as_ref().unwrap().span,
125-
"only `variances_of` returns `&[ty::Variance]`"
126-
)
127-
},
128-
)
108+
fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [ty::Variance] {
109+
let n = tcx.generics_of(def_id).own_params.len();
110+
tcx.arena.alloc_from_iter(iter::repeat_n(ty::Bivariant, n))
129111
}
130112

131113
// Take a cycle of `Q` and try `try_cycle` on every permutation, falling back to `otherwise`.

0 commit comments

Comments
 (0)