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
|
@ -13,9 +13,7 @@ use rustc_middle::thir::*;
|
|||
use rustc_middle::ty::AdtDef;
|
||||
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty, Variance};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_target::abi::{VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use std::assert_matches::assert_matches;
|
||||
use std::iter;
|
||||
|
@ -91,7 +89,7 @@ fn convert_to_hir_projections_and_truncate_for_capture(
|
|||
let hir_projection = match mir_projection {
|
||||
ProjectionElem::Deref => HirProjectionKind::Deref,
|
||||
ProjectionElem::Field(field, _) => {
|
||||
let variant = variant.unwrap_or(VariantIdx::new(0));
|
||||
let variant = variant.unwrap_or(FIRST_VARIANT);
|
||||
HirProjectionKind::Field(field.index() as u32, variant)
|
||||
}
|
||||
ProjectionElem::Downcast(.., idx) => {
|
||||
|
|
|
@ -20,7 +20,7 @@ use rustc_middle::ty::{
|
|||
self, AdtKind, InlineConstSubsts, InlineConstSubstsParts, ScalarInt, Ty, UpvarSubsts, UserType,
|
||||
};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
use rustc_target::abi::FIRST_VARIANT;
|
||||
|
||||
impl<'tcx> Cx<'tcx> {
|
||||
pub(crate) fn mirror_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> ExprId {
|
||||
|
@ -357,7 +357,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
|
||||
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
|
||||
}
|
||||
Res::SelfCtor(..) => Some((adt_def, VariantIdx::new(0))),
|
||||
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
|
||||
_ => None,
|
||||
})
|
||||
} else {
|
||||
|
@ -510,7 +510,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
|
||||
ExprKind::Adt(Box::new(AdtExpr {
|
||||
adt_def: *adt,
|
||||
variant_index: VariantIdx::new(0),
|
||||
variant_index: FIRST_VARIANT,
|
||||
substs,
|
||||
user_ty,
|
||||
fields: self.field_refs(fields),
|
||||
|
@ -732,7 +732,7 @@ impl<'tcx> Cx<'tcx> {
|
|||
}
|
||||
hir::ExprKind::Field(ref source, ..) => ExprKind::Field {
|
||||
lhs: self.mirror_expr(source),
|
||||
variant_index: VariantIdx::new(0),
|
||||
variant_index: FIRST_VARIANT,
|
||||
name: Field::new(self.typeck_results.field_index(expr.hir_id)),
|
||||
},
|
||||
hir::ExprKind::Cast(ref source, ref cast_ty) => {
|
||||
|
|
|
@ -60,7 +60,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
|
|||
use rustc_middle::{middle::stability::EvalResult, mir::interpret::ConstValue};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{Integer, Size, VariantIdx};
|
||||
use rustc_target::abi::{Integer, Size, VariantIdx, FIRST_VARIANT};
|
||||
|
||||
use self::Constructor::*;
|
||||
use self::SliceKind::*;
|
||||
|
@ -706,7 +706,7 @@ impl<'tcx> Constructor<'tcx> {
|
|||
Variant(idx) => idx,
|
||||
Single => {
|
||||
assert!(!adt.is_enum());
|
||||
VariantIdx::new(0)
|
||||
FIRST_VARIANT
|
||||
}
|
||||
_ => bug!("bad constructor {:?} for adt {:?}", self, adt),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue