-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Update ty::VariantDef
to use IndexVec<FieldIdx, FieldDef>
#109762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ use rustc_span::edit_distance::find_best_match_for_name; | |
use rustc_span::hygiene::DesugaringKind; | ||
use rustc_span::source_map::{Span, Spanned}; | ||
use rustc_span::symbol::{kw, sym, Ident, Symbol}; | ||
use rustc_target::abi::FieldIdx; | ||
use rustc_target::spec::abi::Abi::RustIntrinsic; | ||
use rustc_trait_selection::infer::InferCtxtExt; | ||
use rustc_trait_selection::traits::{self, ObligationCauseCode}; | ||
|
@@ -1561,8 +1562,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
|
||
let mut remaining_fields = variant | ||
.fields | ||
.iter() | ||
.enumerate() | ||
.iter_enumerated() | ||
.map(|(i, field)| (field.ident(tcx).normalize_to_macros_2_0(), (i, field))) | ||
.collect::<FxHashMap<_, _>>(); | ||
|
||
|
@@ -1815,7 +1815,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
&self, | ||
adt_ty: Ty<'tcx>, | ||
span: Span, | ||
remaining_fields: FxHashMap<Ident, (usize, &ty::FieldDef)>, | ||
remaining_fields: FxHashMap<Ident, (FieldIdx, &ty::FieldDef)>, | ||
variant: &'tcx ty::VariantDef, | ||
ast_fields: &'tcx [hir::ExprField<'tcx>], | ||
substs: SubstsRef<'tcx>, | ||
|
@@ -2209,11 +2209,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
let (ident, def_scope) = | ||
self.tcx.adjust_ident_and_get_scope(field, base_def.did(), body_hir_id); | ||
let fields = &base_def.non_enum_variant().fields; | ||
if let Some(index) = fields | ||
.iter() | ||
.position(|f| f.ident(self.tcx).normalize_to_macros_2_0() == ident) | ||
if let Some((index, field)) = fields | ||
.iter_enumerated() | ||
.find(|(_, f)| f.ident(self.tcx).normalize_to_macros_2_0() == ident) | ||
{ | ||
let field = &fields[index]; | ||
let field_ty = self.field_ty(expr.span, field, substs); | ||
// Save the index of all fields regardless of their visibility in case | ||
// of error recovery. | ||
|
@@ -2230,15 +2229,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
} | ||
} | ||
ty::Tuple(tys) => { | ||
let fstr = field.as_str(); | ||
if let Ok(index) = fstr.parse::<usize>() { | ||
if fstr == index.to_string() { | ||
if let Ok(index) = field.as_str().parse::<usize>() { | ||
if field.name == sym::integer(index) { | ||
if let Some(&field_ty) = tys.get(index) { | ||
let adjustments = self.adjust_steps(&autoderef); | ||
self.apply_adjustments(base, adjustments); | ||
self.register_predicates(autoderef.into_obligations()); | ||
|
||
self.write_field_index(expr.hir_id, index); | ||
self.write_field_index(expr.hir_id, FieldIdx::from_usize(index)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes me wonder why do we need such cruel string manipulation few lines above O_o There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like it's because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aha, found a little tweak that should be clearer and avoid the field.name == sym::integer(index) |
||
return field_ty; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the kind of place that will hopefully be temporary -- changing
AggregateKind::Adt
to hold aFieldIdx
and the function to usefield_index: FieldIdx
instead offield_index: usize
should get rid of this in an upcoming PR in this series, but I needed to stop the tendrils somewhere 🙃