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:
Scott McMurray 2023-03-25 18:43:03 -07:00
parent 96bd50dd47
commit 0439d13176
25 changed files with 80 additions and 78 deletions

View file

@ -7,7 +7,7 @@ use rustc_middle::traits::Reveal;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_target::abi::VariantIdx;
use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
use std::{fmt, iter};
/// The value of an inserted drop flag.
@ -468,7 +468,7 @@ where
let fields = self.move_paths_for_fields(
self.place,
self.path,
&adt.variant(VariantIdx::new(0)),
&adt.variant(FIRST_VARIANT),
substs,
);
self.drop_ladder(fields, succ, unwind)
@ -894,7 +894,7 @@ where
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
let free_func = tcx.require_lang_item(LangItem::BoxFree, Some(self.source_info.span));
let args = adt
.variant(VariantIdx::new(0))
.variant(FIRST_VARIANT)
.fields
.iter()
.enumerate()