about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/const_eval
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-26 08:39:28 +0200
committerGitHub <noreply@github.com>2023-03-26 08:39:28 +0200
commit4aa4ce6ee26045f74f28d6a5067d01bf54221616 (patch)
tree3808129509fbe0bc71c4be45b5fddef1c678c4de /compiler/rustc_const_eval/src/const_eval
parent776a8f4ecae4292b064987f10b01b4e2e81fc2f4 (diff)
parent0439d131768081174fe4ed53a6f09d41a9e5629f (diff)
downloadrust-4aa4ce6ee26045f74f28d6a5067d01bf54221616.tar.gz
rust-4aa4ce6ee26045f74f28d6a5067d01bf54221616.zip
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).
Diffstat (limited to 'compiler/rustc_const_eval/src/const_eval')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/valtrees.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
index a73f778d4db..8e4454d7cec 100644
--- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs
+++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs
@@ -8,7 +8,7 @@ use crate::interpret::{
 use crate::interpret::{MPlaceTy, Value};
 use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
 use rustc_span::source_map::DUMMY_SP;
-use rustc_target::abi::{Align, VariantIdx};
+use rustc_target::abi::{Align, VariantIdx, FIRST_VARIANT};
 
 #[instrument(skip(ecx), level = "debug")]
 fn branches<'tcx>(
@@ -412,7 +412,7 @@ fn valtree_into_mplace<'tcx>(
 
                         let inner_ty = match ty.kind() {
                             ty::Adt(def, substs) => {
-                                def.variant(VariantIdx::from_u32(0)).fields[i].ty(tcx, substs)
+                                def.variant(FIRST_VARIANT).fields[i].ty(tcx, substs)
                             }
                             ty::Tuple(inner_tys) => inner_tys[i],
                             _ => bug!("unexpected unsized type {:?}", ty),