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.
This commit is contained in:
parent
96bd50dd47
commit
0439d13176
25 changed files with 80 additions and 78 deletions
|
@ -8,7 +8,7 @@ use rustc_middle::ty::abstract_const::CastKind;
|
|||
use rustc_middle::ty::{self, Expr, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::{mir, thir};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use std::iter;
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub(crate) fn destructure_const<'tcx>(
|
|||
let (head, rest) = branches.split_first().unwrap();
|
||||
(VariantIdx::from_u32(head.unwrap_leaf().try_to_u32().unwrap()), rest)
|
||||
} else {
|
||||
(VariantIdx::from_u32(0), branches)
|
||||
(FIRST_VARIANT, branches)
|
||||
};
|
||||
let fields = &def.variant(variant_idx).fields;
|
||||
let mut field_consts = Vec::with_capacity(fields.len());
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use hir::def_id::DefId;
|
||||
use rustc_hir as hir;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::{GeneratorLayout, GeneratorSavedLocal};
|
||||
use rustc_middle::ty::layout::{
|
||||
IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES,
|
||||
|
@ -227,7 +227,7 @@ fn layout_of_uncached<'tcx>(
|
|||
let largest_niche = if count != 0 { element.largest_niche } else { None };
|
||||
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
variants: Variants::Single { index: FIRST_VARIANT },
|
||||
fields: FieldsShape::Array { stride: element.size, count },
|
||||
abi,
|
||||
largest_niche,
|
||||
|
@ -238,7 +238,7 @@ fn layout_of_uncached<'tcx>(
|
|||
ty::Slice(element) => {
|
||||
let element = cx.layout_of(element)?;
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
variants: Variants::Single { index: FIRST_VARIANT },
|
||||
fields: FieldsShape::Array { stride: element.size, count: 0 },
|
||||
abi: Abi::Aggregate { sized: false },
|
||||
largest_niche: None,
|
||||
|
@ -247,7 +247,7 @@ fn layout_of_uncached<'tcx>(
|
|||
})
|
||||
}
|
||||
ty::Str => tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
variants: Variants::Single { index: FIRST_VARIANT },
|
||||
fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 },
|
||||
abi: Abi::Aggregate { sized: false },
|
||||
largest_niche: None,
|
||||
|
@ -399,7 +399,7 @@ fn layout_of_uncached<'tcx>(
|
|||
};
|
||||
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: VariantIdx::new(0) },
|
||||
variants: Variants::Single { index: FIRST_VARIANT },
|
||||
fields,
|
||||
abi: Abi::Vector { element: e_abi, count: e_len },
|
||||
largest_niche: e_ly.largest_niche,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue