Skip to content

Commit 92f93f6

Browse files
Note def descr in NonConstFunctionCall
1 parent addbd00 commit 92f93f6

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

+1-1
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

+1
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

+1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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));

tests/ui/borrowck/issue-64453.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct Project;
22
struct Value;
33

44
static settings_dir: String = format!("");
5-
//~^ ERROR cannot call non-const fn
5+
//~^ ERROR cannot call non-const function
66

77
fn from_string(_: String) -> Value {
88
Value

tests/ui/borrowck/issue-64453.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `format` in statics
1+
error[E0015]: cannot call non-const function `format` in statics
22
--> $DIR/issue-64453.rs:4:31
33
|
44
LL | static settings_dir: String = format!("");

tests/ui/const-generics/nested-type.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
1+
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
22
--> $DIR/nested-type.rs:15:5
33
|
44
LL | Foo::<17>::value()

tests/ui/const-generics/nested-type.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
1+
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
22
--> $DIR/nested-type.rs:15:5
33
|
44
LL | Foo::<17>::value()

tests/ui/const-generics/nested-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Foo<const N: [u8; {
1313
}
1414

1515
Foo::<17>::value()
16-
//~^ ERROR cannot call non-const fn
16+
//~^ ERROR cannot call non-const associated function
1717
}]>;
1818
//[min]~^^^^^^^^^^^^ ERROR `[u8; {
1919

