From b321cd5573d5bfc4b21f456be146c8d29d67bd1d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 23 Dec 2024 21:04:17 +0000 Subject: [PATCH] Add note back to conditionally-const error message --- compiler/rustc_const_eval/src/check_consts/ops.rs | 12 ++++++++++-- tests/ui/issues/issue-25901.stderr | 1 + .../arbitrary-self-from-method-substs-ice.stderr | 1 + .../ui/traits/const-traits/cross-crate.stock.stderr | 1 + .../traits/const-traits/cross-crate.stocknc.stderr | 2 ++ .../traits/const-traits/staged-api-user-crate.stderr | 1 + .../const-traits/super-traits-fail-3.nyn.stderr | 1 + .../const-traits/super-traits-fail-3.nyy.stderr | 1 + 8 files changed, 18 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index ebd680ac28a2..55e43f5af351 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -92,7 +92,7 @@ impl<'tcx> NonConstOp<'tcx> for ConditionallyConstCall<'tcx> { } fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> { - ccx.tcx.sess.create_feature_err( + let mut err = ccx.tcx.sess.create_feature_err( errors::ConditionallyConstCall { span, def_path_str: ccx.tcx.def_path_str_with_args(self.callee, self.args), @@ -100,7 +100,15 @@ impl<'tcx> NonConstOp<'tcx> for ConditionallyConstCall<'tcx> { kind: ccx.const_kind(), }, sym::const_trait_impl, - ) + ); + + err.note(format!( + "calls in {}s are limited to constant functions, \ + tuple structs and tuple variants", + ccx.const_kind(), + )); + + err } } diff --git a/tests/ui/issues/issue-25901.stderr b/tests/ui/issues/issue-25901.stderr index 655a8b78c6a1..b100ce30a41b 100644 --- a/tests/ui/issues/issue-25901.stderr +++ b/tests/ui/issues/issue-25901.stderr @@ -7,6 +7,7 @@ LL | static S: &'static B = &A; = note: see issue #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 + = note: calls in statics are limited to constant functions, tuple structs and tuple variants error: aborting due to 1 previous error diff --git a/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr b/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr index cf4c219215e0..5ed82eb76490 100644 --- a/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr +++ b/tests/ui/self/arbitrary-self-from-method-substs-ice.stderr @@ -7,6 +7,7 @@ LL | self.0 = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error[E0493]: destructor of `R` cannot be evaluated at compile-time --> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43 diff --git a/tests/ui/traits/const-traits/cross-crate.stock.stderr b/tests/ui/traits/const-traits/cross-crate.stock.stderr index 09bf9c023c84..de73d904f42b 100644 --- a/tests/ui/traits/const-traits/cross-crate.stock.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stock.stderr @@ -7,6 +7,7 @@ LL | Const.func(); = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr index e52e5609b01d..74fa35cfd04d 100644 --- a/tests/ui/traits/const-traits/cross-crate.stocknc.stderr +++ b/tests/ui/traits/const-traits/cross-crate.stocknc.stderr @@ -7,6 +7,7 @@ LL | NonConst.func(); = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error[E0658]: cannot call conditionally-const method `::func` in constant functions --> $DIR/cross-crate.rs:22:5 @@ -17,6 +18,7 @@ LL | Const.func(); = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 2 previous errors 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 bf7466b8e166..970e0c1252cf 100644 --- a/tests/ui/traits/const-traits/staged-api-user-crate.stderr +++ b/tests/ui/traits/const-traits/staged-api-user-crate.stderr @@ -7,6 +7,7 @@ LL | Unstable::func(); = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr index 8abda1c8f8af..1b1ca4b28a46 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr @@ -47,6 +47,7 @@ LL | x.a(); = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 5 previous errors diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr index 8abda1c8f8af..1b1ca4b28a46 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr @@ -47,6 +47,7 @@ LL | x.a(); = note: see issue #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 + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants error: aborting due to 5 previous errors