Add specific error for unstable const fn features
This commit is contained in:
parent
f47ec2ad5b
commit
2c339aeb7b
@ -2370,6 +2370,37 @@ fn foo() -> i32 { 22 }
|
||||
```
|
||||
"##,
|
||||
|
||||
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! {
|
||||
|
@ -1206,7 +1206,17 @@ fn run_pass<'a, 'tcx>(&self,
|
||||
// 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)
|
||||
|
Loading…
Reference in New Issue
Block a user