Point at the enclosing const context

```
error[E0015]: cannot call non-const associated function `Foo::{constant#0}::Foo::<17>::value` in constants
  --> $DIR/nested-type.rs:15:5
   |
LL |   struct Foo<const N: [u8; {
   |  __________________________-
LL | |     struct Foo<const N: usize>;
LL | |
LL | |     impl<const N: usize> Foo<N> {
...  |
LL | |     Foo::<17>::value()
   | |     ^^^^^^^^^^^^^^^^^^
LL | |
LL | | }]>;
   | |_- calls in constants are limited to constant functions, tuple structs and tuple variants
```
This commit is contained in:
Esteban Küber 2025-07-19 01:23:52 +00:00
parent eb79e68c24
commit 9bc814cc8d
43 changed files with 176 additions and 95 deletions

View file

@ -212,6 +212,7 @@ fn build_error_for_const_call<'tcx>(
debug!(?call_kind);
let mut note = true;
let mut err = match call_kind {
CallKind::Normal { desugaring: Some((kind, self_ty)), .. } => {
macro_rules! error {
@ -362,6 +363,12 @@ fn build_error_for_const_call<'tcx>(
kind: ccx.const_kind(),
non_or_conditionally,
});
let context_span = ccx.tcx.def_span(ccx.def_id());
err.span_label(context_span, format!(
"calls in {}s are limited to constant functions, tuple structs and tuple variants",
ccx.const_kind(),
));
note = false;
let def_kind = ccx.tcx.def_kind(callee);
if let DefKind::AssocTy | DefKind::AssocConst | DefKind::AssocFn = def_kind {
let parent = ccx.tcx.parent(callee);
@ -409,11 +416,12 @@ fn build_error_for_const_call<'tcx>(
}
};
err.note(format!(
"calls in {}s are limited to constant functions, \
tuple structs and tuple variants",
ccx.const_kind(),
));
if note {
err.note(format!(
"calls in {}s are limited to constant functions, tuple structs and tuple variants",
ccx.const_kind(),
));
}
err
}

View file

@ -2,14 +2,13 @@ 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));
| ^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: function `non_const_fn` is not const
--> $DIR/non-const.rs:8:1
|
LL | fn non_const_fn(x: i32) -> i32 { x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -2,11 +2,12 @@ error[E0015]: cannot call non-const function `format` in statics
--> $DIR/issue-64453.rs:4:31
|
LL | static settings_dir: String = format!("");
| ^^^^^^^^^^^
| --------------------------- ^^^^^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
note: function `format` is not const
--> $SRC_DIR/alloc/src/fmt.rs:LL:COL
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -1,10 +1,17 @@
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()
| ^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
LL | struct Foo<const N: [u8; {
| __________________________-
LL | | struct Foo<const N: usize>;
LL | |
LL | | impl<const N: usize> Foo<N> {
... |
LL | | Foo::<17>::value()
| | ^^^^^^^^^^^^^^^^^^
LL | |
LL | | }]>;
| |_- calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -1,10 +1,17 @@
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()
| ^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
LL | struct Foo<const N: [u8; {
| __________________________-
LL | | struct Foo<const N: usize>;
LL | |
LL | | impl<const N: usize> Foo<N> {
... |
LL | | Foo::<17>::value()
| | ^^^^^^^^^^^^^^^^^^
LL | |
LL | | }]>;
| |_- calls in constants are limited to constant functions, tuple structs and tuple variants
error: `[u8; {
struct Foo<const N: usize>;

View file

@ -2,14 +2,13 @@ error[E0015]: cannot call non-const function `f` in constants
--> $DIR/const-call.rs:6:17
|
LL | let _ = [0; f(2)];
| ^^^^
| ^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: function `f` is not const
--> $DIR/const-call.rs:1:1
|
LL | fn f(x: usize) -> usize {
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -18,12 +18,13 @@ LL | println!("{:?}", 0);
error[E0015]: cannot call non-const function `_print` in constant functions
--> $DIR/format.rs:7:5
|
LL | const fn print() {
| ---------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | println!("{:?}", 0);
| ^^^^^^^^^^^^^^^^^^^
|
note: function `_print` is not const
--> $SRC_DIR/std/src/io/stdio.rs:LL:COL
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0015]: cannot call non-const formatting macro in constant functions

View file

@ -1,6 +1,9 @@
error[E0015]: cannot call non-const function `regular_in_block` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:7:9
|
LL | const extern "C" fn bar() {
| ------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | unsafe {
LL | regular_in_block();
| ^^^^^^^^^^^^^^^^^^
|
@ -9,11 +12,13 @@ note: function `regular_in_block` is not const
|
LL | fn regular_in_block();
| ^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const function `regular` in constant functions
--> $DIR/const-extern-fn-call-extern-fn.rs:16:9
|
LL | const extern "C" fn foo() {
| ------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | unsafe {
LL | regular();
| ^^^^^^^^^
|
@ -22,7 +27,6 @@ note: function `regular` is not const
|
LL | extern "C" fn regular() {}
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 2 previous errors

View file

@ -1,6 +1,8 @@
error[E0015]: cannot call non-const function `random` in constant functions
--> $DIR/const-fn-not-safe-for-const.rs:14:5
|
LL | const fn sub1() -> u32 {
| ---------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | random()
| ^^^^^^^^
|
@ -9,7 +11,6 @@ note: function `random` is not const
|
LL | fn random() -> u32 {
| ^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -2,14 +2,15 @@ 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() {
| ^^^^^^^^^^^
| ---------------- ^^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: function `non_const` is not const
--> $DIR/issue-46843.rs:6:1
|
LL | fn non_const() -> Thing {
| ^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -2,14 +2,15 @@ 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);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ----------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
note: function `foo` is not const
--> $DIR/issue-16538.rs:6:5
|
LL | pub fn foo(value: *const X) -> *const X {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block

View file

@ -1,6 +1,9 @@
error[E0015]: cannot call non-const function `invalid` in constants
--> $DIR/issue-32829-2.rs:10:9
|
LL | const bad_two : u32 = {
| ------------------- calls in constants are limited to constant functions, tuple structs and tuple variants
LL | {
LL | invalid();
| ^^^^^^^^^
|
@ -9,11 +12,13 @@ note: function `invalid` is not const
|
LL | fn invalid() {}
| ^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const function `invalid` in statics
--> $DIR/issue-32829-2.rs:32:9
|
LL | static bad_five : u32 = {
| --------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
LL | {
LL | invalid();
| ^^^^^^^^^
|
@ -22,12 +27,14 @@ note: function `invalid` is not const
|
LL | fn 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 function `invalid` in statics
--> $DIR/issue-32829-2.rs:54:9
|
LL | static mut bad_eight : u32 = {
| -------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
LL | {
LL | invalid();
| ^^^^^^^^^
|
@ -36,7 +43,6 @@ note: function `invalid` is not const
|
LL | fn 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: aborting due to 3 previous errors

View file

@ -2,14 +2,15 @@ error[E0015]: cannot call non-const function `xyz` in constants
--> $DIR/issue-43105.rs:3:17
|
LL | const NUM: u8 = xyz();
| ^^^^^
| ------------- ^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: function `xyz` is not const
--> $DIR/issue-43105.rs:1:1
|
LL | fn xyz() -> u8 { 42 }
| ^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -9,10 +9,11 @@ LL | vec![1, 2, 3]
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 | const fn foo(a: i32) -> Vec<i32> {
| -------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | vec![1, 2, 3]
| ^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors

View file

@ -2,14 +2,15 @@ error[E0015]: cannot call non-const function `bar` in statics
--> $DIR/mir_check_nonconst.rs:8:19
|
LL | static foo: Foo = bar();
| ^^^^^
| --------------- ^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
note: function `bar` is not const
--> $DIR/mir_check_nonconst.rs:4:1
|
LL | fn bar() -> Foo {
| ^^^^^^^^^^^^^^^
= 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: aborting due to 1 previous error

View file

@ -11,9 +11,10 @@ error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std:
--> $DIR/E0010-teach.rs:5:23
|
LL | const CON: Vec<i32> = vec![1, 2, 3];
| ^^^^^^^^^^^^^
| ------------------- ^^^^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors

View file

@ -10,9 +10,10 @@ error[E0015]: cannot call non-const method `slice::<impl [i32]>::into_vec::<std:
--> $DIR/E0010.rs:3:23
|
LL | const CON: Vec<i32> = vec![1, 2, 3];
| ^^^^^^^^^^^^^
| ------------------- ^^^^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors

View file

@ -2,14 +2,15 @@ error[E0015]: cannot call non-const function `create_some` in constants
--> $DIR/E0015.rs:5:25
|
LL | const FOO: Option<u8> = create_some();
| ^^^^^^^^^^^^^
| --------------------- ^^^^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: function `create_some` is not const
--> $DIR/E0015.rs:1:1
|
LL | fn create_some() -> Option<u8> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -1,6 +1,9 @@
error[E0015]: cannot call non-const function `not_const` in constant functions
--> $DIR/constck.rs:6:16
|
LL | const fn f() {
| ------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | if false {
LL | become not_const();
| ^^^^^^^^^^^
|
@ -9,11 +12,13 @@ note: function `not_const` is not const
|
LL | fn not_const() {}
| ^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const function `not_const` in constant functions
--> $DIR/constck.rs:13:26
|
LL | const fn g((): ()) {
| ------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | if false {
LL | become yes_const(not_const());
| ^^^^^^^^^^^
|
@ -22,7 +27,6 @@ note: function `not_const` is not const
|
LL | fn not_const() {}
| ^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 2 previous errors

View file

@ -2,7 +2,7 @@ error[E0015]: cannot call non-const associated function `<Dim3 as Dim>::dim` in
--> $DIR/issue-39559-2.rs:14:24
|
LL | let array: [usize; Dim3::dim()]
| ^^^^^^^^^^^
| ^^^^^^^^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: associated function `dim` is not const because trait `Dim` is not const
--> $DIR/issue-39559-2.rs:1:1
@ -11,7 +11,6 @@ LL | trait Dim {
| ^^^^^^^^^ this trait is not const
LL | fn dim() -> usize;
| ------------------ this associated function is not const
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Dim` const
|
LL + #[const_trait]
@ -22,7 +21,7 @@ error[E0015]: cannot call non-const associated function `<Dim3 as Dim>::dim` in
--> $DIR/issue-39559-2.rs:16:15
|
LL | = [0; Dim3::dim()];
| ^^^^^^^^^^^
| ^^^^^^^^^^^ calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: associated function `dim` is not const because trait `Dim` is not const
--> $DIR/issue-39559-2.rs:1:1
@ -31,7 +30,6 @@ LL | trait Dim {
| ^^^^^^^^^ this trait is not const
LL | fn dim() -> usize;
| ------------------ this associated function is not const
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Dim` const
|
LL + #[const_trait]

View file

@ -15,9 +15,10 @@ error[E0015]: cannot call non-const associated function `Box::<RefCell<isize>>::
--> $DIR/global-variable-promotion-error-7364.rs:5:37
|
LL | static boxed: Box<RefCell<isize>> = Box::new(RefCell::new(0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| --------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
= 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: aborting due to 2 previous errors

View file

@ -2,9 +2,10 @@ error[E0015]: cannot call non-const associated function `Box::<isize>::new` in s
--> $DIR/static-mut-not-constant.rs:1:28
|
LL | static mut a: Box<isize> = Box::new(3);
| ^^^^^^^^^^^
| ------------------------ ^^^^^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
= 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: aborting due to 1 previous error

View file

@ -2,14 +2,15 @@ error[E0015]: cannot call non-const function `foo` in statics
--> $DIR/static-vec-repeat-not-constant.rs:3:25
|
LL | static a: [isize; 2] = [foo(); 2];
| ^^^^^
| -------------------- ^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
note: function `foo` is not const
--> $DIR/static-vec-repeat-not-constant.rs:1:1
|
LL | fn foo() -> isize { 23 }
| ^^^^^^^^^^^^^^^^^
= 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: aborting due to 1 previous error

View file

@ -23,15 +23,19 @@ error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<
--> $DIR/check-values-constraints.rs:81:33
|
LL | static STATIC11: Vec<MyOwned> = vec![MyOwned];
| ^^^^^^^^^^^^^
| ----------------------------- ^^^^^^^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= 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 method `<str as ToString>::to_string` in statics
--> $DIR/check-values-constraints.rs:92:38
|
LL | static mut STATIC14: SafeStruct = SafeStruct {
| ------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
LL | field1: SafeEnum::Variant1,
LL | field2: SafeEnum::Variant4("str".to_string()),
| ^^^^^^^^^^^
|
@ -42,7 +46,6 @@ note: method `to_string` is not const because trait `ToString` is not const
::: $SRC_DIR/alloc/src/string.rs:LL:COL
|
= note: this method is not const
= 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[E0010]: allocations are not allowed in statics
@ -56,10 +59,11 @@ LL | vec![MyOwned],
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:96:5
|
LL | static STATIC15: &'static [Vec<MyOwned>] = &[
| ---------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
LL | vec![MyOwned],
| ^^^^^^^^^^^^^
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -74,10 +78,12 @@ LL | vec![MyOwned],
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:98:5
|
LL | static STATIC15: &'static [Vec<MyOwned>] = &[
| ---------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
...
LL | vec![MyOwned],
| ^^^^^^^^^^^^^
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -92,10 +98,11 @@ LL | &vec![MyOwned],
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:103:6
|
LL | static STATIC16: (&'static Vec<MyOwned>, &'static Vec<MyOwned>) = (
| --------------------------------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
LL | &vec![MyOwned],
| ^^^^^^^^^^^^^
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -110,10 +117,12 @@ LL | &vec![MyOwned],
error[E0015]: cannot call non-const method `slice::<impl [MyOwned]>::into_vec::<std::alloc::Global>` in statics
--> $DIR/check-values-constraints.rs:105:6
|
LL | static STATIC16: (&'static Vec<MyOwned>, &'static Vec<MyOwned>) = (
| --------------------------------------------------------------- calls in statics are limited to constant functions, tuple structs and tuple variants
...
LL | &vec![MyOwned],
| ^^^^^^^^^^^^^
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -129,9 +138,10 @@ error[E0015]: cannot call non-const method `slice::<impl [isize]>::into_vec::<st
--> $DIR/check-values-constraints.rs:111:31
|
LL | static STATIC19: Vec<isize> = vec![3];
| ^^^^^^^
| --------------------------- ^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
@ -147,9 +157,10 @@ error[E0015]: cannot call non-const method `slice::<impl [isize]>::into_vec::<st
--> $DIR/check-values-constraints.rs:117:32
|
LL | static x: Vec<isize> = vec![3];
| ^^^^^^^
| -------------------- ^^^^^^^
| |
| calls in statics are limited to constant functions, tuple structs and tuple variants
|
= note: calls in statics are limited to constant functions, tuple structs and tuple variants
= note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -2,14 +2,15 @@ error[E0015]: cannot call non-const function `non_const` in constant functions
--> $DIR/const-check-fns-in-const-impl.rs:14:16
|
LL | fn foo() { non_const() }
| ^^^^^^^^^^^
| -------- ^^^^^^^^^^^
| |
| calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
note: function `non_const` is not const
--> $DIR/const-check-fns-in-const-impl.rs:11:1
|
LL | fn non_const() {}
| ^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error

View file

@ -21,9 +21,7 @@ error[E0015]: cannot call non-const method `Formatter::<'_>::write_str` in const
--> $DIR/derive-const-gate.rs:1:16
|
LL | #[derive_const(Debug)]
| ^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
| ^^^^^ calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 3 previous errors

View file

@ -11,9 +11,7 @@ error[E0015]: cannot call non-const method `Formatter::<'_>::debug_tuple_field1_
--> $DIR/derive-const-non-const-type.rs:12:16
|
LL | #[derive_const(Debug)]
| ^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
| ^^^^^ calls in constant functions are limited to constant functions, tuple structs and tuple variants
error: aborting due to 2 previous errors

View file

@ -1,10 +1,12 @@
error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:22:11
|
LL | const fn const_context() {
| ------------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | Const.func();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> 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

View file

@ -1,18 +1,21 @@
error[E0015]: cannot call non-const method `<cross_crate::NonConst as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:19:14
|
LL | const fn const_context() {
| ------------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | #[cfg(any(stocknc, gatednc))]
LL | NonConst.func();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
error[E0658]: cannot call conditionally-const method `<cross_crate::Const as cross_crate::MyTrait>::func` in constant functions
--> $DIR/cross-crate.rs:22:11
|
LL | const fn const_context() {
| ------------------------ calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | Const.func();
| ^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> 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

View file

@ -10,6 +10,8 @@ LL | fn foo<T>(self) {
error[E0015]: cannot call non-const method `<() as Trait>::foo` in constant functions
--> $DIR/inline-incorrect-early-bound-in-ctfe.rs:26:8
|
LL | const fn foo() {
| -------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | ().foo();
| ^^^^^
|
@ -20,7 +22,6 @@ LL | trait Trait {
| ^^^^^^^^^^^ this trait is not const
LL | fn foo(self);
| ------------- this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Trait` const
|
LL + #[const_trait]

View file

@ -1,12 +1,13 @@
error[E0015]: cannot call non-const function `_print` in constant functions
--> $DIR/issue-79450.rs:9:9
|
LL | fn prov(&self) {
| -------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | println!("lul");
| ^^^^^^^^^^^^^^^
|
note: function `_print` is not const
--> $SRC_DIR/std/src/io/stdio.rs:LL:COL
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error

View file

@ -1,6 +1,8 @@
error[E0015]: cannot call non-const associated function `<T as A>::assoc` in constant functions
--> $DIR/issue-88155.rs:8:5
|
LL | pub const fn foo<T: A>() -> bool {
| -------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | T::assoc()
| ^^^^^^^^^^
|
@ -11,7 +13,6 @@ LL | pub trait A {
| ^^^^^^^^^^^ this trait is not const
LL | fn assoc() -> bool;
| ------------------- this associated function is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `A` const
|
LL + #[const_trait]

View file

@ -1,10 +1,11 @@
error[E0658]: cannot call conditionally-const associated function `<staged_api::Unstable as staged_api::MyTrait>::func` in constant functions
--> $DIR/staged-api-user-crate.rs:12:5
|
LL | const fn stable_const_context() {
| ------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | Unstable::func();
| ^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> 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

View file

@ -1,10 +1,11 @@
error[E0658]: cannot call conditionally-const associated function `<Vec<usize> as Default>::default` in constant functions
--> $DIR/std-impl-gate.rs:13:5
|
LL | const fn const_context() -> Vec<usize> {
| -------------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | Default::default()
| ^^^^^^^^^^^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> 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

View file

@ -48,6 +48,8 @@ LL | #[const_trait] trait Foo {
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-2.rs:20:7
|
LL | const fn foo<T: Bar>(x: &T) {
| --------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | x.a();
| ^^^
|
@ -58,7 +60,6 @@ LL | trait Foo {
| ^^^^^^^^^ this trait is not const
LL | fn a(&self);
| ------------ this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Foo` const
|
LL + #[const_trait]

View file

@ -60,6 +60,8 @@ LL | #[const_trait] trait Foo {
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-2.rs:20:7
|
LL | const fn foo<T: Bar>(x: &T) {
| --------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
LL | x.a();
| ^^^
|
@ -70,7 +72,6 @@ LL | trait Foo {
| ^^^^^^^^^ this trait is not const
LL | fn a(&self);
| ------------ this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Foo` const
|
LL + #[const_trait]

View file

@ -91,6 +91,9 @@ LL | #[const_trait] trait Bar: [const] Foo {}
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | const fn foo<T: [const] Bar>(x: &T) {
| ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | x.a();
| ^^^
|
@ -101,7 +104,6 @@ LL | trait Foo {
| ^^^^^^^^^ this trait is not const
LL | fn a(&self);
| ------------ this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Foo` const
|
LL + #[const_trait]

View file

@ -91,6 +91,9 @@ LL | #[const_trait] trait Bar: [const] Foo {}
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | const fn foo<T: [const] Bar>(x: &T) {
| ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | x.a();
| ^^^
|
@ -101,7 +104,6 @@ LL | trait Foo {
| ^^^^^^^^^ this trait is not const
LL | fn a(&self);
| ------------ this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Foo` const
|
LL + #[const_trait]

View file

@ -41,10 +41,12 @@ LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)]
error[E0658]: cannot call conditionally-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | const fn foo<T: [const] Bar>(x: &T) {
| ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | x.a();
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> 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

View file

@ -41,10 +41,12 @@ LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)]
error[E0658]: cannot call conditionally-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | const fn foo<T: [const] Bar>(x: &T) {
| ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | x.a();
| ^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> 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

View file

@ -71,6 +71,9 @@ LL | #[const_trait] trait Bar: [const] Foo {}
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | const fn foo<T: [const] Bar>(x: &T) {
| ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | x.a();
| ^^^
|
@ -81,7 +84,6 @@ LL | trait Foo {
| ^^^^^^^^^ this trait is not const
LL | fn a(&self);
| ------------ this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Foo` const
|
LL + #[const_trait]

View file

@ -60,6 +60,9 @@ LL | #[const_trait] trait Foo {
error[E0015]: cannot call non-const method `<T as Foo>::a` in constant functions
--> $DIR/super-traits-fail-3.rs:36:7
|
LL | const fn foo<T: [const] Bar>(x: &T) {
| ----------------------------------- calls in constant functions are limited to constant functions, tuple structs and tuple variants
...
LL | x.a();
| ^^^
|
@ -70,7 +73,6 @@ LL | trait Foo {
| ^^^^^^^^^ this trait is not const
LL | fn a(&self);
| ------------ this method is not const
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider making trait `Foo` const
|
LL + #[const_trait]

View file

@ -669,20 +669,23 @@ error[E0015]: cannot call non-const function `map::<u8>` in constants
--> $DIR/typeck_type_placeholder_item.rs:231:22
|
LL | const _: Option<_> = map(value);
| ^^^^^^^^^^
| ------------------ ^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: function `map` is not const
--> $DIR/typeck_type_placeholder_item.rs:222:1
|
LL | fn map<T>(_: fn() -> Option<&'static T>) -> Option<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const method `<std::ops::Range<i32> as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}>` in constants
--> $DIR/typeck_type_placeholder_item.rs:240:22
|
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
| ^^^^^^^^^^^^^^^^^^^^^^
| ---------- ^^^^^^^^^^^^^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: method `filter` is not const because trait `Iterator` is not const
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
@ -691,13 +694,14 @@ note: method `filter` is not const because trait `Iterator` is not const
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this method is not const
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:240:49: 240:52}>` in constants
--> $DIR/typeck_type_placeholder_item.rs:240:45
|
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
| ^^^^^^^^^^^^^^
| ---------- ^^^^^^^^^^^^^^
| |
| calls in constants are limited to constant functions, tuple structs and tuple variants
|
note: method `map` is not const because trait `Iterator` is not const
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
@ -706,7 +710,6 @@ note: method `map` is not const because trait `Iterator` is not const
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
|
= note: this method is not const
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 83 previous errors