Skip to content

Commit bb5ac03

Browse files
committed
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.
1 parent 7ac6cc9 commit bb5ac03

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ fn codegen_stmt<'tcx>(
785785
let variant_dest = lval.downcast_variant(fx, variant_index);
786786
(variant_index, variant_dest, active_field_index)
787787
}
788-
_ => (VariantIdx::from_u32(0), lval, None),
788+
_ => (FIRST_VARIANT, lval, None),
789789
};
790790
if active_field_index.is_some() {
791791
assert_eq!(operands.len(), 1);

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mod prelude {
8686
self, FloatTy, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut,
8787
TypeFoldable, TypeVisitableExt, UintTy,
8888
};
89-
pub(crate) use rustc_target::abi::{Abi, Scalar, Size, VariantIdx};
89+
pub(crate) use rustc_target::abi::{Abi, Scalar, Size, VariantIdx, FIRST_VARIANT};
9090

9191
pub(crate) use rustc_data_structures::fx::FxHashMap;
9292

src/unsize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub(crate) fn coerce_unsized_into<'tcx>(
146146
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
147147
assert_eq!(def_a, def_b);
148148

149-
for i in 0..def_a.variant(VariantIdx::new(0)).fields.len() {
149+
for i in 0..def_a.variant(FIRST_VARIANT).fields.len() {
150150
let src_f = src.value_field(fx, mir::Field::new(i));
151151
let dst_f = dst.place_field(fx, mir::Field::new(i));
152152

0 commit comments

Comments
 (0)