@@ -5,17 +5,7 @@ use rustc::ty::{self, Predicate, TyCtxt};
5
5
use std:: borrow:: Cow ;
6
6
use syntax_pos:: Span ;
7
7
8
- mod helper {
9
- pub struct IsMinConstFn ( ( ) ) ;
10
- /// This should only ever be used *once* and then passed around as a token.
11
- pub fn ensure_that_you_really_intended_to_create_an_instance_of_this ( ) -> IsMinConstFn {
12
- IsMinConstFn ( ( ) )
13
- }
14
- }
15
-
16
- use self :: helper:: * ;
17
-
18
- type McfResult = Result < IsMinConstFn , ( Span , Cow < ' static , str > ) > ;
8
+ type McfResult = Result < ( ) , ( Span , Cow < ' static , str > ) > ;
19
9
20
10
pub fn is_min_const_fn (
21
11
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -74,39 +64,35 @@ pub fn is_min_const_fn(
74
64
}
75
65
}
76
66
77
- let mut token = ensure_that_you_really_intended_to_create_an_instance_of_this ( ) ;
78
-
79
67
for local in mir. vars_iter ( ) {
80
68
return Err ( (
81
69
mir. local_decls [ local] . source_info . span ,
82
70
"local variables in const fn are unstable" . into ( ) ,
83
71
) ) ;
84
72
}
85
73
for local in & mir. local_decls {
86
- token = check_ty ( tcx, local. ty , local. source_info . span , token ) ?;
74
+ check_ty ( tcx, local. ty , local. source_info . span ) ?;
87
75
}
88
76
// impl trait is gone in MIR, so check the return type manually
89
- token = check_ty (
77
+ check_ty (
90
78
tcx,
91
79
tcx. fn_sig ( def_id) . output ( ) . skip_binder ( ) ,
92
80
mir. local_decls . iter ( ) . next ( ) . unwrap ( ) . source_info . span ,
93
- token,
94
81
) ?;
95
82
96
83
for bb in mir. basic_blocks ( ) {
97
- token = check_terminator ( tcx, mir, bb. terminator ( ) , token ) ?;
84
+ check_terminator ( tcx, mir, bb. terminator ( ) ) ?;
98
85
for stmt in & bb. statements {
99
- token = check_statement ( tcx, mir, stmt, token ) ?;
86
+ check_statement ( tcx, mir, stmt) ?;
100
87
}
101
88
}
102
- Ok ( token )
89
+ Ok ( ( ) )
103
90
}
104
91
105
92
fn check_ty (
106
93
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
107
94
ty : ty:: Ty < ' tcx > ,
108
95
span : Span ,
109
- token : IsMinConstFn ,
110
96
) -> McfResult {
111
97
for ty in ty. walk ( ) {
112
98
match ty. sty {
@@ -146,22 +132,21 @@ fn check_ty(
146
132
_ => { }
147
133
}
148
134
}
149
- Ok ( token )
135
+ Ok ( ( ) )
150
136
}
151
137
152
138
fn check_rvalue (
153
139
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
154
140
mir : & ' a Mir < ' tcx > ,
155
141
rvalue : & Rvalue < ' tcx > ,
156
142
span : Span ,
157
- token : IsMinConstFn ,
158
143
) -> McfResult {
159
144
match rvalue {
160
145
Rvalue :: Repeat ( operand, _) | Rvalue :: Use ( operand) => {
161
- check_operand ( tcx, mir, operand, span, token )
146
+ check_operand ( tcx, mir, operand, span)
162
147
}
163
148
Rvalue :: Len ( place) | Rvalue :: Discriminant ( place) | Rvalue :: Ref ( _, _, place) => {
164
- check_place ( tcx, mir, place, span, token , PlaceMode :: Read )
149
+ check_place ( tcx, mir, place, span, PlaceMode :: Read )
165
150
}
166
151
Rvalue :: Cast ( _, operand, cast_ty) => {
167
152
use rustc:: ty:: cast:: CastTy ;
@@ -175,16 +160,16 @@ fn check_rvalue(
175
160
( CastTy :: RPtr ( _) , CastTy :: Float ) => bug ! ( ) ,
176
161
( CastTy :: RPtr ( _) , CastTy :: Int ( _) ) => bug ! ( ) ,
177
162
( CastTy :: Ptr ( _) , CastTy :: RPtr ( _) ) => bug ! ( ) ,
178
- _ => check_operand ( tcx, mir, operand, span, token ) ,
163
+ _ => check_operand ( tcx, mir, operand, span) ,
179
164
}
180
165
}
181
166
// binops are fine on integers
182
167
Rvalue :: BinaryOp ( _, lhs, rhs) | Rvalue :: CheckedBinaryOp ( _, lhs, rhs) => {
183
- let token = check_operand ( tcx, mir, lhs, span, token ) ?;
184
- let token = check_operand ( tcx, mir, rhs, span, token ) ?;
168
+ check_operand ( tcx, mir, lhs, span) ?;
169
+ check_operand ( tcx, mir, rhs, span) ?;
185
170
let ty = lhs. ty ( mir, tcx) ;
186
171
if ty. is_integral ( ) || ty. is_bool ( ) || ty. is_char ( ) {
187
- Ok ( token )
172
+ Ok ( ( ) )
188
173
} else {
189
174
Err ( (
190
175
span,
@@ -193,11 +178,11 @@ fn check_rvalue(
193
178
}
194
179
}
195
180
// checked by regular const fn checks
196
- Rvalue :: NullaryOp ( ..) => Ok ( token ) ,
181
+ Rvalue :: NullaryOp ( ..) => Ok ( ( ) ) ,
197
182
Rvalue :: UnaryOp ( _, operand) => {
198
183
let ty = operand. ty ( mir, tcx) ;
199
184
if ty. is_integral ( ) || ty. is_bool ( ) {
200
- check_operand ( tcx, mir, operand, span, token )
185
+ check_operand ( tcx, mir, operand, span)
201
186
} else {
202
187
Err ( (
203
188
span,
@@ -206,11 +191,10 @@ fn check_rvalue(
206
191
}
207
192
}
208
193
Rvalue :: Aggregate ( _, operands) => {
209
- let mut token = token;
210
194
for operand in operands {
211
- token = check_operand ( tcx, mir, operand, span, token ) ?;
195
+ check_operand ( tcx, mir, operand, span) ?;
212
196
}
213
- Ok ( token )
197
+ Ok ( ( ) )
214
198
}
215
199
}
216
200
}
@@ -224,19 +208,18 @@ fn check_statement(
224
208
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
225
209
mir : & ' a Mir < ' tcx > ,
226
210
statement : & Statement < ' tcx > ,
227
- token : IsMinConstFn ,
228
211
) -> McfResult {
229
212
let span = statement. source_info . span ;
230
213
match & statement. kind {
231
214
StatementKind :: Assign ( place, rval) => {
232
- let token = check_place ( tcx, mir, place, span, token , PlaceMode :: Assign ) ?;
233
- check_rvalue ( tcx, mir, rval, span, token )
215
+ check_place ( tcx, mir, place, span, PlaceMode :: Assign ) ?;
216
+ check_rvalue ( tcx, mir, rval, span)
234
217
}
235
218
236
219
StatementKind :: ReadForMatch ( _) => Err ( ( span, "match in const fn is unstable" . into ( ) ) ) ,
237
220
238
221
// just an assignment
239
- StatementKind :: SetDiscriminant { .. } => Ok ( token ) ,
222
+ StatementKind :: SetDiscriminant { .. } => Ok ( ( ) ) ,
240
223
241
224
| StatementKind :: InlineAsm { .. } => {
242
225
Err ( ( span, "cannot use inline assembly in const fn" . into ( ) ) )
@@ -248,7 +231,7 @@ fn check_statement(
248
231
| StatementKind :: Validate ( ..)
249
232
| StatementKind :: EndRegion ( _)
250
233
| StatementKind :: UserAssertTy ( ..)
251
- | StatementKind :: Nop => Ok ( token ) ,
234
+ | StatementKind :: Nop => Ok ( ( ) ) ,
252
235
}
253
236
}
254
237
@@ -257,13 +240,12 @@ fn check_operand(
257
240
mir : & ' a Mir < ' tcx > ,
258
241
operand : & Operand < ' tcx > ,
259
242
span : Span ,
260
- token : IsMinConstFn ,
261
243
) -> McfResult {
262
244
match operand {
263
245
Operand :: Move ( place) | Operand :: Copy ( place) => {
264
- check_place ( tcx, mir, place, span, token , PlaceMode :: Read )
246
+ check_place ( tcx, mir, place, span, PlaceMode :: Read )
265
247
}
266
- Operand :: Constant ( _) => Ok ( token ) ,
248
+ Operand :: Constant ( _) => Ok ( ( ) ) ,
267
249
}
268
250
}
269
251
@@ -272,26 +254,25 @@ fn check_place(
272
254
mir : & ' a Mir < ' tcx > ,
273
255
place : & Place < ' tcx > ,
274
256
span : Span ,
275
- token : IsMinConstFn ,
276
257
mode : PlaceMode ,
277
258
) -> McfResult {
278
259
match place {
279
260
Place :: Local ( l) => match mode {
280
261
PlaceMode :: Assign => match mir. local_kind ( * l) {
281
- LocalKind :: Temp | LocalKind :: ReturnPointer => Ok ( token ) ,
262
+ LocalKind :: Temp | LocalKind :: ReturnPointer => Ok ( ( ) ) ,
282
263
LocalKind :: Arg | LocalKind :: Var => {
283
264
Err ( ( span, "assignments in const fn are unstable" . into ( ) ) )
284
265
}
285
266
} ,
286
- PlaceMode :: Read => Ok ( token ) ,
267
+ PlaceMode :: Read => Ok ( ( ) ) ,
287
268
} ,
288
269
// promoteds are always fine, they are essentially constants
289
- Place :: Promoted ( _) => Ok ( token ) ,
270
+ Place :: Promoted ( _) => Ok ( ( ) ) ,
290
271
Place :: Static ( _) => Err ( ( span, "cannot access `static` items in const fn" . into ( ) ) ) ,
291
272
Place :: Projection ( proj) => {
292
273
match proj. elem {
293
274
| ProjectionElem :: Deref | ProjectionElem :: Field ( ..) | ProjectionElem :: Index ( _) => {
294
- check_place ( tcx, mir, & proj. base , span, token , mode)
275
+ check_place ( tcx, mir, & proj. base , span, mode)
295
276
}
296
277
// slice patterns are unstable
297
278
| ProjectionElem :: ConstantIndex { .. } | ProjectionElem :: Subslice { .. } => {
@@ -309,20 +290,19 @@ fn check_terminator(
309
290
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
310
291
mir : & ' a Mir < ' tcx > ,
311
292
terminator : & Terminator < ' tcx > ,
312
- token : IsMinConstFn ,
313
293
) -> McfResult {
314
294
let span = terminator. source_info . span ;
315
295
match & terminator. kind {
316
296
| TerminatorKind :: Goto { .. }
317
297
| TerminatorKind :: Return
318
- | TerminatorKind :: Resume => Ok ( token ) ,
298
+ | TerminatorKind :: Resume => Ok ( ( ) ) ,
319
299
320
300
TerminatorKind :: Drop { location, .. } => {
321
- check_place ( tcx, mir, location, span, token , PlaceMode :: Read )
301
+ check_place ( tcx, mir, location, span, PlaceMode :: Read )
322
302
}
323
303
TerminatorKind :: DropAndReplace { location, value, .. } => {
324
- let token = check_place ( tcx, mir, location, span, token , PlaceMode :: Read ) ?;
325
- check_operand ( tcx, mir, value, span, token )
304
+ check_place ( tcx, mir, location, span, PlaceMode :: Read ) ?;
305
+ check_operand ( tcx, mir, value, span)
326
306
} ,
327
307
TerminatorKind :: SwitchInt { .. } => Err ( (
328
308
span,
@@ -344,12 +324,12 @@ fn check_terminator(
344
324
let fn_ty = func. ty ( mir, tcx) ;
345
325
if let ty:: FnDef ( def_id, _) = fn_ty. sty {
346
326
if tcx. is_min_const_fn ( def_id) {
347
- let mut token = check_operand ( tcx, mir, func, span, token ) ?;
327
+ check_operand ( tcx, mir, func, span) ?;
348
328
349
329
for arg in args {
350
- token = check_operand ( tcx, mir, arg, span, token ) ?;
330
+ check_operand ( tcx, mir, arg, span) ?;
351
331
}
352
- Ok ( token )
332
+ Ok ( ( ) )
353
333
} else {
354
334
Err ( (
355
335
span,
@@ -367,7 +347,7 @@ fn check_terminator(
367
347
msg : _,
368
348
target : _,
369
349
cleanup : _,
370
- } => check_operand ( tcx, mir, cond, span, token ) ,
350
+ } => check_operand ( tcx, mir, cond, span) ,
371
351
372
352
| TerminatorKind :: FalseEdges { .. } | TerminatorKind :: FalseUnwind { .. } => span_bug ! (
373
353
terminator. source_info. span,
0 commit comments