Skip to content

Commit f235b6f

Browse files
committed
give a hint which feature is missing
1 parent 822762c commit f235b6f

File tree

6 files changed

+36
-19
lines changed

6 files changed

+36
-19
lines changed

Diff for: compiler/rustc_const_eval/src/check_consts/ops.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,15 @@ impl<'tcx> NonConstOp<'tcx> for ConditionallyConstCall<'tcx> {
8989
}
9090

9191
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
92-
ccx.dcx().create_err(errors::ConditionallyConstCall {
93-
span,
94-
def_path_str: ccx.tcx.def_path_str_with_args(self.callee, self.args),
95-
def_descr: ccx.tcx.def_descr(self.callee),
96-
kind: ccx.const_kind(),
97-
})
92+
ccx.tcx.sess.create_feature_err(
93+
errors::ConditionallyConstCall {
94+
span,
95+
def_path_str: ccx.tcx.def_path_str_with_args(self.callee, self.args),
96+
def_descr: ccx.tcx.def_descr(self.callee),
97+
kind: ccx.const_kind(),
98+
},
99+
sym::const_trait_impl,
100+
)
98101
}
99102
}
100103

@@ -417,15 +420,8 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
417420

418421
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
419422
let msg = format!("{:#}s are not allowed in {}s", self.0, ccx.const_kind());
420-
if let hir::CoroutineKind::Desugared(
421-
hir::CoroutineDesugaring::Async,
422-
hir::CoroutineSource::Block,
423-
) = self.0
424-
{
425-
ccx.tcx.sess.create_feature_err(
426-
errors::UnallowedOpInConstContext { span, msg },
427-
sym::const_async_blocks,
428-
)
423+
if let Status::Unstable { gate, .. } = self.status_in_item(ccx) {
424+
ccx.tcx.sess.create_feature_err(errors::UnallowedOpInConstContext { span, msg }, gate)
429425
} else {
430426
ccx.dcx().create_err(errors::UnallowedOpInConstContext { span, msg })
431427
}

Diff for: compiler/rustc_session/src/parse.rs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ pub fn feature_warn_issue(
155155
}
156156

157157
/// Adds the diagnostics for a feature to an existing error.
158+
/// Must be a language feature!
158159
pub fn add_feature_diagnostics<G: EmissionGuarantee>(
159160
err: &mut Diag<'_, G>,
160161
sess: &Session,

Diff for: compiler/rustc_session/src/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ impl Session {
300300
self.opts.test
301301
}
302302

303+
/// `feature` must be a language feature.
303304
#[track_caller]
304305
pub fn create_feature_err<'a>(&'a self, err: impl Diagnostic<'a>, feature: Symbol) -> Diag<'a> {
305306
let mut err = self.dcx().create_err(err);
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
error: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
1+
error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
22
--> $DIR/cross-crate.rs:22:5
33
|
44
LL | Const.func();
55
| ^^^^^^^^^^^^
6+
|
7+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
8+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
610

711
error: aborting due to 1 previous error
812

13+
For more information about this error, try `rustc --explain E0658`.
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1-
error: cannot call conditionally-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions
1+
error[E0658]: cannot call conditionally-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions
22
--> $DIR/cross-crate.rs:19:5
33
|
44
LL | NonConst.func();
55
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
8+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
610

7-
error: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
11+
error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
812
--> $DIR/cross-crate.rs:22:5
913
|
1014
LL | Const.func();
1115
| ^^^^^^^^^^^^
16+
|
17+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
18+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1220

1321
error: aborting due to 2 previous errors
1422

23+
For more information about this error, try `rustc --explain E0658`.
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
error: cannot call conditionally-const associated function `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions
1+
error[E0658]: cannot call conditionally-const associated function `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions
22
--> $DIR/staged-api-user-crate.rs:12:5
33
|
44
LL | Unstable::func();
55
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
8+
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
610

711
error: aborting due to 1 previous error
812

13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)