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:
parent
72f42f1174
commit
2b000feba5
@ -1031,10 +1031,11 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|||||||
UncheckedExprNoHint // we cannot reason about UncheckedExprHint here
|
UncheckedExprNoHint // we cannot reason about UncheckedExprHint here
|
||||||
};
|
};
|
||||||
let (
|
let (
|
||||||
decl,
|
decl,
|
||||||
unsafety,
|
unsafety,
|
||||||
abi,
|
abi,
|
||||||
block,
|
block,
|
||||||
|
constness,
|
||||||
) = match try!(eval_const_expr_partial(tcx, callee, sub_ty_hint, fn_args)) {
|
) = match try!(eval_const_expr_partial(tcx, callee, sub_ty_hint, fn_args)) {
|
||||||
Function(did) => if did.is_local() {
|
Function(did) => if did.is_local() {
|
||||||
match tcx.map.find(did.index.as_u32()) {
|
match tcx.map.find(did.index.as_u32()) {
|
||||||
@ -1042,13 +1043,11 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|||||||
hir::ItemFn(
|
hir::ItemFn(
|
||||||
ref decl,
|
ref decl,
|
||||||
unsafety,
|
unsafety,
|
||||||
_, // no need to check for constness... either check_const
|
constness,
|
||||||
// already forbids this or we const eval over whatever
|
|
||||||
// we want
|
|
||||||
abi,
|
abi,
|
||||||
_, // ducktype generics? types are funky in const_eval
|
_, // ducktype generics? types are funky in const_eval
|
||||||
ref block,
|
ref block,
|
||||||
) => (decl, unsafety, abi, block),
|
) => (decl, unsafety, abi, block, constness),
|
||||||
_ => signal!(e, NonConstPath),
|
_ => signal!(e, NonConstPath),
|
||||||
},
|
},
|
||||||
_ => signal!(e, NonConstPath),
|
_ => signal!(e, NonConstPath),
|
||||||
@ -1058,6 +1057,15 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|||||||
},
|
},
|
||||||
_ => signal!(e, NonConstPath),
|
_ => 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!(decl.inputs.len(), args.len());
|
||||||
assert_eq!(unsafety, hir::Unsafety::Normal);
|
assert_eq!(unsafety, hir::Unsafety::Normal);
|
||||||
assert_eq!(abi, abi::Abi::Rust);
|
assert_eq!(abi, abi::Abi::Rust);
|
||||||
|
Loading…
Reference in New Issue
Block a user