diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs index 9d647209c6f8..f61b5cf52798 100644 --- a/compiler/rustc_index/src/lib.rs +++ b/compiler/rustc_index/src/lib.rs @@ -50,3 +50,13 @@ macro_rules! static_assert_size { const _: (usize, usize) = ($size, ::std::mem::size_of::<$ty>()); }; } + +#[macro_export] +macro_rules! indexvec { + ($expr:expr; $n:expr) => { + IndexVec::from_raw(vec![$expr; $n]) + }; + ($($expr:expr),* $(,)?) => { + IndexVec::from_raw(vec![$($expr),*]) + }; +} diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 26b6003e1095..e5e9cd192afa 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -67,7 +67,7 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::{CoroutineDesugaring, CoroutineKind}; use rustc_index::bit_set::{BitMatrix, DenseBitSet, GrowableBitSet}; -use rustc_index::{Idx, IndexVec}; +use rustc_index::{Idx, IndexVec, indexvec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::util::Discr; @@ -289,7 +289,7 @@ fn make_state( let poll_def_id = self.tcx.require_lang_item(LangItem::Poll, source_info.span); let args = self.tcx.mk_args(&[self.old_ret_ty.into()]); let (variant_idx, operands) = if is_return { - (ZERO, IndexVec::from_raw(vec![val])) // Poll::Ready(val) + (ZERO, indexvec![val]) // Poll::Ready(val) } else { (ONE, IndexVec::new()) // Poll::Pending }; @@ -301,7 +301,7 @@ fn make_state( let (variant_idx, operands) = if is_return { (ZERO, IndexVec::new()) // None } else { - (ONE, IndexVec::from_raw(vec![val])) // Some(val) + (ONE, indexvec![val]) // Some(val) }; make_aggregate_adt(option_def_id, variant_idx, args, operands) } @@ -337,12 +337,7 @@ fn make_state( } else { ZERO // CoroutineState::Yielded(val) }; - make_aggregate_adt( - coroutine_state_def_id, - variant_idx, - args, - IndexVec::from_raw(vec![val]), - ) + make_aggregate_adt(coroutine_state_def_id, variant_idx, args, indexvec![val]) } }; @@ -1122,7 +1117,7 @@ fn return_poll_ready_assign<'tcx>(tcx: TyCtxt<'tcx>, source_info: SourceInfo) -> })); let ready_val = Rvalue::Aggregate( Box::new(AggregateKind::Adt(poll_def_id, VariantIdx::from_usize(0), args, None, None)), - IndexVec::from_raw(vec![val]), + indexvec![val], ); Statement::new(source_info, StatementKind::Assign(Box::new((Place::return_place(), ready_val)))) } diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index 33aaa47a541d..808be19cbd81 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -6,7 +6,7 @@ //! contents, we do not need this any more on runtime MIR. use rustc_abi::{FieldIdx, VariantIdx}; -use rustc_index::IndexVec; +use rustc_index::{IndexVec, indexvec}; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::*; use rustc_middle::span_bug; @@ -127,7 +127,7 @@ fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { nonnull.into(), Rvalue::Aggregate( adt_kind(self.nonnull_def, args), - IndexVec::from_raw(vec![Operand::Move(constptr.into())]), + indexvec![Operand::Move(constptr.into())], ), ); @@ -139,7 +139,7 @@ fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { unique.into(), Rvalue::Aggregate( adt_kind(self.unique_def, args), - IndexVec::from_raw(vec![Operand::Move(nonnull.into()), zst(phantomdata_ty)]), + indexvec![Operand::Move(nonnull.into()), zst(phantomdata_ty)], ), ); @@ -147,7 +147,7 @@ fn visit_statement(&mut self, stmt: &mut Statement<'tcx>, location: Location) { box_adt.non_enum_variant().fields[FieldIdx::ONE].ty(tcx, box_args); *rvalue = Rvalue::Aggregate( adt_kind(*box_adt, box_args), - IndexVec::from_raw(vec![Operand::Move(unique.into()), zst(global_alloc_ty)]), + indexvec![Operand::Move(unique.into()), zst(global_alloc_ty)], ); } }