Skip to content

Commit f4a3749

Browse files
committed
expect required_const args to be consts already without promotion
1 parent ab5b9ae commit f4a3749

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compiler/rustc_mir/src/transform/promote_consts.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,14 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
226226
self.super_terminator(terminator, location);
227227

228228
match terminator.kind {
229-
TerminatorKind::Call { ref func, .. } => {
229+
TerminatorKind::Call { ref func, ref args, .. } => {
230230
if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
231231
let fn_sig = self.ccx.tcx.fn_sig(def_id);
232232
if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
233233
let name = self.ccx.tcx.item_name(def_id);
234-
// FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
234+
// FIXME: Find some way to do this without general
235+
// promotion (hard-code array literals, or compile to
236+
// `inline const`).
235237
if name.as_str().starts_with("simd_shuffle") {
236238
self.candidates
237239
.push(Candidate::Argument { bb: location.block, index: 2 });
@@ -242,7 +244,12 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
242244

243245
if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
244246
for index in constant_args {
245-
self.candidates.push(Candidate::Argument { bb: location.block, index });
247+
// FIXME perform this check in some more sensible place
248+
if !matches!(args[index], Operand::Constant(_)) {
249+
let span = terminator.source_info.span;
250+
let msg = format!("argument {} is required to be a constant", index + 1);
251+
self.ccx.tcx.sess.span_err(span, &msg);
252+
}
246253
}
247254
}
248255
}

0 commit comments

Comments
 (0)