File tree Expand file tree Collapse file tree 2 files changed +23
-22
lines changed
src/librustc_mir/transform/check_consts Expand file tree Collapse file tree 2 files changed +23
-22
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,22 @@ use rustc_span::{Span, Symbol};
10
10
11
11
use super :: ConstCx ;
12
12
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
+
13
29
/// An operation that is not *always* allowed in a const context.
14
30
pub trait NonConstOp : std:: fmt:: Debug {
15
31
/// Returns the `Symbol` corresponding to the feature gate that would enable this operation,
Original file line number Diff line number Diff line change @@ -232,30 +232,15 @@ impl Validator<'mir, 'tcx> {
232
232
self . qualifs . in_return_place ( self . ccx )
233
233
}
234
234
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
-
255
235
/// Emits an error if an expression cannot be evaluated in the current context.
256
236
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) ;
259
244
}
260
245
261
246
fn check_static ( & mut self , def_id : DefId , span : Span ) {
You can’t perform that action at this time.
0 commit comments