Skip to content

Commit b9eacee

Browse files
committed
fix ice in fn call const evaluation
1 parent 3330f54 commit b9eacee

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

src/librustc/middle/const_eval.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,6 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10321032
};
10331033
let (
10341034
decl,
1035-
unsafety,
1036-
abi,
10371035
block,
10381036
constness,
10391037
) = match try!(eval_const_expr_partial(tcx, callee, sub_ty_hint, fn_args)) {
@@ -1042,12 +1040,12 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10421040
Some(ast_map::NodeItem(it)) => match it.node {
10431041
hir::ItemFn(
10441042
ref decl,
1045-
unsafety,
1043+
hir::Unsafety::Normal,
10461044
constness,
1047-
abi,
1045+
abi::Abi::Rust,
10481046
_, // ducktype generics? types are funky in const_eval
10491047
ref block,
1050-
) => (decl, unsafety, abi, block, constness),
1048+
) => (decl, block, constness),
10511049
_ => signal!(e, NonConstPath),
10521050
},
10531051
_ => signal!(e, NonConstPath),
@@ -1057,18 +1055,19 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
10571055
},
10581056
_ => signal!(e, NonConstPath),
10591057
};
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)
1058+
match (ty_hint, constness) {
1059+
(ExprTypeChecked, _) => {
1060+
// no need to check for constness... either check_const
1061+
// already forbids this or we const eval over whatever
1062+
// we want
1063+
},
1064+
(_, hir::Constness::Const) => {
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+
},
1068+
_ => signal!(e, NonConstPath),
10681069
}
10691070
assert_eq!(decl.inputs.len(), args.len());
1070-
assert_eq!(unsafety, hir::Unsafety::Normal);
1071-
assert_eq!(abi, abi::Abi::Rust);
10721071

10731072
let mut call_args = NodeMap();
10741073
for (arg, arg_expr) in decl.inputs.iter().zip(args.iter()) {

src/test/compile-fail/const-call.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(const_fn)]
12+
13+
const unsafe fn g(x: usize) -> usize {
14+
x
15+
}
16+
17+
fn f(x: usize) -> usize {
18+
x
19+
}
20+
21+
fn main() {
22+
let _ = [0; f(2)]; //~ ERROR: non-constant path in constant expression [E0307]
23+
let _ = [0; g(2)]; //~ ERROR: non-constant path in constant expression [E0307]
24+
}

0 commit comments

Comments
 (0)