Rollup merge of #109621 - scottmcm:update-variantidx, r=compiler-errors
Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT` Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since [it doesn't have any today](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/struct.VariantIdx.html).
This commit is contained in:
commit
4aa4ce6ee2
25 changed files with 80 additions and 78 deletions
|
@ -10,11 +10,11 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::DataTypeKind;
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_target::abi::{ReprOptions, VariantIdx};
|
||||
use rustc_target::abi::{ReprOptions, VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::cmp::Ordering;
|
||||
|
@ -228,7 +228,7 @@ impl AdtDefData {
|
|||
AdtKind::Struct => AdtFlags::IS_STRUCT,
|
||||
};
|
||||
|
||||
if kind == AdtKind::Struct && variants[VariantIdx::new(0)].ctor.is_some() {
|
||||
if kind == AdtKind::Struct && variants[FIRST_VARIANT].ctor.is_some() {
|
||||
flags |= AdtFlags::HAS_CTOR;
|
||||
}
|
||||
|
||||
|
@ -357,7 +357,7 @@ impl<'tcx> AdtDef<'tcx> {
|
|||
/// Asserts this is a struct or union and returns its unique variant.
|
||||
pub fn non_enum_variant(self) -> &'tcx VariantDef {
|
||||
assert!(self.is_struct() || self.is_union());
|
||||
&self.variant(VariantIdx::new(0))
|
||||
&self.variant(FIRST_VARIANT)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -493,7 +493,7 @@ impl<'tcx> AdtDef<'tcx> {
|
|||
|
||||
#[inline]
|
||||
pub fn variant_range(self) -> Range<VariantIdx> {
|
||||
VariantIdx::new(0)..VariantIdx::new(self.variants().len())
|
||||
FIRST_VARIANT..self.variants().next_index()
|
||||
}
|
||||
|
||||
/// Computes the discriminant value used by a specific variant.
|
||||
|
|
|
@ -22,7 +22,7 @@ use rustc_index::vec::Idx;
|
|||
use rustc_macros::HashStable;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
|
||||
use rustc_target::spec::abi::{self, Abi};
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::Ordering;
|
||||
|
@ -517,8 +517,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
|
|||
#[inline]
|
||||
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
|
||||
// FIXME requires optimized MIR
|
||||
let num_variants = tcx.generator_layout(def_id).unwrap().variant_fields.len();
|
||||
VariantIdx::new(0)..VariantIdx::new(num_variants)
|
||||
FIRST_VARIANT..tcx.generator_layout(def_id).unwrap().variant_fields.next_index()
|
||||
}
|
||||
|
||||
/// The discriminant for the given variant. Panics if the `variant_index` is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue