Skip to content

Commit cecfa43

Browse files
Move check_op logic to ops module
1 parent 1fb612b commit cecfa43

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/librustc_mir/transform/check_consts/ops.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@ use rustc_span::{Span, Symbol};
1010

1111
use super::ConstCx;
1212

13+
/// Emits an error if `op` is not allowed in the given const context.
14+
pub fn non_const<O: NonConstOp>(ccx: &ConstCx<'_, '_>, op: O, span: Span) {
15+
debug!("illegal_op: op={:?}", op);
16+
17+
if op.is_allowed_in_item(ccx) {
18+
return;
19+
}
20+
21+
if ccx.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
22+
ccx.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
23+
return;
24+
}
25+
26+
op.emit_error(ccx, span);
27+
}
28+
1329
/// An operation that is not *always* allowed in a const context.
1430
pub trait NonConstOp: std::fmt::Debug {
1531
/// Returns the `Symbol` corresponding to the feature gate that would enable this operation,

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,30 +232,15 @@ impl Validator<'mir, 'tcx> {
232232
self.qualifs.in_return_place(self.ccx)
233233
}
234234

235-
/// Emits an error at the given `span` if an expression cannot be evaluated in the current
236-
/// context.
237-
pub fn check_op_spanned<O>(&mut self, op: O, span: Span)
238-
where
239-
O: NonConstOp,
240-
{
241-
debug!("check_op: op={:?}", op);
242-
243-
if op.is_allowed_in_item(self) {
244-
return;
245-
}
246-
247-
if self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you {
248-
self.tcx.sess.miri_unleashed_feature(span, O::feature_gate());
249-
return;
250-
}
251-
252-
op.emit_error(self, span);
253-
}
254-
255235
/// Emits an error if an expression cannot be evaluated in the current context.
256236
pub fn check_op(&mut self, op: impl NonConstOp) {
257-
let span = self.span;
258-
self.check_op_spanned(op, span)
237+
ops::non_const(self.ccx, op, self.span);
238+
}
239+
240+
/// Emits an error at the given `span` if an expression cannot be evaluated in the current
241+
/// context.
242+
pub fn check_op_spanned(&mut self, op: impl NonConstOp, span: Span) {
243+
ops::non_const(self.ccx, op, span);
259244
}
260245

261246
fn check_static(&mut self, def_id: DefId, span: Span) {

0 commit comments

Comments
 (0)