Skip to content

Commit 703540d

Browse files
committed
Add specific error for unstable const fn features
1 parent b2c6b8c commit 703540d

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/librustc_mir/diagnostics.rs

+31
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,37 @@ let value = (&foo(), &foo());
23702370
```
23712371
"##,
23722372

2373+
E0723: r##"
2374+
An feature unstable in `const` contexts was used.
2375+
2376+
Erroneous code example:
2377+
2378+
```compile_fail,E0723
2379+
trait T {}
2380+
2381+
impl T for () {}
2382+
2383+
const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable
2384+
()
2385+
}
2386+
```
2387+
2388+
To enable this feature on a nightly version of rustc, add the `const_fn`
2389+
feature flag:
2390+
2391+
```compile_fail,E0723
2392+
#![feature(const_fn)]
2393+
2394+
trait T {}
2395+
2396+
impl T for () {}
2397+
2398+
const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable
2399+
()
2400+
}
2401+
```
2402+
"##,
2403+
23732404
}
23742405

23752406
register_diagnostics! {

src/librustc_mir/transform/qualify_consts.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,17 @@ impl MirPass for QualifyAndPromoteConstants {
11791179
// enforce `min_const_fn` for stable const fns
11801180
use super::qualify_min_const_fn::is_min_const_fn;
11811181
if let Err((span, err)) = is_min_const_fn(tcx, def_id, mir) {
1182-
tcx.sess.span_err(span, &err);
1182+
let mut diag = struct_span_err!(
1183+
tcx.sess,
1184+
span,
1185+
E0723,
1186+
"{} (see issue #57563)",
1187+
err,
1188+
);
1189+
diag.help(
1190+
"add #![feature(const_fn)] to the crate attributes to enable",
1191+
);
1192+
diag.emit();
11831193
} else {
11841194
// this should not produce any errors, but better safe than sorry
11851195
// FIXME(#53819)

0 commit comments

Comments
 (0)