Skip to content

Commit

Permalink
Add specific error for unstable const fn features
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Feb 14, 2019
1 parent f47ec2a commit 2c339ae
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
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:
```compile_fail,E0723
#![feature(const_fn)]
trait T {}
impl T for () {}
const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable
()
}
```
"##,

}

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

0 comments on commit 2c339ae

Please sign in to comment.