Skip to content

Commit 2b000fe

Browse files
author
Oliver Schneider
committed
the const evaluator might run before check_const
So we cannot assume that the function call was marked NOT_CONST by check_const.
1 parent 72f42f1 commit 2b000fe

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/librustc/middle/const_eval.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1031,24 +1031,23 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10311031
UncheckedExprNoHint // we cannot reason about UncheckedExprHint here
10321032
};
10331033
let (
1034-
decl,
1035-
unsafety,
1036-
abi,
1037-
block,
1034+
decl,
1035+
unsafety,
1036+
abi,
1037+
block,
1038+
constness,
10381039
) = match try!(eval_const_expr_partial(tcx, callee, sub_ty_hint, fn_args)) {
10391040
Function(did) => if did.is_local() {
10401041
match tcx.map.find(did.index.as_u32()) {
10411042
Some(ast_map::NodeItem(it)) => match it.node {
10421043
hir::ItemFn(
10431044
ref decl,
10441045
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,
10481047
abi,
10491048
_, // ducktype generics? types are funky in const_eval
10501049
ref block,
1051-
) => (decl, unsafety, abi, block),
1050+
) => (decl, unsafety, abi, block, constness),
10521051
_ => signal!(e, NonConstPath),
10531052
},
10541053
_ => signal!(e, NonConstPath),
@@ -1058,6 +1057,15 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10581057
},
10591058
_ => signal!(e, NonConstPath),
10601059
};
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+
}
10611069
assert_eq!(decl.inputs.len(), args.len());
10621070
assert_eq!(unsafety, hir::Unsafety::Normal);
10631071
assert_eq!(abi, abi::Abi::Rust);

0 commit comments

Comments
 (0)