Rollup merge of #139494 - compiler-errors:restrict-queries, r=oli-obk

Restrict some queries by def-kind more

Random cleanup. I prefer things to assert more so as to catch bugs :)

r? oli-obk
This commit is contained in:
Matthias Krüger 2025-04-08 21:25:57 +02:00 committed by GitHub
commit 894f471d1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 26 deletions

View file

@ -14,6 +14,7 @@
//! At present, however, we do run collection across all items in the
//! crate as a kind of pass. This should eventually be factored away.
use std::assert_matches::assert_matches;
use std::cell::Cell;
use std::iter;
use std::ops::Bound;
@ -1344,7 +1345,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
compute_sig_of_foreign_fn_decl(tcx, def_id, sig.decl, abi, sig.header.safety())
}
Ctor(data) | Variant(hir::Variant { data, .. }) if data.ctor().is_some() => {
Ctor(data) => {
assert_matches!(data.ctor(), Some(_));
let adt_def_id = tcx.hir_get_parent_item(hir_id).def_id.to_def_id();
let ty = tcx.type_of(adt_def_id).instantiate_identity();
let inputs = data.fields().iter().map(|f| tcx.type_of(f.def_id).instantiate_identity());

View file

@ -44,13 +44,13 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
return &[];
}
match tcx.def_kind(item_def_id) {
let kind = tcx.def_kind(item_def_id);
match kind {
DefKind::Fn
| DefKind::AssocFn
| DefKind::Enum
| DefKind::Struct
| DefKind::Union
| DefKind::Variant
| DefKind::Ctor(..) => {
// These are inferred.
let crate_map = tcx.crate_variances(());
@ -89,7 +89,11 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
}
// Variance not relevant.
span_bug!(tcx.def_span(item_def_id), "asked to compute variance for wrong kind of item");
span_bug!(
tcx.def_span(item_def_id),
"asked to compute variance for {}",
kind.descr(item_def_id.to_def_id())
);
}
#[derive(Debug, Copy, Clone)]