diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 31aa3c27826..084a6529908 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -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! { diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index c593be4e67f..2066a50e7fb 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -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)