Skip to content

Commit 0156eaf

Browse files
committed
Introduce indexvec macro.
1 parent 51275e8 commit 0156eaf

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

compiler/rustc_index/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,13 @@ macro_rules! static_assert_size {
5050
const _: (usize, usize) = ($size, ::std::mem::size_of::<$ty>());
5151
};
5252
}
53+
54+
#[macro_export]
55+
macro_rules! indexvec {
56+
($expr:expr; $n:expr) => {
57+
IndexVec::from_raw(vec![$expr; $n])
58+
};
59+
($($expr:expr),* $(,)?) => {
60+
IndexVec::from_raw(vec![$($expr),*])
61+
};
62+
}

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use rustc_hir as hir;
6767
use rustc_hir::lang_items::LangItem;
6868
use rustc_hir::{CoroutineDesugaring, CoroutineKind};
6969
use rustc_index::bit_set::{BitMatrix, DenseBitSet, GrowableBitSet};
70-
use rustc_index::{Idx, IndexVec};
70+
use rustc_index::{Idx, IndexVec, indexvec};
7171
use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor};
7272
use rustc_middle::mir::*;
7373
use rustc_middle::ty::util::Discr;
@@ -289,7 +289,7 @@ impl<'tcx> TransformVisitor<'tcx> {
289289
let poll_def_id = self.tcx.require_lang_item(LangItem::Poll, source_info.span);
290290
let args = self.tcx.mk_args(&[self.old_ret_ty.into()]);
291291
let (variant_idx, operands) = if is_return {
292-
(ZERO, IndexVec::from_raw(vec![val])) // Poll::Ready(val)
292+
(ZERO, indexvec![val]) // Poll::Ready(val)
293293
} else {
294294
(ONE, IndexVec::new()) // Poll::Pending
295295
};
@@ -301,7 +301,7 @@ impl<'tcx> TransformVisitor<'tcx> {
301301
let (variant_idx, operands) = if is_return {
302302
(ZERO, IndexVec::new()) // None
303303
} else {
304-
(ONE, IndexVec::from_raw(vec![val])) // Some(val)
304+
(ONE, indexvec![val]) // Some(val)
305305
};
306306
make_aggregate_adt(option_def_id, variant_idx, args, operands)
307307
}
@@ -337,12 +337,7 @@ impl<'tcx> TransformVisitor<'tcx> {
337337
} else {
338338
ZERO // CoroutineState::Yielded(val)
339339
};
340-
make_aggregate_adt(
341-
coroutine_state_def_id,
342-
variant_idx,
343-
args,
344-
IndexVec::from_raw(vec![val]),
345-
)
340+
make_aggregate_adt(coroutine_state_def_id, variant_idx, args, indexvec![val])
346341
}
347342
};
348343

@@ -1122,7 +1117,7 @@ fn return_poll_ready_assign<'tcx>(tcx: TyCtxt<'tcx>, source_info: SourceInfo) ->
11221117
}));
11231118
let ready_val = Rvalue::Aggregate(
11241119
Box::new(AggregateKind::Adt(poll_def_id, VariantIdx::from_usize(0), args, None, None)),
1125-
IndexVec::from_raw(vec![val]),
1120+
indexvec![val],
11261121
);
11271122
Statement::new(source_info, StatementKind::Assign(Box::new((Place::return_place(), ready_val))))
11281123
}

compiler/rustc_mir_transform/src/elaborate_box_derefs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! contents, we do not need this any more on runtime MIR.
77
88
use rustc_abi::{FieldIdx, VariantIdx};
9-
use rustc_index::IndexVec;
9+
use rustc_index::{IndexVec, indexvec};
1010
use rustc_middle::mir::visit::MutVisitor;
1111
use rustc_middle::mir::*;
1212
use rustc_middle::span_bug;
@@ -127,7 +127,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> {
127127
nonnull.into(),
128128
Rvalue::Aggregate(
129129
adt_kind(self.nonnull_def, args),
130-
IndexVec::from_raw(vec![Operand::Move(constptr.into())]),
130+
indexvec![Operand::Move(constptr.into())],
131131
),
132132
);
133133

@@ -139,15 +139,15 @@ impl<'a, 'tcx> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'a, 'tcx> {
139139
unique.into(),
140140
Rvalue::Aggregate(
141141
adt_kind(self.unique_def, args),
142-
IndexVec::from_raw(vec![Operand::Move(nonnull.into()), zst(phantomdata_ty)]),
142+
indexvec![Operand::Move(nonnull.into()), zst(phantomdata_ty)],
143143
),
144144
);
145145

146146
let global_alloc_ty =
147147
box_adt.non_enum_variant().fields[FieldIdx::ONE].ty(tcx, box_args);
148148
*rvalue = Rvalue::Aggregate(
149149
adt_kind(*box_adt, box_args),
150-
IndexVec::from_raw(vec![Operand::Move(unique.into()), zst(global_alloc_ty)]),
150+
indexvec![Operand::Move(unique.into()), zst(global_alloc_ty)],
151151
);
152152
}
153153
}

0 commit comments

Comments
 (0)