From c67ff2ab50cb476b08c2318e2c2025a22ce696de Mon Sep 17 00:00:00 2001 From: Evgenii Zheltonozhskii Date: Wed, 19 Aug 2026 18:52:27 +0300 Subject: [PATCH] Don't rely on std traits not being const in tests --- tests/ui/consts/const-fn-error.rs | 16 --------------- tests/ui/consts/const-fn-error.stderr | 20 ------------------- tests/ui/static/static-mut-not-constant.rs | 8 +++++++- .../ui/static/static-mut-not-constant.stderr | 8 ++++---- 4 files changed, 11 insertions(+), 41 deletions(-) delete mode 100644 tests/ui/consts/const-fn-error.rs delete mode 100644 tests/ui/consts/const-fn-error.stderr diff --git a/tests/ui/consts/const-fn-error.rs b/tests/ui/consts/const-fn-error.rs deleted file mode 100644 index b71517824232f..0000000000000 --- a/tests/ui/consts/const-fn-error.rs +++ /dev/null @@ -1,16 +0,0 @@ -const X : usize = 2; - -const fn f(x: usize) -> usize { - let mut sum = 0; - for i in 0..x { - //~^ ERROR cannot use `for` - //~| ERROR cannot use `for` - sum += i; - } - sum -} - -#[allow(unused_variables)] -fn main() { - let a : [i32; f(X)]; -} diff --git a/tests/ui/consts/const-fn-error.stderr b/tests/ui/consts/const-fn-error.stderr deleted file mode 100644 index 3d4cf6539c896..0000000000000 --- a/tests/ui/consts/const-fn-error.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0015]: cannot use `for` loop on `std::ops::Range` in constant functions - --> $DIR/const-fn-error.rs:5:14 - | -LL | for i in 0..x { - | ^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - -error[E0015]: cannot use `for` loop on `std::ops::Range` in constant functions - --> $DIR/const-fn-error.rs:5:14 - | -LL | for i in 0..x { - | ^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/static/static-mut-not-constant.rs b/tests/ui/static/static-mut-not-constant.rs index 3830b46828707..48129c09c8dc2 100644 --- a/tests/ui/static/static-mut-not-constant.rs +++ b/tests/ui/static/static-mut-not-constant.rs @@ -1,4 +1,10 @@ -static mut a: Box = Box::new(3); +struct Foo {} + +impl Foo { + fn new(_a: usize) -> Self { Foo{} } +} + +static mut a: Foo = Foo::new(3); //~^ ERROR cannot call non-const associated function fn main() {} diff --git a/tests/ui/static/static-mut-not-constant.stderr b/tests/ui/static/static-mut-not-constant.stderr index f28ea0b1689ab..c96eab038c778 100644 --- a/tests/ui/static/static-mut-not-constant.stderr +++ b/tests/ui/static/static-mut-not-constant.stderr @@ -1,8 +1,8 @@ -error[E0015]: cannot call non-const associated function `Box::::new` in statics - --> $DIR/static-mut-not-constant.rs:1:28 +error[E0015]: cannot call non-const associated function `Foo::new` in statics + --> $DIR/static-mut-not-constant.rs:7:21 | -LL | static mut a: Box = Box::new(3); - | ^^^^^^^^^^^ +LL | static mut a: Foo = Foo::new(3); + | ^^^^^^^^^^^ | = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)`