Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specific feature gate error for const-unstable features #58196

Merged
merged 4 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/librustc_mir/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,37 @@ let value = (&foo(), &foo());
```
"##,

E0723: r##"
An feature unstable in `const` contexts was used.

Erroneous code example:

```compile_fail,E0723
trait T {}

impl T for () {}

const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable
()
}
```

To enable this feature on a nightly version of rustc, add the `const_fn`
feature flag:

```
#![feature(const_fn)]

trait T {}

impl T for () {}

const fn foo() -> impl T {
()
}
```
"##,

}

register_diagnostics! {
Expand Down
12 changes: 11 additions & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,17 @@ impl MirPass for QualifyAndPromoteConstants {
// enforce `min_const_fn` for stable const fns
use super::qualify_min_const_fn::is_min_const_fn;
if let Err((span, err)) = is_min_const_fn(tcx, def_id, mir) {
tcx.sess.span_err(span, &err);
let mut diag = struct_span_err!(
tcx.sess,
span,
E0723,
"{} (see issue #57563)",
err,
);
diag.help(
"add #![feature(const_fn)] to the crate attributes to enable",
);
diag.emit();
} else {
// this should not produce any errors, but better safe than sorry
// FIXME(#53819)
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
error: heap allocations are not allowed in const fn
error[E0723]: heap allocations are not allowed in const fn (see issue #57563)
--> $DIR/bad_const_fn_body_ice.rs:2:5
|
LL | vec![1, 2, 3] //~ ERROR heap allocations are not allowed in const fn
| ^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0723`.
21 changes: 16 additions & 5 deletions src/test/ui/consts/min_const_fn/cast_errors.stderr
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
error: unsizing casts are not allowed in const fn
error[E0723]: unsizing casts are not allowed in const fn (see issue #57563)
--> $DIR/cast_errors.rs:3:41
|
LL | const fn unsize(x: &[u8; 3]) -> &[u8] { x }
| ^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: function pointers in const fn are unstable
error[E0723]: function pointers in const fn are unstable (see issue #57563)
--> $DIR/cast_errors.rs:5:23
|
LL | const fn closure() -> fn() { || {} }
| ^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: function pointers in const fn are unstable
error[E0723]: function pointers in const fn are unstable (see issue #57563)
--> $DIR/cast_errors.rs:8:5
|
LL | (|| {}) as fn();
| ^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: function pointers in const fn are unstable
error[E0723]: function pointers in const fn are unstable (see issue #57563)
--> $DIR/cast_errors.rs:11:28
|
LL | const fn reify(f: fn()) -> unsafe fn() { f }
| ^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: function pointers in const fn are unstable
error[E0723]: function pointers in const fn are unstable (see issue #57563)
--> $DIR/cast_errors.rs:13:21
|
LL | const fn reify2() { main as unsafe fn(); }
| ^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0723`.
5 changes: 4 additions & 1 deletion src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
error: function pointers in const fn are unstable
error[E0723]: function pointers in const fn are unstable (see issue #57563)
--> $DIR/cmp_fn_pointers.rs:1:14
|
LL | const fn cmp(x: fn(), y: fn()) -> bool { //~ ERROR function pointers in const fn are unstable
| ^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0723`.
5 changes: 4 additions & 1 deletion src/test/ui/consts/min_const_fn/loop_ice.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
error: loops are not allowed in const fn
error[E0723]: loops are not allowed in const fn (see issue #57563)
--> $DIR/loop_ice.rs:2:5
|
LL | loop {} //~ ERROR loops are not allowed in const fn
| ^^^^^^^
|
= help: add #![feature(const_fn)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0723`.
Loading