diff options
| author | varkor <github@varkor.com> | 2019-02-05 21:27:26 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-02-14 15:04:37 +0000 |
| commit | 2c339aeb7bec40777b606889b9bd256fcea1dece (patch) | |
| tree | 4b96eb985c0ec4b3df73de412f5846224f8076f2 /src | |
| parent | f47ec2ad5b6887b3d400aee49e2294bd27733d18 (diff) | |
| download | rust-2c339aeb7bec40777b606889b9bd256fcea1dece.tar.gz rust-2c339aeb7bec40777b606889b9bd256fcea1dece.zip | |
Add specific error for unstable const fn features
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/diagnostics.rs | 31 | ||||
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 12 |
2 files changed, 42 insertions, 1 deletions
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 @@ 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! { 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 @@ impl MirPass for QualifyAndPromoteConstants { // 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) |
