@@ -1031,24 +1031,23 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
1031
1031
UncheckedExprNoHint // we cannot reason about UncheckedExprHint here
1032
1032
} ;
1033
1033
let (
1034
- decl,
1035
- unsafety,
1036
- abi,
1037
- block,
1034
+ decl,
1035
+ unsafety,
1036
+ abi,
1037
+ block,
1038
+ constness,
1038
1039
) = match try!( eval_const_expr_partial ( tcx, callee, sub_ty_hint, fn_args) ) {
1039
1040
Function ( did) => if did. is_local ( ) {
1040
1041
match tcx. map . find ( did. index . as_u32 ( ) ) {
1041
1042
Some ( ast_map:: NodeItem ( it) ) => match it. node {
1042
1043
hir:: ItemFn (
1043
1044
ref decl,
1044
1045
unsafety,
1045
- _, // no need to check for constness... either check_const
1046
- // already forbids this or we const eval over whatever
1047
- // we want
1046
+ constness,
1048
1047
abi,
1049
1048
_, // ducktype generics? types are funky in const_eval
1050
1049
ref block,
1051
- ) => ( decl, unsafety, abi, block) ,
1050
+ ) => ( decl, unsafety, abi, block, constness ) ,
1052
1051
_ => signal ! ( e, NonConstPath ) ,
1053
1052
} ,
1054
1053
_ => signal ! ( e, NonConstPath ) ,
@@ -1058,6 +1057,15 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
1058
1057
} ,
1059
1058
_ => signal ! ( e, NonConstPath ) ,
1060
1059
} ;
1060
+ if let ExprTypeChecked = ty_hint {
1061
+ // no need to check for constness... either check_const
1062
+ // already forbids this or we const eval over whatever
1063
+ // we want
1064
+ } else {
1065
+ // we don't know much about the function, so we force it to be a const fn
1066
+ // so compilation will fail later in case the const fn's body is not const
1067
+ assert_eq ! ( constness, hir:: Constness :: Const )
1068
+ }
1061
1069
assert_eq ! ( decl. inputs. len( ) , args. len( ) ) ;
1062
1070
assert_eq ! ( unsafety, hir:: Unsafety :: Normal ) ;
1063
1071
assert_eq ! ( abi, abi:: Abi :: Rust ) ;
0 commit comments