Add specific error for unstable const fn features
This commit is contained in:
parent
f47ec2ad5b
commit
2c339aeb7b
2 changed files with 42 additions and 1 deletions
|
@ -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! {
|
register_diagnostics! {
|
||||||
|
|
|
@ -1206,7 +1206,17 @@ impl MirPass for QualifyAndPromoteConstants {
|
||||||
// enforce `min_const_fn` for stable const fns
|
// enforce `min_const_fn` for stable const fns
|
||||||
use super::qualify_min_const_fn::is_min_const_fn;
|
use super::qualify_min_const_fn::is_min_const_fn;
|
||||||
if let Err((span, err)) = is_min_const_fn(tcx, def_id, mir) {
|
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 {
|
} else {
|
||||||
// this should not produce any errors, but better safe than sorry
|
// this should not produce any errors, but better safe than sorry
|
||||||
// FIXME(#53819)
|
// FIXME(#53819)
|
||||||
|
|
Loading…
Reference in a new issue