rust/src/test/compile-fail/const-fn-error.rs
Oliver Schneider 1471d932a9 move const block checks before lowering step
this makes sure the checks run before typeck (which might use the constant or const
function to calculate an array length) and gives prettier error messages in case of for
loops and such (since they aren't expanded yet).
2016-01-15 13:16:54 +01:00

30 lines
846 B
Rust

// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// test that const fn signature and body errors are checked
// even in array lengths, which are evaluated before check_const
#![feature(const_fn)]
const X : usize = 2;
const fn f(x: usize) -> usize {
let mut sum = 0; //~ ERROR: E0016
for i in 0..x { //~ ERROR: E0016
sum += i;
}
sum
}
#[allow(unused_variables)]
fn main() {
let a : [i32; f(X)];
}