mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
New tests for cross-crate usages of const fn and so forth
This commit is contained in:
parent
2c5e784d6f
commit
808b411244
16
src/test/auxiliary/const_fn_lib.rs
Normal file
16
src/test/auxiliary/const_fn_lib.rs
Normal 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
|
21
src/test/compile-fail/const-fn-stability-calls-2.rs
Normal file
21
src/test/compile-fail/const-fn-stability-calls-2.rs
Normal 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
|
||||
}
|
25
src/test/compile-fail/const-fn-stability-calls-3.rs
Normal file
25
src/test/compile-fail/const-fn-stability-calls-3.rs
Normal 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
|
||||
}
|
34
src/test/compile-fail/const-fn-stability-calls.rs
Normal file
34
src/test/compile-fail/const-fn-stability-calls.rs
Normal 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()] = [];
|
||||
}
|
@ -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()] = [];
|
||||
}
|
||||
|
25
src/test/run-pass/const-fn-cross-crate.rs
Normal file
25
src/test/run-pass/const-fn-cross-crate.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user