@@ -8,8 +8,7 @@ use syntax::feature_gate::{emit_feature_err, GateIssue};
8
8
use syntax:: symbol:: sym;
9
9
use syntax_pos:: { Span , Symbol } ;
10
10
11
- use super :: Item ;
12
- use super :: validation:: Mode ;
11
+ use super :: { ConstKind , Item } ;
13
12
14
13
/// An operation that is not *always* allowed in a const context.
15
14
pub trait NonConstOp : std:: fmt:: Debug {
@@ -36,7 +35,7 @@ pub trait NonConstOp: std::fmt::Debug {
36
35
span,
37
36
E0019 ,
38
37
"{} contains unimplemented expression type" ,
39
- item. mode
38
+ item. const_kind ( )
40
39
) ;
41
40
if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
42
41
err. note ( "A function call isn't allowed in the const's initialization expression \
@@ -76,7 +75,7 @@ impl NonConstOp for FnCallNonConst {
76
75
E0015 ,
77
76
"calls in {}s are limited to constant functions, \
78
77
tuple structs and tuple variants",
79
- item. mode ,
78
+ item. const_kind ( ) ,
80
79
) ;
81
80
err. emit ( ) ;
82
81
}
@@ -121,8 +120,8 @@ impl NonConstOp for HeapAllocation {
121
120
122
121
fn emit_error ( & self , item : & Item < ' _ , ' _ > , span : Span ) {
123
122
let mut err = struct_span_err ! ( item. tcx. sess, span, E0010 ,
124
- "allocations are not allowed in {}s" , item. mode ) ;
125
- err. span_label ( span, format ! ( "allocation not allowed in {}s" , item. mode ) ) ;
123
+ "allocations are not allowed in {}s" , item. const_kind ( ) ) ;
124
+ err. span_label ( span, format ! ( "allocation not allowed in {}s" , item. const_kind ( ) ) ) ;
126
125
if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
127
126
err. note (
128
127
"The value of statics and constants must be known at compile time, \
@@ -146,7 +145,7 @@ impl NonConstOp for LiveDrop {
146
145
struct_span_err ! ( item. tcx. sess, span, E0493 ,
147
146
"destructors cannot be evaluated at compile-time" )
148
147
. span_label ( span, format ! ( "{}s cannot evaluate destructors" ,
149
- item. mode ) )
148
+ item. const_kind ( ) ) )
150
149
. emit ( ) ;
151
150
}
152
151
}
@@ -163,9 +162,9 @@ impl NonConstOp for MutBorrow {
163
162
if let BorrowKind :: Mut { .. } = kind {
164
163
let mut err = struct_span_err ! ( item. tcx. sess, span, E0017 ,
165
164
"references in {}s may only refer \
166
- to immutable values", item. mode ) ;
165
+ to immutable values", item. const_kind ( ) ) ;
167
166
err. span_label ( span, format ! ( "{}s require immutable values" ,
168
- item. mode ) ) ;
167
+ item. const_kind ( ) ) ) ;
169
168
if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
170
169
err. note ( "References in statics and constants may only refer \
171
170
to immutable values.\n \n \
@@ -202,7 +201,7 @@ impl NonConstOp for Panic {
202
201
sym:: const_panic,
203
202
span,
204
203
GateIssue :: Language ,
205
- & format ! ( "panicking in {}s is unstable" , item. mode ) ,
204
+ & format ! ( "panicking in {}s is unstable" , item. const_kind ( ) ) ,
206
205
) ;
207
206
}
208
207
}
@@ -220,7 +219,7 @@ impl NonConstOp for RawPtrComparison {
220
219
sym:: const_compare_raw_pointers,
221
220
span,
222
221
GateIssue :: Language ,
223
- & format ! ( "comparing raw pointers inside {}" , item. mode ) ,
222
+ & format ! ( "comparing raw pointers inside {}" , item. const_kind ( ) ) ,
224
223
) ;
225
224
}
226
225
}
@@ -238,7 +237,7 @@ impl NonConstOp for RawPtrDeref {
238
237
span, GateIssue :: Language ,
239
238
& format ! (
240
239
"dereferencing raw pointers in {}s is unstable" ,
241
- item. mode ,
240
+ item. const_kind ( ) ,
242
241
) ,
243
242
) ;
244
243
}
@@ -257,7 +256,7 @@ impl NonConstOp for RawPtrToIntCast {
257
256
span, GateIssue :: Language ,
258
257
& format ! (
259
258
"casting pointers to integers in {}s is unstable" ,
260
- item. mode ,
259
+ item. const_kind ( ) ,
261
260
) ,
262
261
) ;
263
262
}
@@ -268,13 +267,13 @@ impl NonConstOp for RawPtrToIntCast {
268
267
pub struct StaticAccess ;
269
268
impl NonConstOp for StaticAccess {
270
269
fn is_allowed_in_item ( & self , item : & Item < ' _ , ' _ > ) -> bool {
271
- item. mode . is_static ( )
270
+ item. const_kind ( ) . is_static ( )
272
271
}
273
272
274
273
fn emit_error ( & self , item : & Item < ' _ , ' _ > , span : Span ) {
275
274
let mut err = struct_span_err ! ( item. tcx. sess, span, E0013 ,
276
275
"{}s cannot refer to statics, use \
277
- a constant instead", item. mode ) ;
276
+ a constant instead", item. const_kind ( ) ) ;
278
277
if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
279
278
err. note (
280
279
"Static and const variables can refer to other const variables. \
@@ -313,7 +312,7 @@ impl NonConstOp for Transmute {
313
312
& item. tcx . sess . parse_sess , sym:: const_transmute,
314
313
span, GateIssue :: Language ,
315
314
& format ! ( "The use of std::mem::transmute() \
316
- is gated in {}s", item. mode ) ) ;
315
+ is gated in {}s", item. const_kind ( ) ) ) ;
317
316
}
318
317
}
319
318
@@ -322,7 +321,7 @@ pub struct UnionAccess;
322
321
impl NonConstOp for UnionAccess {
323
322
fn is_allowed_in_item ( & self , item : & Item < ' _ , ' _ > ) -> bool {
324
323
// Union accesses are stable in all contexts except `const fn`.
325
- item. mode != Mode :: ConstFn || Self :: feature_gate ( item. tcx ) . unwrap ( )
324
+ item. const_kind ( ) != ConstKind :: ConstFn || Self :: feature_gate ( item. tcx ) . unwrap ( )
326
325
}
327
326
328
327
fn feature_gate ( tcx : TyCtxt < ' _ > ) -> Option < bool > {
0 commit comments