diff options
| author | Ralf Jung <post@ralfj.de> | 2024-11-09 23:32:06 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-11-09 23:32:06 +0100 |
| commit | f235b6f9c6788e213b6365103cfa9c6c798fe659 (patch) | |
| tree | 57a57420aca41b847ee3e9af48bb4434cdbc48b6 | |
| parent | 822762c966b0c8e85c0a552929a5a9c53bf93a97 (diff) | |
| download | rust-f235b6f9c6788e213b6365103cfa9c6c798fe659.tar.gz rust-f235b6f9c6788e213b6365103cfa9c6c798fe659.zip | |
give a hint which feature is missing
| -rw-r--r-- | compiler/rustc_const_eval/src/check_consts/ops.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_session/src/parse.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 1 | ||||
| -rw-r--r-- | tests/ui/traits/const-traits/cross-crate.stock.stderr | 7 | ||||
| -rw-r--r-- | tests/ui/traits/const-traits/cross-crate.stocknc.stderr | 13 | ||||
| -rw-r--r-- | tests/ui/traits/const-traits/staged-api-user-crate.stderr | 7 |
6 files changed, 36 insertions, 19 deletions
diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 5b745e6dffd..036ca763280 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -89,12 +89,15 @@ impl<'tcx> NonConstOp<'tcx> for ConditionallyConstCall<'tcx> { } fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { - ccx.dcx().create_err(errors::ConditionallyConstCall { - span, - def_path_str: ccx.tcx.def_path_str_with_args(self.callee, self.args), - def_descr: ccx.tcx.def_descr(self.callee), - kind: ccx.const_kind(), - }) + ccx.tcx.sess.create_feature_err( + errors::ConditionallyConstCall { + span, + def_path_str: ccx.tcx.def_path_str_with_args(self.callee, self.args), + def_descr: ccx.tcx.def_descr(self.callee), + kind: ccx.const_kind(), + }, + sym::const_trait_impl, + ) } } @@ -417,15 +420,8 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine { fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { let msg = format!("{:#}s are not allowed in {}s", self.0, ccx.const_kind()); - if let hir::CoroutineKind::Desugared( - hir::CoroutineDesugaring::Async, - hir::CoroutineSource::Block, - ) = self.0 - { - ccx.tcx.sess.create_feature_err( - errors::UnallowedOpInConstContext { span, msg }, - sym::const_async_blocks, - ) + if let Status::Unstable { gate, .. } = self.status_in_item(ccx) { + ccx.tcx.sess.create_feature_err(errors::UnallowedOpInConstContext { span, msg }, gate) } else { ccx.dcx().create_err(errors::UnallowedOpInConstContext { span, msg }) } diff --git a/compiler/rustc_session/src/parse.rs b/compiler/rustc_session/src/parse.rs index f20ae85b8e8..21c11655110 100644 --- a/compiler/rustc_session/src/parse.rs +++ b/compiler/rustc_session/src/parse.rs @@ -155,6 +155,7 @@ pub fn feature_warn_issue( } /// Adds the diagnostics for a feature to an existing error. +/// Must be a language feature! pub fn add_feature_diagnostics<G: EmissionGuarantee>( err: &mut Diag<'_, G>, sess: &Session, diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 470e372ee48..9d9434a7776 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -300,6 +300,7 @@ impl Session { self.opts.test } + /// `feature` must be a language feature. #[track_caller] pub fn create_feature_err<'a>(&'a self, err: impl Diagnostic<'a>, feature: Symbol) -> Diag<'a> { let mut err = self.dcx().create_err(err); diff --git a/tests/ui/traits/const-traits/cross-crate.stock.stderr b/tests/ui/traits/const-traits/cross-crate.stock.stderr index d26228f6958..09bf9c023c8 100644 --- a/tests/ui/traits/const-traits/cross-crate.stock.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stock.stderr @@ -1,8 +1,13 @@ -error: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions +error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions --> $DIR/cross-crate.rs:22:5 | LL | Const.func(); | ^^^^^^^^^^^^ + | + = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr index 9b372860262..e52e5609b01 100644 --- a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr @@ -1,14 +1,23 @@ -error: cannot call conditionally-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions +error[E0658]: cannot call conditionally-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions --> $DIR/cross-crate.rs:19:5 | LL | NonConst.func(); | ^^^^^^^^^^^^^^^ + | + = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions +error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions --> $DIR/cross-crate.rs:22:5 | LL | Const.func(); | ^^^^^^^^^^^^ + | + = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/const-traits/staged-api-user-crate.stderr b/tests/ui/traits/const-traits/staged-api-user-crate.stderr index 2bce230ffdf..bf7466b8e16 100644 --- a/tests/ui/traits/const-traits/staged-api-user-crate.stderr +++ b/tests/ui/traits/const-traits/staged-api-user-crate.stderr @@ -1,8 +1,13 @@ -error: cannot call conditionally-const associated function `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions +error[E0658]: cannot call conditionally-const associated function `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions --> $DIR/staged-api-user-crate.rs:12:5 | LL | Unstable::func(); | ^^^^^^^^^^^^^^^^ + | + = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0658`. |
