Skip to content

Commit

Permalink
Note def descr in NonConstFunctionCall
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 23, 2024
1 parent addbd00 commit 92f93f6
Show file tree
Hide file tree
Showing 84 changed files with 107 additions and 105 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const_eval_non_const_fmt_macro_call =
cannot call non-const formatting macro in {const_eval_const_context}s
const_eval_non_const_fn_call =
cannot call non-const fn `{$def_path_str}` in {const_eval_const_context}s
cannot call non-const {$def_descr} `{$def_path_str}` in {const_eval_const_context}s
const_eval_non_const_impl =
impl defined here, but it is not `const`
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
}
_ => ccx.dcx().create_err(errors::NonConstFnCall {
span,
def_descr: ccx.tcx.def_descr(callee),
def_path_str: ccx.tcx.def_path_str_with_args(callee, args),
kind: ccx.const_kind(),
}),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub(crate) struct NonConstFnCall {
#[primary_span]
pub span: Span,
pub def_path_str: String,
pub def_descr: &'static str,
pub kind: ConstContext,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0015.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn create_some() -> Option<u8> {
Some(1)
}
// error: cannot call non-const fn `create_some` in constants
// error: cannot call non-const function `create_some` in constants
const FOO: Option<u8> = create_some();
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ help: enable `#![feature(const_trait_impl)]` in your crate and mark `Bar` as `#[
LL | #[const_trait] trait Bar: ~const Foo {}
| ++++++++++++++

error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
LL | x.a();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ help: mark `Bar` as `#[const_trait]` to allow it to have `const` implementations
LL | #[const_trait] trait Bar: ~const Foo {}
| ++++++++++++++

error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
LL | x.a();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ note: `Bar` can't be used with `~const` because it isn't annotated with `#[const
7 | trait Bar: ~const Foo {}
| ^^^^^^^^^^^^^^^^^^^^^

error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
10 | x.a();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ note: `Bar` can't be used with `~const` because it isn't annotated with `#[const
7 | trait Bar: ~const Foo {}
| ^^^^^^^^^^^^^^^^^^^^^

error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> const-super-trait.rs:10:7
|
10 | x.a();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/asm/non-const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ fn main() {}
fn non_const_fn(x: i32) -> i32 { x }

global_asm!("/* {} */", const non_const_fn(0));
//~^ERROR: cannot call non-const fn
//~^ERROR: cannot call non-const function
2 changes: 1 addition & 1 deletion tests/ui/asm/non-const.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `non_const_fn` in constants
error[E0015]: cannot call non-const function `non_const_fn` in constants
--> $DIR/non-const.rs:10:31
|
LL | global_asm!("/* {} */", const non_const_fn(0));
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-64453.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct Project;
struct Value;

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

fn from_string(_: String) -> Value {
Value
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-64453.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `format` in statics
error[E0015]: cannot call non-const function `format` in statics
--> $DIR/issue-64453.rs:4:31
|
LL | static settings_dir: String = format!("");
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/nested-type.full.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
--> $DIR/nested-type.rs:15:5
|
LL | Foo::<17>::value()
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/nested-type.min.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
--> $DIR/nested-type.rs:15:5
|
LL | Foo::<17>::value()
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/nested-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Foo<const N: [u8; {
}

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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ fn f(x: usize) -> usize {

fn main() {
let _ = [0; f(2)];
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
}
2 changes: 1 addition & 1 deletion tests/ui/consts/const-call.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `f` in constants
error[E0015]: cannot call non-const function `f` in constants
--> $DIR/const-call.rs:6:17
|
LL | let _ = [0; f(2)];
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/const-eval/format.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const fn failure() {
panic!("{:?}", 0);
//~^ ERROR cannot call non-const formatting macro in constant functions
//~| ERROR cannot call non-const fn `Arguments::<'_>::new_v1::<1, 1>` in constant functions
//~| ERROR cannot call non-const associated function `Arguments::<'_>::new_v1::<1, 1>` in constant functions
}

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

fn main() {}
6 changes: 3 additions & 3 deletions tests/ui/consts/const-eval/format.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | panic!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= 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)

error[E0015]: cannot call non-const fn `Arguments::<'_>::new_v1::<1, 1>` in constant functions
error[E0015]: cannot call non-const associated function `Arguments::<'_>::new_v1::<1, 1>` in constant functions
--> $DIR/format.rs:2:5
|
LL | panic!("{:?}", 0);
Expand All @@ -25,7 +25,7 @@ LL | println!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= 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)

error[E0015]: cannot call non-const fn `Arguments::<'_>::new_v1::<2, 1>` in constant functions
error[E0015]: cannot call non-const associated function `Arguments::<'_>::new_v1::<2, 1>` in constant functions
--> $DIR/format.rs:8:5
|
LL | println!("{:?}", 0);
Expand All @@ -34,7 +34,7 @@ LL | println!("{:?}", 0);
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= 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)

error[E0015]: cannot call non-const fn `_print` in constant functions
error[E0015]: cannot call non-const function `_print` in constant functions
--> $DIR/format.rs:8:5
|
LL | println!("{:?}", 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-eval/ub-slice-get-unchecked.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
error[E0015]: cannot call non-const method `core::slice::<impl [()]>::get_unchecked::<std::ops::Range<usize>>` in constants
--> $DIR/ub-slice-get-unchecked.rs:7:29
|
LL | const B: &[()] = unsafe { A.get_unchecked(3..1) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern "C" {
const extern "C" fn bar() {
unsafe {
regular_in_block();
//~^ ERROR: cannot call non-const fn
//~^ ERROR: cannot call non-const function
}
}

Expand All @@ -14,7 +14,7 @@ extern "C" fn regular() {}
const extern "C" fn foo() {
unsafe {
regular();
//~^ ERROR: cannot call non-const fn
//~^ ERROR: cannot call non-const function
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0015]: cannot call non-const fn `regular_in_block` in constant functions
error[E0015]: cannot call non-const function `regular_in_block` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:7:9
|
LL | regular_in_block();
| ^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error[E0015]: cannot call non-const fn `regular` in constant functions
error[E0015]: cannot call non-const function `regular` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:16:9
|
LL | regular();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-fn-not-safe-for-const.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `random` in constant functions
error[E0015]: cannot call non-const function `random` in constant functions
--> $DIR/const-fn-not-safe-for-const.rs:14:5
|
LL | random()
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/control-flow/issue-46843.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn non_const() -> Thing {
}

pub const Q: i32 = match non_const() {
//~^ ERROR cannot call non-const fn
//~^ ERROR cannot call non-const function
Thing::This => 1,
Thing::That => 0
};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/control-flow/issue-46843.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `non_const` in constants
error[E0015]: cannot call non-const function `non_const` in constants
--> $DIR/issue-46843.rs:10:26
|
LL | pub const Q: i32 = match non_const() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-16538.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `Y::foo` in statics
error[E0015]: cannot call non-const function `Y::foo` in statics
--> $DIR/issue-16538.rs:11:23
|
LL | static foo: &Y::X = &*Y::foo(Y::x as *const Y::X);
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/issue-32829-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bad : u32 = {
const bad_two : u32 = {
{
invalid();
//~^ ERROR: cannot call non-const fn `invalid`
//~^ ERROR: cannot call non-const function `invalid`
0
}
};
Expand All @@ -30,7 +30,7 @@ static bad_four : u32 = {
static bad_five : u32 = {
{
invalid();
//~^ ERROR: cannot call non-const fn `invalid`
//~^ ERROR: cannot call non-const function `invalid`
0
}
};
Expand All @@ -52,7 +52,7 @@ static mut bad_seven : u32 = {
static mut bad_eight : u32 = {
{
invalid();
//~^ ERROR: cannot call non-const fn `invalid`
//~^ ERROR: cannot call non-const function `invalid`
0
}
};
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/issue-32829-2.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0015]: cannot call non-const fn `invalid` in constants
error[E0015]: cannot call non-const function `invalid` in constants
--> $DIR/issue-32829-2.rs:10:9
|
LL | invalid();
| ^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants

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

error[E0015]: cannot call non-const fn `invalid` in statics
error[E0015]: cannot call non-const function `invalid` in statics
--> $DIR/issue-32829-2.rs:54:9
|
LL | invalid();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-43105.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn xyz() -> u8 { 42 }

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

fn main() {
match 1 {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/issue-43105.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `xyz` in constants
error[E0015]: cannot call non-const function `xyz` in constants
--> $DIR/issue-43105.rs:3:17
|
LL | const NUM: u8 = xyz();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/min_const_fn/bad_const_fn_body_ice.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fn foo(a: i32) -> Vec<i32> {
vec![1, 2, 3]
//~^ ERROR allocations are not allowed
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const method
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | vec![1, 2, 3]
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constant functions
--> $DIR/bad_const_fn_body_ice.rs:2:5
|
LL | vec![1, 2, 3]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/mir_check_nonconst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fn bar() -> Foo {
}

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

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/consts/mir_check_nonconst.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `bar` in statics
error[E0015]: cannot call non-const function `bar` in statics
--> $DIR/mir_check_nonconst.rs:8:19
|
LL | static foo: Foo = bar();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0010-teach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#![allow(warnings)]

const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const method
fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0010-teach.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
= note: The runtime heap is not yet available at compile-time, so no runtime heap allocations can be created.
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
--> $DIR/E0010-teach.rs:5:23
|
LL | const CON: Vec<i32> = vec![1, 2, 3];
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0010.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(warnings)]

const CON: Vec<i32> = vec![1, 2, 3]; //~ ERROR E0010
//~| ERROR cannot call non-const fn
//~| ERROR cannot call non-const method
fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0010.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | const CON: Vec<i32> = vec![1, 2, 3];
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0015]: cannot call non-const fn `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std::alloc::Global>` in constants
--> $DIR/E0010.rs:3:23
|
LL | const CON: Vec<i32> = vec![1, 2, 3];
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0015.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ fn create_some() -> Option<u8> {
}

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

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0015.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0015]: cannot call non-const fn `create_some` in constants
error[E0015]: cannot call non-const function `create_some` in constants
--> $DIR/E0015.rs:5:25
|
LL | const FOO: Option<u8> = create_some();
Expand Down
Loading

0 comments on commit 92f93f6

Please sign in to comment.