the const evaluator might run before check_const

So we cannot assume that the function call was marked NOT_CONST by check_const.
This commit is contained in:
Oliver Schneider 2015-10-27 09:39:07 +01:00
parent 72f42f1174
commit 2b000feba5

View File

@ -1031,10 +1031,11 @@ fn fromb(b: bool) -> ConstVal { Int(b as i64) }
UncheckedExprNoHint // we cannot reason about UncheckedExprHint here
};
let (
decl,
unsafety,
abi,
block,
decl,
unsafety,
abi,
block,
constness,
) = match try!(eval_const_expr_partial(tcx, callee, sub_ty_hint, fn_args)) {
Function(did) => if did.is_local() {
match tcx.map.find(did.index.as_u32()) {
@ -1042,13 +1043,11 @@ fn fromb(b: bool) -> ConstVal { Int(b as i64) }
hir::ItemFn(
ref decl,
unsafety,
_, // no need to check for constness... either check_const
// already forbids this or we const eval over whatever
// we want
constness,
abi,
_, // ducktype generics? types are funky in const_eval
ref block,
) => (decl, unsafety, abi, block),
) => (decl, unsafety, abi, block, constness),
_ => signal!(e, NonConstPath),
},
_ => signal!(e, NonConstPath),
@ -1058,6 +1057,15 @@ fn fromb(b: bool) -> ConstVal { Int(b as i64) }
},
_ => signal!(e, NonConstPath),
};
if let ExprTypeChecked = ty_hint {
// no need to check for constness... either check_const
// already forbids this or we const eval over whatever
// we want
} else {
// we don't know much about the function, so we force it to be a const fn
// so compilation will fail later in case the const fn's body is not const
assert_eq!(constness, hir::Constness::Const)
}
assert_eq!(decl.inputs.len(), args.len());
assert_eq!(unsafety, hir::Unsafety::Normal);
assert_eq!(abi, abi::Abi::Rust);