New tests for cross-crate usages of const fn and so forth

This commit is contained in:
Niko Matsakis 2015-05-29 09:57:36 -04:00
parent 2c5e784d6f
commit 808b411244
6 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// 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.
// Crate that exports a const fn. Used for testing cross-crate.
#![crate_type="rlib"]
#![feature(const_fn)]
pub const fn foo() -> usize { 22 } //~ ERROR const fn is unstable

View File

@ -0,0 +1,21 @@
// 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 use of const fn from another crate without a feature gate.
// aux-build:const_fn_lib.rs
extern crate const_fn_lib;
use const_fn_lib::foo;
fn main() {
let x: [usize; foo()] = []; //~ ERROR unsupported constant expr
}

View File

@ -0,0 +1,25 @@
// 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 use of const fn from another crate without a feature gate.
#![feature(rustc_attrs)]
#![allow(unused_variables)]
// aux-build:const_fn_lib.rs
extern crate const_fn_lib;
use const_fn_lib::foo;
#[rustc_error]
fn main() { //~ ERROR compilation successful
let x = foo(); // use outside a constant is ok
}

View File

@ -0,0 +1,34 @@
// 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 use of const fn from another crate without a feature gate.
// aux-build:const_fn_lib.rs
extern crate const_fn_lib;
use const_fn_lib::foo;
static FOO: usize = foo(); //~ ERROR const fns are an unstable feature
const BAR: usize = foo(); //~ ERROR const fns are an unstable feature
macro_rules! constant {
($n:ident: $t:ty = $v:expr) => {
const $n: $t = $v;
}
}
constant! {
BAZ: usize = foo() //~ ERROR const fns are an unstable feature
}
fn main() {
// let x: [usize; foo()] = [];
}

View File

@ -28,6 +28,16 @@ impl Foo for u32 {
static FOO: usize = foo();
const BAR: usize = foo();
macro_rules! constant {
($n:ident: $t:ty = $v:expr) => {
const $n: $t = $v;
}
}
constant! {
BAZ: usize = foo()
}
fn main() {
let x: [usize; foo()] = [];
}

View File

@ -0,0 +1,25 @@
// 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.
// aux-build:const_fn_lib.rs
// A very basic test of const fn functionality.
#![feature(const_fn)]
extern crate const_fn_lib;
use const_fn_lib::foo;
const FOO: usize = foo();
fn main() {
assert_eq!(FOO, 22);
}