Skip to content

Commit b321cd5

Browse files
Add note back to conditionally-const error message
1 parent ec12cd8 commit b321cd5

8 files changed

+18
-2
lines changed

compiler/rustc_const_eval/src/check_consts/ops.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,23 @@ impl<'tcx> NonConstOp<'tcx> for ConditionallyConstCall<'tcx> {
9292
}
9393

9494
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> Diag<'tcx> {
95-
ccx.tcx.sess.create_feature_err(
95+
let mut err = ccx.tcx.sess.create_feature_err(
9696
errors::ConditionallyConstCall {
9797
span,
9898
def_path_str: ccx.tcx.def_path_str_with_args(self.callee, self.args),
9999
def_descr: ccx.tcx.def_descr(self.callee),
100100
kind: ccx.const_kind(),
101101
},
102102
sym::const_trait_impl,
103-
)
103+
);
104+
105+
err.note(format!(
106+
"calls in {}s are limited to constant functions, \
107+
tuple structs and tuple variants",
108+
ccx.const_kind(),
109+
));
110+
111+
err
104112
}
105113
}
106114

tests/ui/issues/issue-25901.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | static S: &'static B = &A;
77
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
88
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
1011

1112
error: aborting due to 1 previous error
1213

tests/ui/self/arbitrary-self-from-method-substs-ice.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | self.0
77
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
88
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1011

1112
error[E0493]: destructor of `R` cannot be evaluated at compile-time
1213
--> $DIR/arbitrary-self-from-method-substs-ice.rs:10:43

tests/ui/traits/const-traits/cross-crate.stock.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | Const.func();
77
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
88
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1011

1112
error: aborting due to 1 previous error
1213

tests/ui/traits/const-traits/cross-crate.stocknc.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | NonConst.func();
77
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
88
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1011

1112
error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
1213
--> $DIR/cross-crate.rs:22:5
@@ -17,6 +18,7 @@ LL | Const.func();
1718
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
1819
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
1920
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
21+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2022

2123
error: aborting due to 2 previous errors
2224

tests/ui/traits/const-traits/staged-api-user-crate.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | Unstable::func();
77
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
88
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
1011

1112
error: aborting due to 1 previous error
1213

tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ LL | x.a();
4747
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
4848
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
50+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
5051

5152
error: aborting due to 5 previous errors
5253

tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ LL | x.a();
4747
= note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
4848
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
4949
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
50+
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
5051

5152
error: aborting due to 5 previous errors
5253

0 commit comments

Comments
 (0)