@@ -30,34 +30,25 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
30
30
& mut self ,
31
31
instance : ty:: Instance < ' tcx > ,
32
32
args : & [ OpTy < ' tcx > ] ,
33
- is_const_fn : bool ,
34
33
) -> InterpResult < ' tcx , Option < ty:: Instance < ' tcx > > > {
35
- // The list of functions we handle here must be in sync with
36
- // `is_lang_special_const_fn` in `transform/check_consts/mod.rs`.
34
+ // All `#[rustc_do_not_const_check]` functions should be hooked here.
37
35
let def_id = instance. def_id ( ) ;
38
36
39
- if is_const_fn {
40
- if Some ( def_id) == self . tcx . lang_items ( ) . const_eval_select ( ) {
41
- // redirect to const_eval_select_ct
42
- if let Some ( const_eval_select) = self . tcx . lang_items ( ) . const_eval_select_ct ( ) {
43
- return Ok ( Some (
44
- ty:: Instance :: resolve (
45
- * self . tcx ,
46
- ty:: ParamEnv :: reveal_all ( ) ,
47
- const_eval_select,
48
- instance. substs ,
49
- )
50
- . unwrap ( )
51
- . unwrap ( ) ,
52
- ) ) ;
53
- }
37
+ if Some ( def_id) == self . tcx . lang_items ( ) . const_eval_select ( ) {
38
+ // redirect to const_eval_select_ct
39
+ if let Some ( const_eval_select) = self . tcx . lang_items ( ) . const_eval_select_ct ( ) {
40
+ return Ok ( Some (
41
+ ty:: Instance :: resolve (
42
+ * self . tcx ,
43
+ ty:: ParamEnv :: reveal_all ( ) ,
44
+ const_eval_select,
45
+ instance. substs ,
46
+ )
47
+ . unwrap ( )
48
+ . unwrap ( ) ,
49
+ ) ) ;
54
50
}
55
- return Ok ( None ) ;
56
- }
57
-
58
- if Some ( def_id) == self . tcx . lang_items ( ) . panic_fn ( )
59
- || Some ( def_id) == self . tcx . lang_items ( ) . panic_str ( )
60
- || Some ( def_id) == self . tcx . lang_items ( ) . panic_display ( )
51
+ } else if Some ( def_id) == self . tcx . lang_items ( ) . panic_display ( )
61
52
|| Some ( def_id) == self . tcx . lang_items ( ) . begin_panic_fn ( )
62
53
{
63
54
// &str or &&str
@@ -274,31 +265,22 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
274
265
275
266
// Only check non-glue functions
276
267
if let ty:: InstanceDef :: Item ( def) = instance. def {
277
- let mut is_const_fn = true ;
278
-
279
268
// Execution might have wandered off into other crates, so we cannot do a stability-
280
269
// sensitive check here. But we can at least rule out functions that are not const
281
270
// at all.
282
271
if !ecx. tcx . is_const_fn_raw ( def. did ) {
283
272
// allow calling functions marked with #[default_method_body_is_const].
284
273
if !ecx. tcx . has_attr ( def. did , sym:: default_method_body_is_const) {
285
- is_const_fn = false ;
274
+ // We certainly do *not* want to actually call the fn
275
+ // though, so be sure we return here.
276
+ throw_unsup_format ! ( "calling non-const function `{}`" , instance)
286
277
}
287
278
}
288
279
289
- // Some functions we support even if they are non-const -- but avoid testing
290
- // that for const fn!
291
- // `const_eval_select` is a const fn because it must use const trait bounds.
292
- if let Some ( new_instance) = ecx. hook_special_const_fn ( instance, args, is_const_fn) ? {
280
+ if let Some ( new_instance) = ecx. hook_special_const_fn ( instance, args) ? {
293
281
// We call another const fn instead.
294
282
return Self :: find_mir_or_eval_fn ( ecx, new_instance, _abi, args, _ret, _unwind) ;
295
283
}
296
-
297
- if !is_const_fn {
298
- // We certainly do *not* want to actually call the fn
299
- // though, so be sure we return here.
300
- throw_unsup_format ! ( "calling non-const function `{}`" , instance)
301
- }
302
284
}
303
285
// This is a const fn. Call it.
304
286
Ok ( Some ( ecx. load_mir ( instance. def , None ) ?) )
0 commit comments