Rollup merge of #139811 - yotamofek:pr/newtype_cleanups, r=oli-obk
Use `newtype_index!`-generated types more idiomatically Continuation of sorts of #139674 Shouldn't affect anything, just makes some code simpler
This commit is contained in:
commit
04d10520f0
20 changed files with 61 additions and 87 deletions
|
@ -203,7 +203,7 @@ struct TransformVisitor<'tcx> {
|
|||
|
||||
impl<'tcx> TransformVisitor<'tcx> {
|
||||
fn insert_none_ret_block(&self, body: &mut Body<'tcx>) -> BasicBlock {
|
||||
let block = BasicBlock::new(body.basic_blocks.len());
|
||||
let block = body.basic_blocks.next_index();
|
||||
let source_info = SourceInfo::outermost(body.span);
|
||||
|
||||
let none_value = match self.coroutine_kind {
|
||||
|
@ -1193,7 +1193,7 @@ fn insert_panic_block<'tcx>(
|
|||
body: &mut Body<'tcx>,
|
||||
message: AssertMessage<'tcx>,
|
||||
) -> BasicBlock {
|
||||
let assert_block = BasicBlock::new(body.basic_blocks.len());
|
||||
let assert_block = body.basic_blocks.next_index();
|
||||
let kind = TerminatorKind::Assert {
|
||||
cond: Operand::Constant(Box::new(ConstOperand {
|
||||
span: body.span,
|
||||
|
|
|
@ -258,17 +258,16 @@ where
|
|||
) -> Vec<(Place<'tcx>, Option<D::Path>)> {
|
||||
variant
|
||||
.fields
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, f)| {
|
||||
let field = FieldIdx::new(i);
|
||||
let subpath = self.elaborator.field_subpath(variant_path, field);
|
||||
.iter_enumerated()
|
||||
.map(|(field_idx, field)| {
|
||||
let subpath = self.elaborator.field_subpath(variant_path, field_idx);
|
||||
let tcx = self.tcx();
|
||||
|
||||
assert_eq!(self.elaborator.typing_env().typing_mode, ty::TypingMode::PostAnalysis);
|
||||
let field_ty = match tcx
|
||||
.try_normalize_erasing_regions(self.elaborator.typing_env(), f.ty(tcx, args))
|
||||
{
|
||||
let field_ty = match tcx.try_normalize_erasing_regions(
|
||||
self.elaborator.typing_env(),
|
||||
field.ty(tcx, args),
|
||||
) {
|
||||
Ok(t) => t,
|
||||
Err(_) => Ty::new_error(
|
||||
self.tcx(),
|
||||
|
@ -279,7 +278,7 @@ where
|
|||
),
|
||||
};
|
||||
|
||||
(tcx.mk_place_field(base_place, field, field_ty), subpath)
|
||||
(tcx.mk_place_field(base_place, field_idx, field_ty), subpath)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
@ -903,9 +903,9 @@ fn inline_call<'tcx, I: Inliner<'tcx>>(
|
|||
|
||||
let mut integrator = Integrator {
|
||||
args: &args,
|
||||
new_locals: Local::new(caller_body.local_decls.len())..,
|
||||
new_scopes: SourceScope::new(caller_body.source_scopes.len())..,
|
||||
new_blocks: BasicBlock::new(caller_body.basic_blocks.len())..,
|
||||
new_locals: caller_body.local_decls.next_index()..,
|
||||
new_scopes: caller_body.source_scopes.next_index()..,
|
||||
new_blocks: caller_body.basic_blocks.next_index()..,
|
||||
destination: destination_local,
|
||||
callsite_scope: caller_body.source_scopes[callsite.source_info.scope].clone(),
|
||||
callsite,
|
||||
|
@ -1169,7 +1169,7 @@ impl Integrator<'_, '_> {
|
|||
if idx < self.args.len() {
|
||||
self.args[idx]
|
||||
} else {
|
||||
Local::new(self.new_locals.start.index() + (idx - self.args.len()))
|
||||
self.new_locals.start + (idx - self.args.len())
|
||||
}
|
||||
};
|
||||
trace!("mapping local `{:?}` to `{:?}`", local, new);
|
||||
|
@ -1177,13 +1177,13 @@ impl Integrator<'_, '_> {
|
|||
}
|
||||
|
||||
fn map_scope(&self, scope: SourceScope) -> SourceScope {
|
||||
let new = SourceScope::new(self.new_scopes.start.index() + scope.index());
|
||||
let new = self.new_scopes.start + scope.index();
|
||||
trace!("mapping scope `{:?}` to `{:?}`", scope, new);
|
||||
new
|
||||
}
|
||||
|
||||
fn map_block(&self, block: BasicBlock) -> BasicBlock {
|
||||
let new = BasicBlock::new(self.new_blocks.start.index() + block.index());
|
||||
let new = self.new_blocks.start + block.index();
|
||||
trace!("mapping block `{:?}` to `{:?}`", block, new);
|
||||
new
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ impl<'tcx> MirPatch<'tcx> {
|
|||
|
||||
/// Queues the addition of a new basic block.
|
||||
pub(crate) fn new_block(&mut self, data: BasicBlockData<'tcx>) -> BasicBlock {
|
||||
let block = BasicBlock::new(self.term_patch_map.len());
|
||||
let block = self.term_patch_map.next_index();
|
||||
debug!("MirPatch: new_block: {:?}: {:?}", block, data);
|
||||
self.new_blocks.push(data);
|
||||
self.term_patch_map.push(None);
|
||||
|
|
|
@ -18,7 +18,7 @@ use either::{Left, Right};
|
|||
use rustc_const_eval::check_consts::{ConstCx, qualifs};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{self, GenericArgs, List, Ty, TyCtxt, TypeVisitableExt};
|
||||
|
@ -864,17 +864,21 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||
new_temp
|
||||
}
|
||||
|
||||
fn promote_candidate(mut self, candidate: Candidate, next_promoted_id: usize) -> Body<'tcx> {
|
||||
fn promote_candidate(
|
||||
mut self,
|
||||
candidate: Candidate,
|
||||
next_promoted_index: Promoted,
|
||||
) -> Body<'tcx> {
|
||||
let def = self.source.source.def_id();
|
||||
let (mut rvalue, promoted_op) = {
|
||||
let promoted = &mut self.promoted;
|
||||
let promoted_id = Promoted::new(next_promoted_id);
|
||||
let tcx = self.tcx;
|
||||
let mut promoted_operand = |ty, span| {
|
||||
promoted.span = span;
|
||||
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
|
||||
let args = tcx.erase_regions(GenericArgs::identity_for_item(tcx, def));
|
||||
let uneval = mir::UnevaluatedConst { def, args, promoted: Some(promoted_id) };
|
||||
let uneval =
|
||||
mir::UnevaluatedConst { def, args, promoted: Some(next_promoted_index) };
|
||||
|
||||
ConstOperand { span, user_ty: None, const_: Const::Unevaluated(uneval, ty) }
|
||||
};
|
||||
|
@ -1034,7 +1038,7 @@ fn promote_candidates<'tcx>(
|
|||
required_consts: Vec::new(),
|
||||
};
|
||||
|
||||
let mut promoted = promoter.promote_candidate(candidate, promotions.len());
|
||||
let mut promoted = promoter.promote_candidate(candidate, promotions.next_index());
|
||||
promoted.source.promoted = Some(promotions.next_index());
|
||||
promotions.push(promoted);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue