@@ -30,34 +30,25 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
3030 & mut self ,
3131 instance : ty:: Instance < ' tcx > ,
3232 args : & [ OpTy < ' tcx > ] ,
33- is_const_fn : bool ,
3433 ) -> 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.
3735 let def_id = instance. def_id ( ) ;
3836
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+ ) ) ;
5450 }
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 ( )
6152 || Some ( def_id) == self . tcx . lang_items ( ) . begin_panic_fn ( )
6253 {
6354 // &str or &&str
@@ -274,31 +265,22 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
274265
275266 // Only check non-glue functions
276267 if let ty:: InstanceDef :: Item ( def) = instance. def {
277- let mut is_const_fn = true ;
278-
279268 // Execution might have wandered off into other crates, so we cannot do a stability-
280269 // sensitive check here. But we can at least rule out functions that are not const
281270 // at all.
282271 if !ecx. tcx . is_const_fn_raw ( def. did ) {
283272 // allow calling functions marked with #[default_method_body_is_const].
284273 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)
286277 }
287278 }
288279
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) ? {
293281 // We call another const fn instead.
294282 return Self :: find_mir_or_eval_fn ( ecx, new_instance, _abi, args, _ret, _unwind) ;
295283 }
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- }
302284 }
303285 // This is a const fn. Call it.
304286 Ok ( Some ( ecx. load_mir ( instance. def , None ) ?) )
0 commit comments