Skip to content

Commit

Permalink
the const evaluator might run before check_const
Browse files Browse the repository at this point in the history
So we cannot assume that the function call was marked NOT_CONST by check_const.
  • Loading branch information
Oliver Schneider committed Oct 27, 2015
1 parent 72f42f1 commit 2b000fe
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/librustc/middle/const_eval.rs
Expand Up @@ -1031,24 +1031,23 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
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()) {
Some(ast_map::NodeItem(it)) => match it.node {
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),
Expand All @@ -1058,6 +1057,15 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
},
_ => 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);
Expand Down

0 comments on commit 2b000fe

Please sign in to comment.