Implement the min_const_fn feature gate

This commit is contained in:
Oliver Schneider 2018-08-22 15:56:37 +02:00 committed by Oliver Schneider
parent 1114ab684f
commit 472ca71598
39 changed files with 1626 additions and 230 deletions

View file

@ -10,7 +10,7 @@
// ignore-emscripten
// compile-flags: -Z lower_128bit_ops=yes -C debug_assertions=no
// compile-flags: -Z lower_128bit_ops=yes -C debug_assertions=no -O
#![feature(const_fn)]
@ -63,103 +63,65 @@ fn main() {
// END RUST SOURCE
// START rustc.const_signed.Lower128Bit.after.mir
// _8 = _1;
// _9 = const compiler_builtins::int::addsub::rust_i128_addo(move _8, const 1i128) -> bb10;
// ...
// _7 = move (_9.0: i128);
// ...
// _10 = const compiler_builtins::int::addsub::rust_i128_subo(move _7, const 2i128) -> bb11;
// ...
// _6 = move (_10.0: i128);
// ...
// _11 = const compiler_builtins::int::mul::rust_i128_mulo(move _6, const 3i128) -> bb12;
// ...
// _5 = move (_11.0: i128);
// ...
// _12 = Eq(const 4i128, const 0i128);
// assert(!move _12, "attempt to divide by zero") -> bb4;
// ...
// _13 = Eq(const 4i128, const -1i128);
// _14 = Eq(_5, const -170141183460469231731687303715884105728i128);
// _15 = BitAnd(move _13, move _14);
// assert(!move _15, "attempt to divide with overflow") -> bb5;
// ...
// _4 = const compiler_builtins::int::sdiv::rust_i128_div(move _5, const 4i128) -> bb13;
// ...
// _17 = Eq(const 5i128, const -1i128);
// _18 = Eq(_4, const -170141183460469231731687303715884105728i128);
// _19 = BitAnd(move _17, move _18);
// assert(!move _19, "attempt to calculate the remainder with overflow") -> bb7;
// ...
// _3 = const compiler_builtins::int::sdiv::rust_i128_rem(move _4, const 5i128) -> bb15;
// ...
// _2 = move (_20.0: i128);
// ...
// _23 = const 7i32 as u128 (Misc);
// _21 = const compiler_builtins::int::shift::rust_i128_shro(move _2, move _23) -> bb16;
// ...
// _0 = move (_21.0: i128);
// ...
// assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
// ...
// assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
// ...
// assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
// ...
// _16 = Eq(const 5i128, const 0i128);
// assert(!move _16, "attempt to calculate the remainder with a divisor of zero") -> bb6;
// ...
// assert(!move (_20.1: bool), "attempt to shift left with overflow") -> bb8;
// ...
// _22 = const 6i32 as u128 (Misc);
// _20 = const compiler_builtins::int::shift::rust_i128_shlo(move _3, move _22) -> bb14;
// ...
// assert(!move (_21.1: bool), "attempt to shift right with overflow") -> bb9;
// _7 = const compiler_builtins::int::addsub::rust_i128_add(move _8, const 1i128) -> bb7;
// ...
// _10 = Eq(const 4i128, const -1i128);
// _11 = Eq(_5, const -170141183460469231731687303715884105728i128);
// _12 = BitAnd(move _10, move _11);
// assert(!move _12, "attempt to divide with overflow") -> bb2;
// ...
// _4 = const compiler_builtins::int::sdiv::rust_i128_div(move _5, const 4i128) -> bb8;
// ...
// _14 = Eq(const 5i128, const -1i128);
// _15 = Eq(_4, const -170141183460469231731687303715884105728i128);
// _16 = BitAnd(move _14, move _15);
// assert(!move _16, "attempt to calculate the remainder with overflow") -> bb4;
// ...
// _3 = const compiler_builtins::int::sdiv::rust_i128_rem(move _4, const 5i128) -> bb11;
// ...
// _9 = Eq(const 4i128, const 0i128);
// assert(!move _9, "attempt to divide by zero") -> bb1;
// ...
// _5 = const compiler_builtins::int::mul::rust_i128_mul(move _6, const 3i128) -> bb5;
// ...
// _6 = const compiler_builtins::int::addsub::rust_i128_sub(move _7, const 2i128) -> bb6;
// ...
// _13 = Eq(const 5i128, const 0i128);
// assert(!move _13, "attempt to calculate the remainder with a divisor of zero") -> bb3;
// ...
// _17 = const 7i32 as u32 (Misc);
// _0 = const compiler_builtins::int::shift::rust_i128_shr(move _2, move _17) -> bb9;
// ...
// _18 = const 6i32 as u32 (Misc);
// _2 = const compiler_builtins::int::shift::rust_i128_shl(move _3, move _18) -> bb10;
// END rustc.const_signed.Lower128Bit.after.mir
// START rustc.const_unsigned.Lower128Bit.after.mir
// _8 = _1;
// _9 = const compiler_builtins::int::addsub::rust_u128_addo(move _8, const 1u128) -> bb8;
// ...
// _7 = move (_9.0: u128);
// ...
// _10 = const compiler_builtins::int::addsub::rust_u128_subo(move _7, const 2u128) -> bb9;
// ...
// _6 = move (_10.0: u128);
// ...
// _11 = const compiler_builtins::int::mul::rust_u128_mulo(move _6, const 3u128) -> bb10;
// ...
// _5 = move (_11.0: u128);
// ...
// _12 = Eq(const 4u128, const 0u128);
// assert(!move _12, "attempt to divide by zero") -> bb4;
// ...
// _4 = const compiler_builtins::int::udiv::rust_u128_div(move _5, const 4u128) -> bb11;
// ...
// _3 = const compiler_builtins::int::udiv::rust_u128_rem(move _4, const 5u128) -> bb13;
// ...
// _2 = move (_14.0: u128);
// ...
// _17 = const 7i32 as u128 (Misc);
// _15 = const compiler_builtins::int::shift::rust_u128_shro(move _2, move _17) -> bb14;
// ...
// _0 = move (_15.0: u128);
// ...
// assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
// ...
// assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
// ...
// assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
// ...
// _13 = Eq(const 5u128, const 0u128);
// assert(!move _13, "attempt to calculate the remainder with a divisor of zero") -> bb5;
// ...
// assert(!move (_14.1: bool), "attempt to shift left with overflow") -> bb6;
// ...
// _16 = const 6i32 as u128 (Misc);
// _14 = const compiler_builtins::int::shift::rust_u128_shlo(move _3, move _16) -> bb12;
// ...
// assert(!move (_15.1: bool), "attempt to shift right with overflow") -> bb7;
// _8 = _1;
// _7 = const compiler_builtins::int::addsub::rust_u128_add(move _8, const 1u128) -> bb5;
// ...
// _4 = const compiler_builtins::int::udiv::rust_u128_div(move _5, const 4u128) -> bb6;
// ...
// _3 = const compiler_builtins::int::udiv::rust_u128_rem(move _4, const 5u128) -> bb9;
// ...
// _9 = Eq(const 4u128, const 0u128);
// assert(!move _9, "attempt to divide by zero") -> bb1;
// ...
// _5 = const compiler_builtins::int::mul::rust_u128_mul(move _6, const 3u128) -> bb3;
// ...
// _6 = const compiler_builtins::int::addsub::rust_u128_sub(move _7, const 2u128) -> bb4;
// ...
// _10 = Eq(const 5u128, const 0u128);
// assert(!move _10, "attempt to calculate the remainder with a divisor of zero") -> bb2;
// ...
// return;
// ...
// _11 = const 7i32 as u32 (Misc);
// _0 = const compiler_builtins::int::shift::rust_u128_shr(move _2, move _11) -> bb7;
// ...
// _12 = const 6i32 as u32 (Misc);
// _2 = const compiler_builtins::int::shift::rust_u128_shl(move _3, move _12) -> bb8;
// END rustc.const_unsigned.Lower128Bit.after.mir
// START rustc.test_signed.Lower128Bit.after.mir

View file

@ -11,6 +11,8 @@
// ignore-wasm32
// ignore-emscripten
// compile-flags: -C debug_assertions=yes
#![feature(const_fn, libc)]
#![allow(const_err)]
@ -19,7 +21,7 @@ extern crate libc;
use std::env;
use std::process::{Command, Stdio};
// this will panic in debug mode
// this will panic in debug mode and overflow in release mode
const fn bar() -> usize { 0 - 1 }
fn foo() {

View file

@ -4,14 +4,14 @@ note: ...which requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_
note: ...which requires const-evaluating `Foo::bytes::{{constant}}`...
--> $SRC_DIR/libcore/mem.rs:LL:COL
|
LL | unsafe { intrinsics::size_of::<T>() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | intrinsics::size_of::<T>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which again requires computing layout of `Foo`, completing the cycle
note: cycle used when const-evaluating `Foo::bytes::{{constant}}`
--> $SRC_DIR/libcore/mem.rs:LL:COL
|
LL | unsafe { intrinsics::size_of::<T>() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | intrinsics::size_of::<T>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View file

@ -0,0 +1,224 @@
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:49:25
|
LL | const fn into_inner(self) -> T { self.0 } //~ destructors cannot be evaluated
| ^^^^ constant functions cannot evaluate destructors
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:51:5
|
LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:56:28
|
LL | const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated
| ^^^^ constant functions cannot evaluate destructors
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:58:5
|
LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:63:27
|
LL | const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors
| ^^^^ constant functions cannot evaluate destructors
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:65:5
|
LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:70:5
|
LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:88:16
|
LL | const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:90:18
|
LL | const fn foo11_2<T: Send>(t: T) -> T { t }
| ^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn.rs:92:33
|
LL | const fn foo19(f: f32) -> f32 { f * 2.0 }
| ^^^^^^^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn.rs:94:35
|
LL | const fn foo19_2(f: f32) -> f32 { 2.0 - f }
| ^^^^^^^
error: only int and `bool` operations are stable in const fn
--> $DIR/min_const_fn.rs:96:35
|
LL | const fn foo19_3(f: f32) -> f32 { -f }
| ^^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn.rs:98:43
|
LL | const fn foo19_4(f: f32, g: f32) -> f32 { f / g }
| ^^^^^
error: cannot access `static` items in const fn
--> $DIR/min_const_fn.rs:102:27
|
LL | const fn foo25() -> u32 { BAR } //~ ERROR cannot access `static` items in const fn
| ^^^
error: cannot access `static` items in const fn
--> $DIR/min_const_fn.rs:103:36
|
LL | const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot access `static` items
| ^^^^
error: casting pointers to ints is unstable in const fn
--> $DIR/min_const_fn.rs:104:42
|
LL | const fn foo30(x: *const u32) -> usize { x as usize }
| ^^^^^^^^^^
error: casting pointers to ints is unstable in const fn
--> $DIR/min_const_fn.rs:106:42
|
LL | const fn foo30_2(x: *mut u32) -> usize { x as usize }
| ^^^^^^^^^^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:108:38
|
LL | const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } }
| ^^^^^^^^^^^^^^^^^^^^^^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:110:29
|
LL | const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn
| ^^^^^^^^^^^
error: local variables in const fn are unstable
--> $DIR/min_const_fn.rs:111:34
|
LL | const fn foo30_6() -> bool { let x = true; x } //~ ERROR local variables in const fn are unstable
| ^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:112:44
|
LL | const fn foo36(a: bool, b: bool) -> bool { a && b }
| ^^^^^^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:114:44
|
LL | const fn foo37(a: bool, b: bool) -> bool { a || b }
| ^^^^^^
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:116:14
|
LL | const fn inc(x: &mut i32) { *x += 1 }
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:121:6
|
LL | impl<T: std::fmt::Debug> Foo<T> {
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:126:6
|
LL | impl<T: std::fmt::Debug + Sized> Foo<T> {
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:131:6
|
LL | impl<T: Sync + Sized> Foo<T> {
| ^
error: `impl Trait` in const fn is unstable
--> $DIR/min_const_fn.rs:137:1
|
LL | const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> { AlanTuring(0) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:139:34
|
LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
| ^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:141:22
|
LL | const fn no_apit(_x: impl std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized`
| ^^^^^^^^^^^^^^^^^^^^
error: `impl Trait` in const fn is unstable
--> $DIR/min_const_fn.rs:142:1
|
LL | const fn no_rpit() -> impl std::fmt::Debug {} //~ ERROR `impl Trait` in const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:143:23
|
LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized`
| ^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:144:1
|
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0597]: borrowed value does not live long enough
--> $DIR/min_const_fn.rs:144:64
|
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
| ^^ - temporary value only lives until here
| |
| temporary value does not live long enough
|
= note: borrowed value must be valid for the static lifetime...
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:149:41
|
LL | const fn really_no_traits_i_mean_it() { (&() as &std::fmt::Debug, ()).1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: function pointers in const fn are unstable
--> $DIR/min_const_fn.rs:152:21
|
LL | const fn no_fn_ptrs(_x: fn()) {}
| ^^
error: function pointers in const fn are unstable
--> $DIR/min_const_fn.rs:154:1
|
LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 36 previous errors
Some errors occurred: E0493, E0597.
For more information about an error, try `rustc --explain E0493`.

View file

@ -0,0 +1,156 @@
// Copyright 2018 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.
#![feature(min_const_fn)]
// ok
const fn foo1() {}
const fn foo2(x: i32) -> i32 { x }
const fn foo3<T>(x: T) -> T { x }
const fn foo7() {
(
foo1(),
foo2(420),
foo3(69),
).0
}
const fn foo12<T: Sized>(t: T) -> T { t }
const fn foo13<T: ?Sized>(t: &T) -> &T { t }
const fn foo14<'a, T: 'a>(t: &'a T) -> &'a T { t }
const fn foo15<T>(t: T) -> T where T: Sized { t }
const fn foo15_2<T>(t: &T) -> &T where T: ?Sized { t }
const fn foo16(f: f32) -> f32 { f }
const fn foo17(f: f32) -> u32 { f as u32 }
const fn foo18(i: i32) -> i32 { i * 3 }
const fn foo20(b: bool) -> bool { !b }
const fn foo21<T, U>(t: T, u: U) -> (T, U) { (t, u) }
const fn foo22(s: &[u8], i: usize) -> u8 { s[i] }
const FOO: u32 = 42;
const fn foo23() -> u32 { FOO }
const fn foo24() -> &'static u32 { &FOO }
const fn foo27(x: &u32) -> u32 { *x }
const fn foo28(x: u32) -> u32 { *&x }
const fn foo29(x: u32) -> i32 { x as i32 }
const fn foo31(a: bool, b: bool) -> bool { a & b }
const fn foo32(a: bool, b: bool) -> bool { a | b }
const fn foo33(a: bool, b: bool) -> bool { a & b }
const fn foo34(a: bool, b: bool) -> bool { a | b }
const fn foo35(a: bool, b: bool) -> bool { a ^ b }
struct Foo<T: ?Sized>(T);
impl<T> Foo<T> {
const fn new(t: T) -> Self { Foo(t) }
const fn into_inner(self) -> T { self.0 } //~ destructors cannot be evaluated
const fn get(&self) -> &T { &self.0 }
const fn get_mut(&mut self) -> &mut T { &mut self.0 }
//~^ mutable references in const fn are unstable
}
impl<'a, T> Foo<T> {
const fn new_lt(t: T) -> Self { Foo(t) }
const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated
const fn get_lt(&'a self) -> &T { &self.0 }
const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
//~^ mutable references in const fn are unstable
}
impl<T: Sized> Foo<T> {
const fn new_s(t: T) -> Self { Foo(t) }
const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors
const fn get_s(&self) -> &T { &self.0 }
const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
//~^ mutable references in const fn are unstable
}
impl<T: ?Sized> Foo<T> {
const fn get_sq(&self) -> &T { &self.0 }
const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
//~^ mutable references in const fn are unstable
}
const fn char_ops(c: char, d: char) -> bool { c == d }
const fn char_ops2(c: char, d: char) -> bool { c < d }
const fn char_ops3(c: char, d: char) -> bool { c != d }
const fn i32_ops(c: i32, d: i32) -> bool { c == d }
const fn i32_ops2(c: i32, d: i32) -> bool { c < d }
const fn i32_ops3(c: i32, d: i32) -> bool { c != d }
const fn i32_ops4(c: i32, d: i32) -> i32 { c + d }
const fn char_cast(u: u8) -> char { u as char }
const unsafe fn foo4() -> i32 { 42 }
const unsafe fn foo5<T>() -> *const T { 0 as *const T }
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
// not ok
const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
const fn foo11_2<T: Send>(t: T) -> T { t }
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
const fn foo19(f: f32) -> f32 { f * 2.0 }
//~^ ERROR only int, `bool` and `char` operations are stable in const fn
const fn foo19_2(f: f32) -> f32 { 2.0 - f }
//~^ ERROR only int, `bool` and `char` operations are stable in const fn
const fn foo19_3(f: f32) -> f32 { -f }
//~^ ERROR only int and `bool` operations are stable in const fn
const fn foo19_4(f: f32, g: f32) -> f32 { f / g }
//~^ ERROR only int, `bool` and `char` operations are stable in const fn
static BAR: u32 = 42;
const fn foo25() -> u32 { BAR } //~ ERROR cannot access `static` items in const fn
const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot access `static` items
const fn foo30(x: *const u32) -> usize { x as usize }
//~^ ERROR casting pointers to int
const fn foo30_2(x: *mut u32) -> usize { x as usize }
//~^ ERROR casting pointers to int
const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } }
//~^ ERROR `if`, `match`, `&&` and `||` are not stable in const fn
const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn
const fn foo30_6() -> bool { let x = true; x } //~ ERROR local variables in const fn are unstable
const fn foo36(a: bool, b: bool) -> bool { a && b }
//~^ ERROR `if`, `match`, `&&` and `||` are not stable in const fn
const fn foo37(a: bool, b: bool) -> bool { a || b }
//~^ ERROR `if`, `match`, `&&` and `||` are not stable in const fn
const fn inc(x: &mut i32) { *x += 1 }
//~^ ERROR mutable references in const fn are unstable
fn main() {}
impl<T: std::fmt::Debug> Foo<T> {
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
const fn foo(&self) {}
}
impl<T: std::fmt::Debug + Sized> Foo<T> {
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
const fn foo2(&self) {}
}
impl<T: Sync + Sized> Foo<T> {
//~^ ERROR trait bounds other than `Sized` on const fn parameters are unstable
const fn foo3(&self) {}
}
struct AlanTuring<T>(T);
const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> { AlanTuring(0) }
//~^ ERROR `impl Trait` in const fn is unstable
const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
//~^ ERROR trait bounds other than `Sized`
const fn no_apit(_x: impl std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized`
const fn no_rpit() -> impl std::fmt::Debug {} //~ ERROR `impl Trait` in const fn is unstable
const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized`
const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
//~^ ERROR trait bounds other than `Sized`
const fn no_unsafe() { unsafe {} }
const fn really_no_traits_i_mean_it() { (&() as &std::fmt::Debug, ()).1 }
//~^ ERROR trait bounds other than `Sized`
const fn no_fn_ptrs(_x: fn()) {}
//~^ ERROR function pointers in const fn are unstable
const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
//~^ ERROR function pointers in const fn are unstable

View file

@ -0,0 +1,213 @@
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:49:25
|
LL | const fn into_inner(self) -> T { self.0 } //~ destructors cannot be evaluated
| ^^^^ constant functions cannot evaluate destructors
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:51:5
|
LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:56:28
|
LL | const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated
| ^^^^ constant functions cannot evaluate destructors
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:58:5
|
LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0493]: destructors cannot be evaluated at compile-time
--> $DIR/min_const_fn.rs:63:27
|
LL | const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors
| ^^^^ constant functions cannot evaluate destructors
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:65:5
|
LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:70:5
|
LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:88:16
|
LL | const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:90:18
|
LL | const fn foo11_2<T: Send>(t: T) -> T { t }
| ^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn.rs:92:33
|
LL | const fn foo19(f: f32) -> f32 { f * 2.0 }
| ^^^^^^^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn.rs:94:35
|
LL | const fn foo19_2(f: f32) -> f32 { 2.0 - f }
| ^^^^^^^
error: only int and `bool` operations are stable in const fn
--> $DIR/min_const_fn.rs:96:35
|
LL | const fn foo19_3(f: f32) -> f32 { -f }
| ^^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn.rs:98:43
|
LL | const fn foo19_4(f: f32, g: f32) -> f32 { f / g }
| ^^^^^
error: cannot access `static` items in const fn
--> $DIR/min_const_fn.rs:102:27
|
LL | const fn foo25() -> u32 { BAR } //~ ERROR cannot access `static` items in const fn
| ^^^
error: cannot access `static` items in const fn
--> $DIR/min_const_fn.rs:103:36
|
LL | const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot access `static` items
| ^^^^
error: casting pointers to ints is unstable in const fn
--> $DIR/min_const_fn.rs:104:42
|
LL | const fn foo30(x: *const u32) -> usize { x as usize }
| ^^^^^^^^^^
error: casting pointers to ints is unstable in const fn
--> $DIR/min_const_fn.rs:106:42
|
LL | const fn foo30_2(x: *mut u32) -> usize { x as usize }
| ^^^^^^^^^^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:108:38
|
LL | const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } }
| ^^^^^^^^^^^^^^^^^^^^^^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:110:29
|
LL | const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn
| ^^^^^^^^^^^
error: local variables in const fn are unstable
--> $DIR/min_const_fn.rs:111:34
|
LL | const fn foo30_6() -> bool { let x = true; x } //~ ERROR local variables in const fn are unstable
| ^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:112:44
|
LL | const fn foo36(a: bool, b: bool) -> bool { a && b }
| ^^^^^^
error: `if`, `match`, `&&` and `||` are not stable in const fn
--> $DIR/min_const_fn.rs:114:44
|
LL | const fn foo37(a: bool, b: bool) -> bool { a || b }
| ^^^^^^
error: mutable references in const fn are unstable
--> $DIR/min_const_fn.rs:116:14
|
LL | const fn inc(x: &mut i32) { *x += 1 }
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:121:6
|
LL | impl<T: std::fmt::Debug> Foo<T> {
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:126:6
|
LL | impl<T: std::fmt::Debug + Sized> Foo<T> {
| ^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:131:6
|
LL | impl<T: Sync + Sized> Foo<T> {
| ^
error: `impl Trait` in const fn is unstable
--> $DIR/min_const_fn.rs:137:1
|
LL | const fn no_rpit2() -> AlanTuring<impl std::fmt::Debug> { AlanTuring(0) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:139:34
|
LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
| ^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:141:22
|
LL | const fn no_apit(_x: impl std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized`
| ^^^^^^^^^^^^^^^^^^^^
error: `impl Trait` in const fn is unstable
--> $DIR/min_const_fn.rs:142:1
|
LL | const fn no_rpit() -> impl std::fmt::Debug {} //~ ERROR `impl Trait` in const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:143:23
|
LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized`
| ^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:144:1
|
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn.rs:149:41
|
LL | const fn really_no_traits_i_mean_it() { (&() as &std::fmt::Debug, ()).1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: function pointers in const fn are unstable
--> $DIR/min_const_fn.rs:152:21
|
LL | const fn no_fn_ptrs(_x: fn()) {}
| ^^
error: function pointers in const fn are unstable
--> $DIR/min_const_fn.rs:154:1
|
LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 35 previous errors
For more information about this error, try `rustc --explain E0493`.

View file

@ -0,0 +1,25 @@
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn_dyn.rs:21:5
|
LL | x.0.field;
| ^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn_dyn.rs:24:66
|
LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
| ^^
error[E0597]: borrowed value does not live long enough
--> $DIR/min_const_fn_dyn.rs:24:67
|
LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
| ^ - temporary value only lives until here
| |
| temporary value does not live long enough
|
= note: borrowed value must be valid for the static lifetime...
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0597`.

View file

@ -0,0 +1,27 @@
// Copyright 2018 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.
#![feature(min_const_fn)]
struct HasDyn {
field: &'static dyn std::fmt::Debug,
}
struct Hide(HasDyn);
const fn no_inner_dyn_trait(_x: Hide) {}
const fn no_inner_dyn_trait2(x: Hide) {
x.0.field;
//~^ ERROR trait bounds other than `Sized`
}
const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
//~^ ERROR trait bounds other than `Sized`
fn main() {}

View file

@ -0,0 +1,14 @@
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn_dyn.rs:21:5
|
LL | x.0.field;
| ^^^^^^^^^
error: trait bounds other than `Sized` on const fn parameters are unstable
--> $DIR/min_const_fn_dyn.rs:24:66
|
LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
| ^^
error: aborting due to 2 previous errors

View file

@ -0,0 +1,29 @@
// Copyright 2018 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.
#![feature(min_const_fn)]
struct HasPtr {
field: fn(),
}
struct Hide(HasPtr);
fn field() {}
const fn no_inner_dyn_trait(_x: Hide) {}
const fn no_inner_dyn_trait2(x: Hide) {
x.0.field;
//~^ ERROR function pointers in const fn
}
const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasPtr { field }) }
//~^ ERROR function pointers in const fn
fn main() {}

View file

@ -0,0 +1,14 @@
error: function pointers in const fn are unstable
--> $DIR/min_const_fn_fn_ptr.rs:23:5
|
LL | x.0.field;
| ^^^^^^^^^
error: function pointers in const fn are unstable
--> $DIR/min_const_fn_fn_ptr.rs:26:59
|
LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasPtr { field }) }
| ^^^^^
error: aborting due to 2 previous errors

View file

@ -0,0 +1,38 @@
// Copyright 2018 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.
#![unstable(feature = "humans",
reason = "who ever let humans program computers,
we're apparently really bad at it",
issue = "0")]
#![feature(rustc_const_unstable, const_fn, foo)]
#![feature(staged_api)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo")]
const fn foo() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn`
#[unstable(feature = "rust1", issue="0")]
const fn foo2() -> u32 { 42 }
#[stable(feature = "rust1", since = "1.0.0")]
// can't call non-min_const_fn
const fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn`
#[stable(feature = "rust1", since = "1.0.0")]
// conformity is required, even with `const_fn` feature gate
const fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` operations
fn main() {}

View file

@ -0,0 +1,20 @@
error: can only call other `min_const_fn` within a `min_const_fn`
--> $DIR/min_const_fn_libstd_stability.rs:25:25
|
LL | const fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn`
| ^^^^^
error: can only call other `min_const_fn` within a `min_const_fn`
--> $DIR/min_const_fn_libstd_stability.rs:32:26
|
LL | const fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn`
| ^^^^^^
error: only int, `bool` and `char` operations are stable in const fn
--> $DIR/min_const_fn_libstd_stability.rs:36:26
|
LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` operations
| ^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View file

@ -0,0 +1,38 @@
// Copyright 2018 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.
#![feature(min_const_fn)]
// ok
const unsafe fn foo4() -> i32 { 42 }
const unsafe fn foo5<T>() -> *const T { 0 as *const T }
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
const fn no_unsafe() { unsafe {} }
// not ok
const fn foo8() -> i32 {
unsafe { foo4() } //~ ERROR unsafe operations are not allowed in const fn
}
const fn foo9() -> *const String {
unsafe { foo5::<String>() } //~ ERROR unsafe operations are not allowed in const fn
}
const fn foo10() -> *const Vec<std::cell::Cell<u32>> {
unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR not allowed in const fn
}
const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
//~^ dereferencing raw pointers in constant functions
fn main() {}
const unsafe fn no_union() {
union Foo { x: (), y: () }
Foo { x: () }.y //~ ERROR not allowed in const fn
//~^ unions in const fn
}

View file

@ -0,0 +1,59 @@
error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911)
--> $DIR/min_const_fn_unsafe.rs:29:51
|
LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
| ^^
|
= help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable
error[E0658]: unions in const fn are unstable (see issue #51909)
--> $DIR/min_const_fn_unsafe.rs:36:5
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn_union)] to the crate attributes to enable
error: call to unsafe function is unsafe and unsafe operations are not allowed in const fn
--> $DIR/min_const_fn_unsafe.rs:21:14
|
LL | unsafe { foo4() } //~ ERROR unsafe operations are not allowed in const fn
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: call to unsafe function is unsafe and unsafe operations are not allowed in const fn
--> $DIR/min_const_fn_unsafe.rs:24:14
|
LL | unsafe { foo5::<String>() } //~ ERROR unsafe operations are not allowed in const fn
| ^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: call to unsafe function is unsafe and unsafe operations are not allowed in const fn
--> $DIR/min_const_fn_unsafe.rs:27:14
|
LL | unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
error: dereference of raw pointer is unsafe and unsafe operations are not allowed in const fn
--> $DIR/min_const_fn_unsafe.rs:29:51
|
LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
| ^^ dereference of raw pointer
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
error: access to union field is unsafe and unsafe operations are not allowed in const fn
--> $DIR/min_const_fn_unsafe.rs:36:5
|
LL | Foo { x: () }.y //~ ERROR not allowed in const fn
| ^^^^^^^^^^^^^^^ access to union field
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0658`.

View file

@ -4,8 +4,8 @@ error[E0308]: intrinsic has wrong type
LL | fn size_of<T>(); //~ ERROR E0308
| ^^^^^^^^^^^^^^^^ expected (), found usize
|
= note: expected type `unsafe extern "rust-intrinsic" fn()`
found type `unsafe extern "rust-intrinsic" fn() -> usize`
= note: expected type `extern "rust-intrinsic" fn()`
found type `extern "rust-intrinsic" fn() -> usize`
error: aborting due to previous error

View file

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test use of const fn without feature gate.
// Test use of const fn without the `const_fn` feature gate.
// `min_const_fn` is checked in its own file
#![feature(min_const_fn)]
const fn foo() -> usize { 0 } //~ ERROR const fn is unstable
const fn foo() -> usize { 0 } // ok
trait Foo {
const fn foo() -> u32; //~ ERROR const fn is unstable
@ -20,12 +22,11 @@ trait Foo {
}
impl Foo {
const fn baz() -> u32 { 0 } //~ ERROR const fn is unstable
const fn baz() -> u32 { 0 } // ok
}
impl Foo for u32 {
const fn foo() -> u32 { 0 } //~ ERROR const fn is unstable
//~| ERROR trait fns cannot be declared const
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
}
static FOO: usize = foo();

View file

@ -1,31 +1,23 @@
error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-const_fn.rs:16:5
--> $DIR/feature-gate-const_fn.rs:18:5
|
LL | const fn foo() -> u32; //~ ERROR const fn is unstable
| ^^^^^ trait fns cannot be const
error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-const_fn.rs:18:5
--> $DIR/feature-gate-const_fn.rs:20:5
|
LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^ trait fns cannot be const
error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-const_fn.rs:27:5
--> $DIR/feature-gate-const_fn.rs:29:5
|
LL | const fn foo() -> u32 { 0 } //~ ERROR const fn is unstable
LL | const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
| ^^^^^ trait fns cannot be const
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-const_fn.rs:13:1
|
LL | const fn foo() -> usize { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-const_fn.rs:16:5
--> $DIR/feature-gate-const_fn.rs:18:5
|
LL | const fn foo() -> u32; //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^
@ -33,30 +25,14 @@ LL | const fn foo() -> u32; //~ ERROR const fn is unstable
= help: add #![feature(const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-const_fn.rs:18:5
--> $DIR/feature-gate-const_fn.rs:20:5
|
LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-const_fn.rs:23:5
|
LL | const fn baz() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-const_fn.rs:27:5
|
LL | const fn foo() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
error: aborting due to 8 previous errors
error: aborting due to 5 previous errors
Some errors occurred: E0379, E0658.
For more information about an error, try `rustc --explain E0379`.

View file

@ -0,0 +1,46 @@
// 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 min_const_fn without feature gate.
const fn foo() -> usize { 0 } //~ ERROR const fn is unstable
trait Foo {
const fn foo() -> u32; //~ ERROR const fn is unstable
//~| ERROR trait fns cannot be declared const
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
//~| ERROR trait fns cannot be declared const
}
impl Foo {
const fn baz() -> u32 { 0 } //~ ERROR const fn is unstable
}
impl Foo for u32 {
const fn foo() -> u32 { 0 } //~ ERROR const fn is unstable
//~| ERROR trait fns cannot be declared const
}
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,62 @@
error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-min_const_fn.rs:16:5
|
LL | const fn foo() -> u32; //~ ERROR const fn is unstable
| ^^^^^ trait fns cannot be const
error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-min_const_fn.rs:18:5
|
LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^ trait fns cannot be const
error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-min_const_fn.rs:27:5
|
LL | const fn foo() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^ trait fns cannot be const
error[E0658]: const fn is unstable (see issue #53555)
--> $DIR/feature-gate-min_const_fn.rs:13:1
|
LL | const fn foo() -> usize { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(min_const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-min_const_fn.rs:16:5
|
LL | const fn foo() -> u32; //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #24111)
--> $DIR/feature-gate-min_const_fn.rs:18:5
|
LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #53555)
--> $DIR/feature-gate-min_const_fn.rs:23:5
|
LL | const fn baz() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(min_const_fn)] to the crate attributes to enable
error[E0658]: const fn is unstable (see issue #53555)
--> $DIR/feature-gate-min_const_fn.rs:27:5
|
LL | const fn foo() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(min_const_fn)] to the crate attributes to enable
error: aborting due to 8 previous errors
Some errors occurred: E0379, E0658.
For more information about an error, try `rustc --explain E0379`.