tests/ui/consts/const-call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ fn f(x: usize) -> usize {
44

55
fn main() {
66
let _ = [0; f(2)];
7-
//~^ ERROR cannot call non-const fn
7+
//~^ ERROR cannot call non-const function
88
}

tests/ui/consts/const-call.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `f` in constants
1+
error[E0015]: cannot call non-const function `f` in constants
22
--> $DIR/const-call.rs:6:17
33
|
44
LL | let _ = [0; f(2)];

tests/ui/consts/const-eval/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const fn failure() {
22
panic!("{:?}", 0);
33
//~^ ERROR cannot call non-const formatting macro in constant functions
4-
//~| ERROR cannot call non-const fn `Arguments::<'_>::new_v1::<1, 1>` in constant functions
4+
//~| ERROR cannot call non-const associated function `Arguments::<'_>::new_v1::<1, 1>` in constant functions
55
}
66

77
const fn print() {
88
println!("{:?}", 0);
99
//~^ ERROR cannot call non-const formatting macro in constant functions
10-
//~| ERROR cannot call non-const fn `Arguments::<'_>::new_v1::<2, 1>` in constant functions
11-
//~| ERROR cannot call non-const fn `_print` in constant functions
10+
//~| ERROR cannot call non-const associated function `Arguments::<'_>::new_v1::<2, 1>` in constant functions
11+
//~| ERROR cannot call non-const function `_print` in constant functions
1212
}
1313

1414
fn main() {}

tests/ui/consts/const-eval/format.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | panic!("{:?}", 0);
77
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
88
= note: this error originates in the macro `$crate::const_format_args` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
99

10-
error[E0015]: cannot call non-const fn `Arguments::<'_>::new_v1::<1, 1>` in constant functions
10+
error[E0015]: cannot call non-const associated function `Arguments::<'_>::new_v1::<1, 1>` in constant functions
1111
--> $DIR/format.rs:2:5
1212
|
1313
LL | panic!("{:?}", 0);
@@ -25,7 +25,7 @@ LL | println!("{:?}", 0);
2525
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
2626
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
2727

28-
error[E0015]: cannot call non-const fn `Arguments::<'_>::new_v1::<2, 1>` in constant functions
28+
error[E0015]: cannot call non-const associated function `Arguments::<'_>::new_v1::<2, 1>` in constant functions
2929
--> $DIR/format.rs:8:5
3030
|
3131
LL | println!("{:?}", 0);
@@ -34,7 +34,7 @@ LL | println!("{:?}", 0);
3434
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
3535
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

37-
error[E0015]: cannot call non-const fn `_print` in constant functions
37+
error[E0015]: cannot call non-const function `_print` in constant functions
3838
--> $DIR/format.rs:8:5
3939
|
4040
LL | println!("{:?}", 0);

tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
1+
error[E0015]: cannot call non-const method `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
22
--> $DIR/ub-slice-get-unchecked.rs:7:29
33
|
44
LL | const B: &[()] = unsafe { A.get_unchecked(3..1) };

tests/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
const extern "C" fn bar() {
66
unsafe {
77
regular_in_block();
8-
//~^ ERROR: cannot call non-const fn
8+
//~^ ERROR: cannot call non-const function
99
}
1010
}
1111

@@ -14,7 +14,7 @@ extern "C" fn regular() {}
1414
const extern "C" fn foo() {
1515
unsafe {
1616
regular();
17-
//~^ ERROR: cannot call non-const fn
17+
//~^ ERROR: cannot call non-const function
1818
}
1919
}
2020

tests/ui/consts/const-extern-fn/const-extern-fn-call-extern-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0015]: cannot call non-const fn `regular_in_block` in constant functions
1+
error[E0015]: cannot call non-const function `regular_in_block` in constant functions
22
--> $DIR/const-extern-fn-call-extern-fn.rs:7:9
33
|
44
LL | regular_in_block();
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
88

9-
error[E0015]: cannot call non-const fn `regular` in constant functions
9+
error[E0015]: cannot call non-const function `regular` in constant functions
1010
--> $DIR/const-extern-fn-call-extern-fn.rs:16:9
1111
|
1212
LL | regular();

tests/ui/consts/const-fn-not-safe-for-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `random` in constant functions
1+
error[E0015]: cannot call non-const function `random` in constant functions
22
--> $DIR/const-fn-not-safe-for-const.rs:14:5
33
|
44
LL | random()

tests/ui/consts/control-flow/issue-46843.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn non_const() -> Thing {
88
}
99

1010
pub const Q: i32 = match non_const() {
11-
//~^ ERROR cannot call non-const fn
11+
//~^ ERROR cannot call non-const function
1212
Thing::This => 1,
1313
Thing::That => 0
1414
};

tests/ui/consts/control-flow/issue-46843.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `non_const` in constants
1+
error[E0015]: cannot call non-const function `non_const` in constants
22
--> $DIR/issue-46843.rs:10:26
33
|
44
LL | pub const Q: i32 = match non_const() {

tests/ui/consts/issue-16538.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `Y::foo` in statics
1+
error[E0015]: cannot call non-const function `Y::foo` in statics
22
--> $DIR/issue-16538.rs:11:23
33
|
44
LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);

tests/ui/consts/issue-32829-2.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const bad : u32 = {
88
const bad_two : u32 = {
99
{
1010
invalid();
11-
//~^ ERROR: cannot call non-const fn `invalid`
11+
//~^ ERROR: cannot call non-const function `invalid`
1212
0
1313
}
1414
};
@@ -30,7 +30,7 @@ static bad_four : u32 = {
3030
static bad_five : u32 = {
3131
{
3232
invalid();
33-
//~^ ERROR: cannot call non-const fn `invalid`
33+
//~^ ERROR: cannot call non-const function `invalid`
3434
0
3535
}
3636
};
@@ -52,7 +52,7 @@ static mut bad_seven : u32 = {
5252
static mut bad_eight : u32 = {
5353
{
5454
invalid();
55-
//~^ ERROR: cannot call non-const fn `invalid`
55+
//~^ ERROR: cannot call non-const function `invalid`
5656
0
5757
}
5858
};

tests/ui/consts/issue-32829-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0015]: cannot call non-const fn `invalid` in constants
1+
error[E0015]: cannot call non-const function `invalid` in constants
22
--> $DIR/issue-32829-2.rs:10:9
33
|
44
LL | invalid();
55
| ^^^^^^^^^
66
|
77
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
88

9-
error[E0015]: cannot call non-const fn `invalid` in statics
9+
error[E0015]: cannot call non-const function `invalid` in statics
1010
--> $DIR/issue-32829-2.rs:32:9
1111
|
1212
LL | invalid();
@@ -15,7 +15,7 @@ LL | invalid();
1515
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
1616
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
1717

18-
error[E0015]: cannot call non-const fn `invalid` in statics
18+
error[E0015]: cannot call non-const function `invalid` in statics
1919
--> $DIR/issue-32829-2.rs:54:9
2020
|
2121
LL | invalid();

tests/ui/consts/issue-43105.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn xyz() -> u8 { 42 }
22

33
const NUM: u8 = xyz();
4-
//~^ ERROR cannot call non-const fn
4+
//~^ ERROR cannot call non-const function
55

66
fn main() {
77
match 1 {

tests/ui/consts/issue-43105.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `xyz` in constants
1+
error[E0015]: cannot call non-const function `xyz` in constants
22
--> $DIR/issue-43105.rs:3:17
33
|
44
LL | const NUM: u8 = xyz();
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fn foo(a: i32) -> Vec<i32> {
22
vec![1, 2, 3]
33
//~^ ERROR allocations are not allowed
4-
//~| ERROR cannot call non-const fn
4+
//~| ERROR cannot call non-const method
55
}
66

77
fn main() {}

tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | vec![1, 2, 3]
66
|
77
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
88

9-
error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
9+
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
1010
--> $DIR/bad_const_fn_body_ice.rs:2:5
1111
|
1212
LL | vec![1, 2, 3]

tests/ui/consts/mir_check_nonconst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ fn bar() -> Foo {
66
}
77

88
static foo: Foo = bar();
9-
//~^ ERROR cannot call non-const fn
9+
//~^ ERROR cannot call non-const function
1010

1111
fn main() {}

tests/ui/consts/mir_check_nonconst.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `bar` in statics
1+
error[E0015]: cannot call non-const function `bar` in statics
22
--> $DIR/mir_check_nonconst.rs:8:19
33
|
44
LL | static foo: Foo = bar();

tests/ui/error-codes/E0010-teach.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#![allow(warnings)]
44

55
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
6-
//~| ERROR cannot call non-const fn
6+
//~| ERROR cannot call non-const method
77
fn main() {}

tests/ui/error-codes/E0010-teach.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
77
= note: The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created.
88
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
99

10-
error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
10+
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
1111
--> $DIR/E0010-teach.rs:5:23
1212
|
1313
LL | const CON: Vec<i32> = vec![1, 2, 3];

tests/ui/error-codes/E0010.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(warnings)]
22

33
const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
4-
//~| ERROR cannot call non-const fn
4+
//~| ERROR cannot call non-const method
55
fn main() {}

tests/ui/error-codes/E0010.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
66
|
77
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
88

9-
error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
9+
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
1010
--> $DIR/E0010.rs:3:23
1111
|
1212
LL | const CON: Vec<i32> = vec![1, 2, 3];

tests/ui/error-codes/E0015.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ fn create_some() -> Option<u8> {
33
}
44

55
const FOO: Option<u8> = create_some();
6-
//~^ ERROR cannot call non-const fn `create_some` in constants [E0015]
6+
//~^ ERROR cannot call non-const function `create_some` in constants [E0015]
77

88
fn main() {}

tests/ui/error-codes/E0015.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0015]: cannot call non-const fn `create_some` in constants
1+
error[E0015]: cannot call non-const function `create_some` in constants
22
--> $DIR/E0015.rs:5:25
33
|
44
LL | const FOO: Option<u8> = create_some();

0 commit comments

Comments
 (0)