@@ -8,8 +8,7 @@ use syntax::feature_gate::{emit_feature_err, GateIssue};
88use syntax:: symbol:: sym;
99use syntax_pos:: { Span , Symbol } ;
1010
11- use super :: Item ;
12- use super :: validation:: Mode ;
11+ use super :: { ConstKind , Item } ;
1312
1413/// An operation that is not *always* allowed in a const context.
1514pub trait NonConstOp : std:: fmt:: Debug {
@@ -36,7 +35,7 @@ pub trait NonConstOp: std::fmt::Debug {
3635 span,
3736 E0019 ,
3837 "{} contains unimplemented expression type" ,
39- item. mode
38+ item. const_kind ( )
4039 ) ;
4140 if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
4241 err. note ( "A function call isn't allowed in the const's initialization expression \
@@ -76,7 +75,7 @@ impl NonConstOp for FnCallNonConst {
7675 E0015 ,
7776 "calls in {}s are limited to constant functions, \
7877 tuple structs and tuple variants",
79- item. mode ,
78+ item. const_kind ( ) ,
8079 ) ;
8180 err. emit ( ) ;
8281 }
@@ -121,8 +120,8 @@ impl NonConstOp for HeapAllocation {
121120
122121 fn emit_error ( & self , item : & Item < ' _ , ' _ > , span : Span ) {
123122 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 ( ) ) ) ;
126125 if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
127126 err. note (
128127 "The value of statics and constants must be known at compile time, \
@@ -146,7 +145,7 @@ impl NonConstOp for LiveDrop {
146145 struct_span_err ! ( item. tcx. sess, span, E0493 ,
147146 "destructors cannot be evaluated at compile-time" )
148147 . span_label ( span, format ! ( "{}s cannot evaluate destructors" ,
149- item. mode ) )
148+ item. const_kind ( ) ) )
150149 . emit ( ) ;
151150 }
152151}
@@ -163,9 +162,9 @@ impl NonConstOp for MutBorrow {
163162 if let BorrowKind :: Mut { .. } = kind {
164163 let mut err = struct_span_err ! ( item. tcx. sess, span, E0017 ,
165164 "references in {}s may only refer \
166- to immutable values", item. mode ) ;
165+ to immutable values", item. const_kind ( ) ) ;
167166 err. span_label ( span, format ! ( "{}s require immutable values" ,
168- item. mode ) ) ;
167+ item. const_kind ( ) ) ) ;
169168 if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
170169 err. note ( "References in statics and constants may only refer \
171170 to immutable values.\n \n \
@@ -202,7 +201,7 @@ impl NonConstOp for Panic {
202201 sym:: const_panic,
203202 span,
204203 GateIssue :: Language ,
205- & format ! ( "panicking in {}s is unstable" , item. mode ) ,
204+ & format ! ( "panicking in {}s is unstable" , item. const_kind ( ) ) ,
206205 ) ;
207206 }
208207}
@@ -220,7 +219,7 @@ impl NonConstOp for RawPtrComparison {
220219 sym:: const_compare_raw_pointers,
221220 span,
222221 GateIssue :: Language ,
223- & format ! ( "comparing raw pointers inside {}" , item. mode ) ,
222+ & format ! ( "comparing raw pointers inside {}" , item. const_kind ( ) ) ,
224223 ) ;
225224 }
226225}
@@ -238,7 +237,7 @@ impl NonConstOp for RawPtrDeref {
238237 span, GateIssue :: Language ,
239238 & format ! (
240239 "dereferencing raw pointers in {}s is unstable" ,
241- item. mode ,
240+ item. const_kind ( ) ,
242241 ) ,
243242 ) ;
244243 }
@@ -257,7 +256,7 @@ impl NonConstOp for RawPtrToIntCast {
257256 span, GateIssue :: Language ,
258257 & format ! (
259258 "casting pointers to integers in {}s is unstable" ,
260- item. mode ,
259+ item. const_kind ( ) ,
261260 ) ,
262261 ) ;
263262 }
@@ -268,13 +267,13 @@ impl NonConstOp for RawPtrToIntCast {
268267pub struct StaticAccess ;
269268impl NonConstOp for StaticAccess {
270269 fn is_allowed_in_item ( & self , item : & Item < ' _ , ' _ > ) -> bool {
271- item. mode . is_static ( )
270+ item. const_kind ( ) . is_static ( )
272271 }
273272
274273 fn emit_error ( & self , item : & Item < ' _ , ' _ > , span : Span ) {
275274 let mut err = struct_span_err ! ( item. tcx. sess, span, E0013 ,
276275 "{}s cannot refer to statics, use \
277- a constant instead", item. mode ) ;
276+ a constant instead", item. const_kind ( ) ) ;
278277 if item. tcx . sess . teach ( & err. get_code ( ) . unwrap ( ) ) {
279278 err. note (
280279 "Static and const variables can refer to other const variables. \
@@ -313,7 +312,7 @@ impl NonConstOp for Transmute {
313312 & item. tcx . sess . parse_sess , sym:: const_transmute,
314313 span, GateIssue :: Language ,
315314 & format ! ( "The use of std::mem::transmute() \
316- is gated in {}s", item. mode ) ) ;
315+ is gated in {}s", item. const_kind ( ) ) ) ;
317316 }
318317}
319318
@@ -322,7 +321,7 @@ pub struct UnionAccess;
322321impl NonConstOp for UnionAccess {
323322 fn is_allowed_in_item ( & self , item : & Item < ' _ , ' _ > ) -> bool {
324323 // 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 ( )
326325 }
327326
328327 fn feature_gate ( tcx : TyCtxt < ' _ > ) -> Option < bool > {
0 commit comments