/// the attribute currently provides the semantic requirement that arguments
/// must be constant.
Argument { bb: BasicBlock, index: usize },
-
- /// `const` operand in asm!.
- InlineAsm { bb: BasicBlock, index: usize },
}
impl Candidate {
fn forces_explicit_promotion(&self) -> bool {
match self {
Candidate::Ref(_) => false,
- Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true,
+ Candidate::Argument { .. } => true,
}
}
fn source_info(&self, body: &Body<'_>) -> SourceInfo {
match self {
Candidate::Ref(location) => *body.source_info(*location),
- Candidate::Argument { bb, .. } | Candidate::InlineAsm { bb, .. } => {
- *body.source_info(body.terminator_loc(*bb))
- }
+ Candidate::Argument { bb, .. } => *body.source_info(body.terminator_loc(*bb)),
}
}
}
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
self.super_terminator(terminator, location);
- match terminator.kind {
- TerminatorKind::Call { ref func, .. } => {
- if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
- let fn_sig = self.ccx.tcx.fn_sig(def_id);
- if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
- let name = self.ccx.tcx.item_name(def_id);
- // FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
- if name.as_str().starts_with("simd_shuffle") {
- self.candidates
- .push(Candidate::Argument { bb: location.block, index: 2 });
-
- return; // Don't double count `simd_shuffle` candidates
- }
- }
+ if let TerminatorKind::Call { ref func, .. } = terminator.kind {
+ if let ty::FnDef(def_id, _) = *func.ty(self.ccx.body, self.ccx.tcx).kind() {
+ let fn_sig = self.ccx.tcx.fn_sig(def_id);
+ if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = fn_sig.abi() {
+ let name = self.ccx.tcx.item_name(def_id);
+ // FIXME(eddyb) use `#[rustc_args_required_const(2)]` for shuffles.
+ if name.as_str().starts_with("simd_shuffle") {
+ self.candidates.push(Candidate::Argument { bb: location.block, index: 2 });
- if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
- for index in constant_args {
- self.candidates.push(Candidate::Argument { bb: location.block, index });
- }
+ return; // Don't double count `simd_shuffle` candidates
}
}
- }
- TerminatorKind::InlineAsm { ref operands, .. } => {
- for (index, op) in operands.iter().enumerate() {
- if let InlineAsmOperand::Const { .. } = op {
- self.candidates.push(Candidate::InlineAsm { bb: location.block, index })
+
+ if let Some(constant_args) = args_required_const(self.ccx.tcx, def_id) {
+ for index in constant_args {
+ self.candidates.push(Candidate::Argument { bb: location.block, index });
}
}
}
- _ => {}
}
}
}
_ => bug!(),
}
}
- Candidate::InlineAsm { bb, index } => {
- assert!(self.explicit);
-
- let terminator = self.body[bb].terminator();
- match &terminator.kind {
- TerminatorKind::InlineAsm { operands, .. } => match &operands[index] {
- InlineAsmOperand::Const { value } => self.validate_operand(value),
- _ => bug!(),
- },
- _ => bug!(),
- }
- }
}
}
}
match candidate {
- Candidate::Argument { bb, index } | Candidate::InlineAsm { bb, index }
- if !is_promotable =>
- {
+ Candidate::Argument { bb, index } if !is_promotable => {
let span = ccx.body[bb].terminator().source_info.span;
let msg = format!("argument {} is required to be a constant", index + 1);
ccx.tcx.sess.span_err(span, &msg);
literal: tcx
.mk_const(ty::Const {
ty,
- val: ty::ConstKind::Unevaluated(
+ val: ty::ConstKind::Unevaluated(ty::Unevaluated {
def,
- InternalSubsts::for_item(tcx, def.did, |param, _| {
+ substs: InternalSubsts::for_item(tcx, def.did, |param, _| {
if let ty::GenericParamDefKind::Lifetime = param.kind {
tcx.lifetimes.re_erased.into()
} else {
tcx.mk_param_from_def(param)
}
}),
- Some(promoted_id),
- ),
+ promoted: Some(promoted_id),
+ }),
})
.into(),
}))
_ => bug!(),
}
}
- Candidate::InlineAsm { bb, index } => {
- let terminator = blocks[bb].terminator_mut();
- match terminator.kind {
- TerminatorKind::InlineAsm { ref mut operands, .. } => {
- match &mut operands[index] {
- InlineAsmOperand::Const { ref mut value } => {
- let ty = value.ty(local_decls, self.tcx);
- let span = terminator.source_info.span;
-
- Rvalue::Use(mem::replace(value, promoted_operand(ty, span)))
- }
- _ => bug!(),
- }
- }
-
- _ => bug!(),
- }
- }
}
};
}
}
}
- Candidate::Argument { .. } | Candidate::InlineAsm { .. } => {}
+ Candidate::Argument { .. } => {}
}
// Declare return place local so that `mir::Body::new` doesn't complain.