Report let bindings and statements as unstable
This commit is contained in:
parent
d7bf358dbd
commit
8a5eb68958
16 changed files with 150 additions and 65 deletions
30
src/test/ui/const-eval/const_let.rs
Normal file
30
src/test/ui/const-eval/const_let.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// 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(const_let)]
|
||||
|
||||
fn main() {}
|
||||
|
||||
struct FakeNeedsDrop;
|
||||
|
||||
impl Drop for FakeNeedsDrop {
|
||||
fn drop(&mut self) {}
|
||||
}
|
||||
|
||||
// ok
|
||||
const X: FakeNeedsDrop = { let x = FakeNeedsDrop; x };
|
||||
|
||||
// error
|
||||
const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x };
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
|
||||
// error
|
||||
const Z: () = { let mut x = None; x = Some(FakeNeedsDrop); };
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
15
src/test/ui/const-eval/const_let.stderr
Normal file
15
src/test/ui/const-eval/const_let.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error[E0019]: constant contains unimplemented expression type
|
||||
--> $DIR/const_let.rs:25:55
|
||||
|
|
||||
LL | const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x };
|
||||
| ^
|
||||
|
||||
error[E0019]: constant contains unimplemented expression type
|
||||
--> $DIR/const_let.rs:29:35
|
||||
|
|
||||
LL | const Z: () = { let mut x = None; x = Some(FakeNeedsDrop); };
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
@ -14,7 +14,8 @@ const X : usize = 2;
|
|||
|
||||
const fn f(x: usize) -> usize {
|
||||
let mut sum = 0;
|
||||
//~^ ERROR E0016
|
||||
//~^ let bindings in constant functions are unstable
|
||||
//~| statements in constant functions are unstable
|
||||
for i in 0..x {
|
||||
//~^ ERROR E0015
|
||||
//~| ERROR E0019
|
||||
|
|
|
|||
|
|
@ -1,23 +1,33 @@
|
|||
error[E0016]: blocks in constant functions are limited to items and tail expressions
|
||||
error[E0658]: let bindings in constant functions are unstable (see issue #48821)
|
||||
--> $DIR/const-fn-error.rs:16:19
|
||||
|
|
||||
LL | let mut sum = 0;
|
||||
| ^
|
||||
|
|
||||
= help: add #![feature(const_let)] to the crate attributes to enable
|
||||
|
||||
error[E0658]: statements in constant functions are unstable (see issue #48821)
|
||||
--> $DIR/const-fn-error.rs:16:19
|
||||
|
|
||||
LL | let mut sum = 0;
|
||||
| ^
|
||||
|
|
||||
= help: add #![feature(const_let)] to the crate attributes to enable
|
||||
|
||||
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/const-fn-error.rs:18:14
|
||||
--> $DIR/const-fn-error.rs:19:14
|
||||
|
|
||||
LL | for i in 0..x {
|
||||
| ^^^^
|
||||
|
||||
error[E0019]: constant function contains unimplemented expression type
|
||||
--> $DIR/const-fn-error.rs:18:14
|
||||
--> $DIR/const-fn-error.rs:19:14
|
||||
|
|
||||
LL | for i in 0..x {
|
||||
| ^^^^
|
||||
|
||||
error[E0080]: constant evaluation error
|
||||
--> $DIR/const-fn-error.rs:18:14
|
||||
--> $DIR/const-fn-error.rs:19:14
|
||||
|
|
||||
LL | for i in 0..x {
|
||||
| ^^^^ calling non-const fn `<I as std::iter::IntoIterator><std::ops::Range<usize>>::into_iter`
|
||||
|
|
@ -26,12 +36,12 @@ LL | let a : [i32; f(X)];
|
|||
| ---- inside call to `f`
|
||||
|
|
||||
note: for constant expression here
|
||||
--> $DIR/const-fn-error.rs:29:13
|
||||
--> $DIR/const-fn-error.rs:30:13
|
||||
|
|
||||
LL | let a : [i32; f(X)];
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors occurred: E0015, E0016, E0019, E0080.
|
||||
Some errors occurred: E0015, E0019, E0080, E0658.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@
|
|||
#![feature(const_fn)]
|
||||
|
||||
const fn foo() -> usize {
|
||||
let x = 42; //~ ERROR blocks in constant functions are limited to items and tail expressions
|
||||
let x = 42;
|
||||
//~^ ERROR statements in constant functions are unstable
|
||||
//~| ERROR: let bindings in constant functions are unstable
|
||||
42
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,19 @@
|
|||
error[E0016]: blocks in constant functions are limited to items and tail expressions
|
||||
error[E0658]: let bindings in constant functions are unstable (see issue #48821)
|
||||
--> $DIR/feature-gate-const_let.rs:16:13
|
||||
|
|
||||
LL | let x = 42; //~ ERROR blocks in constant functions are limited to items and tail expressions
|
||||
LL | let x = 42;
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(const_let)] to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0658]: statements in constant functions are unstable (see issue #48821)
|
||||
--> $DIR/feature-gate-const_let.rs:16:13
|
||||
|
|
||||
LL | let x = 42;
|
||||
| ^^
|
||||
|
|
||||
= help: add #![feature(const_let)] to the crate attributes to enable
|
||||
|
||||
For more information about this error, try `rustc --explain E0016`.
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue