Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 772b95e

Browse files
authored
Rollup merge of rust-lang#134701 - compiler-errors:non-const-def-descr, r=Urgau,fmease
Correctly note item kind in `NonConstFunctionCall` error message Don't just call everything a "`fn`". This is more consistent with the error message we give for conditionally-const items, which do note the item's def kind. r? fmease, this is a prerequisite for making those `~const PartialEq` error messages better. Re-roll if you're busy or don't want to review this.
2 parents 3331185 + 92f93f6 commit 772b95e

File tree

84 files changed

+107
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+107
-105
lines changed

compiler/rustc_const_eval/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ const_eval_non_const_fmt_macro_call =
253253
cannot call non-const formatting macro in {const_eval_const_context}s
254254
255255
const_eval_non_const_fn_call =
256-
cannot call non-const fn `{$def_path_str}` in {const_eval_const_context}s
256+
cannot call non-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
257257
258258
const_eval_non_const_impl =
259259
impl defined here, but it is not `const`

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
304304
}
305305
_ => ccx.dcx().create_err(errors::NonConstFnCall {
306306
span,
307+
def_descr: ccx.tcx.def_descr(callee),
307308
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
308309
kind: ccx.const_kind(),
309310
}),

compiler/rustc_const_eval/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub(crate) struct NonConstFnCall {
192192
#[primary_span]
193193
pub span: Span,
194194
pub def_path_str: String,
195+
pub def_descr: &'static str,
195196
pub kind: ConstContext,
196197
}
197198

compiler/rustc_error_codes/src/error_codes/E0015.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn create_some() -> Option<u8> {
77
Some(1)
88
}
99
10-
// error: cannot call non-const fn `create_some` in constants
10+
// error: cannot call non-const function `create_some` in constants
1111
const FOO: Option<u8> = create_some();
1212
```
1313

tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-disabled.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[
5252
LL | #[const_trait] trait Bar: ~const Foo {}
5353
| ++++++++++++++
5454

55-
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
55+
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
5656
--> const-super-trait.rs:10:7
5757
|
5858
LL | x.a();

tests/run-make/const-trait-stable-toolchain/const-super-trait-nightly-enabled.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations
3232
LL | #[const_trait] trait Bar: ~const Foo {}
3333
| ++++++++++++++
3434

35-
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
35+
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
3636
--> const-super-trait.rs:10:7
3737
|
3838
LL | x.a();

tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-disabled.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ note: `Bar` can't be used with `~const` because it isn't annotated with `#[const
5050
7 | trait Bar: ~const Foo {}
5151
| ^^^^^^^^^^^^^^^^^^^^^
5252

53-
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
53+
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
5454
--> const-super-trait.rs:10:7
5555
|
5656
10 | x.a();

tests/run-make/const-trait-stable-toolchain/const-super-trait-stable-enabled.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ note: `Bar` can't be used with `~const` because it isn't annotated with `#[const
4040
7 | trait Bar: ~const Foo {}
4141
| ^^^^^^^^^^^^^^^^^^^^^
4242

43-
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
43+
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
4444
--> const-super-trait.rs:10:7
4545
|
4646
10 | x.a();

tests/ui/asm/non-const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ fn main() {}
88
fn non_const_fn(x: i32) -> i32 { x }
99

1010
global_asm!("/* {} */", const non_const_fn(0));
11-
//~^ERROR: cannot call non-const fn
11+
//~^ERROR: cannot call non-const function

tests/ui/asm/non-const.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `non_const_fn` in constants
1+
error[E0015]: cannot call non-const function `non_const_fn` in constants
22
--> $DIR/non-const.rs:10:31
33
|
44
LL | global_asm!("/* {} */", const non_const_fn(0));

0 commit comments

Comments
 (0)