Skip to content

Commit 2c339ae

Browse files
committed
Add specific error for unstable const fn features
1 parent f47ec2a commit 2c339ae

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
@@ -1206,7 +1206,17 @@ impl MirPass for QualifyAndPromoteConstants {
12061206
// enforce `min_const_fn` for stable const fns
12071207
use super::qualify_min_const_fn::is_min_const_fn;
12081208
if let Err((span, err)) = is_min_const_fn(tcx, def_id, mir) {
1209-
tcx.sess.span_err(span, &err);
1209+
let mut diag = struct_span_err!(
1210+
tcx.sess,
1211+
span,
1212+
E0723,
1213+
"{} (see issue #57563)",
1214+
err,
1215+
);
1216+
diag.help(
1217+
"add #![feature(const_fn)] to the crate attributes to enable",
1218+
);
1219+
diag.emit();
12101220
} else {
12111221
// this should not produce any errors, but better safe than sorry
12121222
// FIXME(#53819)

0 commit comments

Comments
 (0)