Move `check_op` logic to `ops` module
This commit is contained in:
parent
1fb612bd15
commit
cecfa43fb4
|
@ -10,6 +10,22 @@ use rustc_span::{Span, Symbol};
|
|||
|
||||
use super::ConstCx;
|
||||
|
||||
/// Emits an error if `op` is not allowed in the given const context.
|
||||
pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) {
|
||||
debug!("illegal_op: op={:?}", op);
|
||||
|
||||
if op.is_allowed_in_item(ccx) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ccx.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
|
||||
ccx.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
|
||||
return;
|
||||
}
|
||||
|
||||
op.emit_error(ccx, span);
|
||||
}
|
||||
|
||||
/// An operation that is not *always* allowed in a const context.
|
||||
pub trait NonConstOp: std::fmt::Debug {
|
||||
/// Returns the `Symbol` corresponding to the feature gate that would enable this operation,
|
||||
|
|
|
@ -232,30 +232,15 @@ impl Validator<'mir, 'tcx> {
|
|||
self.qualifs.in_return_place(self.ccx)
|
||||
}
|
||||
|
||||
/// Emits an error at the given `span` if an expression cannot be evaluated in the current
|
||||
/// context.
|
||||
pub fn check_op_spanned<O>(&mut self, op: O, span: Span)
|
||||
where
|
||||
O: NonConstOp,
|
||||
{
|
||||
debug!("check_op: op={:?}", op);
|
||||
|
||||
if op.is_allowed_in_item(self) {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
|
||||
self.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
|
||||
return;
|
||||
}
|
||||
|
||||
op.emit_error(self, span);
|
||||
}
|
||||
|
||||
/// Emits an error if an expression cannot be evaluated in the current context.
|
||||
pub fn check_op(&mut self, op: impl NonConstOp) {
|
||||
let span = self.span;
|
||||
self.check_op_spanned(op, span)
|
||||
ops::non_const(self.ccx, op, self.span);
|
||||
}
|
||||
|
||||
/// Emits an error at the given `span` if an expression cannot be evaluated in the current
|
||||
/// context.
|
||||
pub fn check_op_spanned(&mut self, op: impl NonConstOp, span: Span) {
|
||||
ops::non_const(self.ccx, op, span);
|
||||
}
|
||||
|
||||
fn check_static(&mut self, def_id: DefId, span: Span) {
|
||||
|
|
Loading…
Reference in New Issue