Rollup merge of #130895 - RalfJung:asm-tests, r=nnethercote

make type-check-4 asm tests about non-const expressions

These tests recently got changed in https://github.com/rust-lang/rust/pull/129759. I asked the PR author to make the tests read from a `static mut` (rather than just making them "pass"), but I now think that was a mistake: previously the tests failed because the const was not a valid const expression, after the PR they failed because the const failed to evaluate.

So this PR restores the tests to "fail because the const is not a valid const expression". That can be done in a target-independent way so I unified the x86 and aarch64 tests into one.

Cc `@oli-obk` as the original [author](0d88631059) of these tests -- not sure if you still remember what they were intended to test.
This commit is contained in:
Matthias Krüger 2024-09-30 14:33:46 +02:00 committed by GitHub
commit fd2785f67a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 96 deletions

View File

@ -1,27 +0,0 @@
//@ only-aarch64
//@ build-fail
use std::arch::global_asm;
fn main() {}
// Constants must be... constant
static mut S: i32 = 1;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
global_asm!("{}", const unsafe { S });
//~^ ERROR: evaluation of constant value failed
//~| mutable global memory
global_asm!("{}", const const_foo(0));
global_asm!("{}", const const_foo(unsafe { S }));
//~^ ERROR: evaluation of constant value failed
//~| mutable global memory
global_asm!("{}", const const_bar(0));
global_asm!("{}", const const_bar(unsafe { S }));
//~^ ERROR: evaluation of constant value failed
//~| mutable global memory

View File

@ -1,21 +0,0 @@
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:17:34
|
LL | global_asm!("{}", const unsafe { S });
| ^ constant accesses mutable global memory
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:21:44
|
LL | global_asm!("{}", const const_foo(unsafe { S }));
| ^ constant accesses mutable global memory
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:25:44
|
LL | global_asm!("{}", const const_bar(unsafe { S }));
| ^ constant accesses mutable global memory
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0080`.

11
tests/ui/asm/non-const.rs Normal file
View File

@ -0,0 +1,11 @@
//@ needs-asm-support
use std::arch::global_asm;
fn main() {}
// Constants must be... constant
fn non_const_fn(x: i32) -> i32 { x }
global_asm!("/* {} */", const non_const_fn(0));
//~^ERROR: cannot call non-const fn

View File

@ -0,0 +1,11 @@
error[E0015]: cannot call non-const fn `non_const_fn` in constants
--> $DIR/non-const.rs:10:31
|
LL | global_asm!("/* {} */", const non_const_fn(0));
| ^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0015`.

View File

@ -1,27 +0,0 @@
//@ only-x86_64
//@ build-fail
use std::arch::global_asm;
fn main() {}
// Constants must be... constant
static mut S: i32 = 1;
const fn const_foo(x: i32) -> i32 {
x
}
const fn const_bar<T>(x: T) -> T {
x
}
global_asm!("{}", const unsafe { S });
//~^ ERROR evaluation of constant value failed
//~| mutable global memory
global_asm!("{}", const const_foo(0));
global_asm!("{}", const const_foo(unsafe { S }));
//~^ ERROR evaluation of constant value failed
//~| mutable global memory
global_asm!("{}", const const_bar(0));
global_asm!("{}", const const_bar(unsafe { S }));
//~^ ERROR evaluation of constant value failed
//~| mutable global memory

View File

@ -1,21 +0,0 @@
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:17:34
|
LL | global_asm!("{}", const unsafe { S });
| ^ constant accesses mutable global memory
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:21:44
|
LL | global_asm!("{}", const const_foo(unsafe { S }));
| ^ constant accesses mutable global memory
error[E0080]: evaluation of constant value failed
--> $DIR/type-check-4.rs:25:44
|
LL | global_asm!("{}", const const_bar(unsafe { S }));
| ^ constant accesses mutable global memory
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0080`.