about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-05-03 12:44:35 +0200
committerGitHub <noreply@github.com>2025-05-03 12:44:35 +0200
commitd8b0347a4bd82edd3e109d651cf074aa83365c47 (patch)
tree34e8c260458486a3c735ca6d7bf06d2a4fdfeea6
parenta1a23debd614b14ffdc41b4dcbb4cc4712b473f5 (diff)
parent6873a46626fef5f8f95488272fc605b4847d011e (diff)
downloadrust-d8b0347a4bd82edd3e109d651cf074aa83365c47.tar.gz
rust-d8b0347a4bd82edd3e109d651cf074aa83365c47.zip
Rollup merge of #140395 - RalfJung:target-feature-tests, r=petrochenkov
organize and extend forbidden target feature tests

In particular this adds some loongarch tests for https://github.com/rust-lang/rust/pull/135015, Cc `@heiher`

Seems like the tests change so much git does not detect the renames; a commit-by-commit review should help.

try-job: `x86_64-gnu-llvm-20-*`
-rw-r--r--tests/ui/target-feature/abi-incompatible-target-feature-attribute.riscv.stderr8
-rw-r--r--tests/ui/target-feature/abi-incompatible-target-feature-attribute.rs17
-rw-r--r--tests/ui/target-feature/abi-incompatible-target-feature-attribute.x86.stderr8
-rw-r--r--tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr19
-rw-r--r--tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs22
-rw-r--r--tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.x86.stderr (renamed from tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.stderr)0
-rw-r--r--tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.rs (renamed from tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.rs)3
-rw-r--r--tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.stderr (renamed from tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.stderr)0
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-attribute.rs (renamed from tests/ui/target-feature/allowed-softfloat-target-feature-attribute.rs)2
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-flag-disable.aarch64.stderr (renamed from tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr)0
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-flag-disable.loongarch.stderr11
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr11
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-flag-disable.rs27
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-flag-disable.x86-implied.stderr (renamed from tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr)0
-rw-r--r--tests/ui/target-feature/abi-required-target-feature-flag-disable.x86.stderr (renamed from tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.stderr)0
-rw-r--r--tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs15
-rw-r--r--tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs13
-rw-r--r--tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.rs15
-rw-r--r--tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.rs15
19 files changed, 128 insertions, 58 deletions
diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-attribute.riscv.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-attribute.riscv.stderr
new file mode 100644
index 00000000000..49c5479275f
--- /dev/null
+++ b/tests/ui/target-feature/abi-incompatible-target-feature-attribute.riscv.stderr
@@ -0,0 +1,8 @@
+error: target feature `d` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
+  --> $DIR/abi-incompatible-target-feature-attribute.rs:15:90
+   |
+LL | #[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
+   |                                                                                          ^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-attribute.rs b/tests/ui/target-feature/abi-incompatible-target-feature-attribute.rs
new file mode 100644
index 00000000000..a8733440759
--- /dev/null
+++ b/tests/ui/target-feature/abi-incompatible-target-feature-attribute.rs
@@ -0,0 +1,17 @@
+//! Ensure ABI-incompatible features cannot be enabled via `#[target_feature]`.
+// ignore-tidy-linelength
+//@ compile-flags: --crate-type=lib
+//@ revisions: x86 riscv
+//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu
+//@[x86] needs-llvm-components: x86
+//@[riscv] compile-flags: --target=riscv32e-unknown-none-elf
+//@[riscv] needs-llvm-components: riscv
+#![feature(no_core, lang_items, riscv_target_feature, x87_target_feature)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
+//~^ERROR: cannot be enabled with
+pub unsafe fn my_fun() {}
diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-attribute.x86.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-attribute.x86.stderr
new file mode 100644
index 00000000000..81471fd7e30
--- /dev/null
+++ b/tests/ui/target-feature/abi-incompatible-target-feature-attribute.x86.stderr
@@ -0,0 +1,8 @@
+error: target feature `soft-float` cannot be enabled with `#[target_feature]`: this feature is incompatible with the target ABI
+  --> $DIR/abi-incompatible-target-feature-attribute.rs:15:32
+   |
+LL | #[cfg_attr(x86, target_feature(enable = "soft-float"))] #[cfg_attr(riscv, target_feature(enable = "d"))]
+   |                                ^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr
new file mode 100644
index 00000000000..2dca0c22033
--- /dev/null
+++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr
@@ -0,0 +1,19 @@
+warning: target feature `d` must be disabled to ensure that the ABI of the current target can be implemented correctly
+   |
+   = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
+
+warning: unstable feature specified for `-Ctarget-feature`: `d`
+   |
+   = note: this feature is not stably supported; its behavior can change in the future
+
+warning: unstable feature specified for `-Ctarget-feature`: `f`
+   |
+   = note: this feature is not stably supported; its behavior can change in the future
+
+warning: unstable feature specified for `-Ctarget-feature`: `zicsr`
+   |
+   = note: this feature is not stably supported; its behavior can change in the future
+
+warning: 4 warnings emitted
+
diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs
new file mode 100644
index 00000000000..68e1d3b9ddc
--- /dev/null
+++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs
@@ -0,0 +1,22 @@
+//! Ensure ABI-incompatible features cannot be enabled via `-Ctarget-feature`.
+// These are just warnings for now.
+//@ check-pass
+//@ compile-flags: --crate-type=lib
+//@ revisions: x86 riscv
+//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=+soft-float
+//@[x86] needs-llvm-components: x86
+//@[riscv] compile-flags: --target=riscv32e-unknown-none-elf -Ctarget-feature=+d
+//@[riscv] needs-llvm-components: riscv
+
+#![feature(no_core, lang_items, riscv_target_feature)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+#[lang = "freeze"]
+pub trait Freeze {}
+
+//~? WARN must be disabled to ensure that the ABI of the current target can be implemented correctly
+//~? WARN unstable feature specified for `-Ctarget-feature`
+//[riscv]~? WARN unstable feature specified for `-Ctarget-feature`
+//[riscv]~? WARN unstable feature specified for `-Ctarget-feature`
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.x86.stderr
index e49672f33b9..e49672f33b9 100644
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.stderr
+++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.x86.stderr
diff --git a/tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.rs b/tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.rs
index 7368ef120fa..0013d033b9c 100644
--- a/tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.rs
+++ b/tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.rs
@@ -1,3 +1,6 @@
+//! `x87` is a required target feature on some x86 targets, but not on this one as this one
+//! uses soft-floats. So ensure disabling the target feature here (which is a NOP) does
+//! not trigger a warning.
 //@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
 //@ needs-llvm-components: x86
 //@ compile-flags: -Ctarget-feature=-x87
diff --git a/tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.stderr b/tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.stderr
index 309b64afd92..309b64afd92 100644
--- a/tests/ui/target-feature/allowed-softfloat-target-feature-flag-disable.stderr
+++ b/tests/ui/target-feature/abi-irrelevant-target-feature-flag-disable.stderr
diff --git a/tests/ui/target-feature/allowed-softfloat-target-feature-attribute.rs b/tests/ui/target-feature/abi-required-target-feature-attribute.rs
index 8b60820cc9b..95723c57f94 100644
--- a/tests/ui/target-feature/allowed-softfloat-target-feature-attribute.rs
+++ b/tests/ui/target-feature/abi-required-target-feature-attribute.rs
@@ -1,3 +1,5 @@
+//! Enabling a target feature that is anyway required changes nothing, so this is allowed
+//! for `#[target_feature]`.
 //@ compile-flags: --target=x86_64-unknown-none --crate-type=lib
 //@ needs-llvm-components: x86
 //@ build-pass
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.aarch64.stderr
index b1186d5d5dc..b1186d5d5dc 100644
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.stderr
+++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.aarch64.stderr
diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.loongarch.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.loongarch.stderr
new file mode 100644
index 00000000000..35102e0571f
--- /dev/null
+++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.loongarch.stderr
@@ -0,0 +1,11 @@
+warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
+   |
+   = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
+
+warning: unstable feature specified for `-Ctarget-feature`: `d`
+   |
+   = note: this feature is not stably supported; its behavior can change in the future
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr
new file mode 100644
index 00000000000..35102e0571f
--- /dev/null
+++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr
@@ -0,0 +1,11 @@
+warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly
+   |
+   = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
+
+warning: unstable feature specified for `-Ctarget-feature`: `d`
+   |
+   = note: this feature is not stably supported; its behavior can change in the future
+
+warning: 2 warnings emitted
+
diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs b/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs
new file mode 100644
index 00000000000..c3ce05baa64
--- /dev/null
+++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs
@@ -0,0 +1,27 @@
+//! Ensure ABI-required features cannot be disabled via `-Ctarget-feature`.
+//! Also covers the case of a feature indirectly disabling another via feature implications.
+//@ compile-flags: --crate-type=lib
+//@ revisions: x86 x86-implied aarch64 riscv loongarch
+//@[x86] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-x87
+//@[x86] needs-llvm-components: x86
+//@[x86-implied] compile-flags: --target=x86_64-unknown-linux-gnu -Ctarget-feature=-sse
+//@[x86-implied] needs-llvm-components: x86
+//@[aarch64] compile-flags: --target=aarch64-unknown-linux-gnu -Ctarget-feature=-neon
+//@[aarch64] needs-llvm-components: aarch64
+//@[riscv] compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=-d
+//@[riscv] needs-llvm-components: riscv
+//@[loongarch] compile-flags: --target=loongarch64-unknown-none -Ctarget-feature=-d
+//@[loongarch] needs-llvm-components: loongarch
+// For now this is just a warning.
+//@ build-pass
+// Remove some LLVM warnings that only show up sometimes.
+//@ normalize-stderr: "\n[^\n]*(target-abi|lp64f)[^\n]*" -> ""
+
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+//~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly
+//[x86,riscv,loongarch]~? WARN unstable feature specified for `-Ctarget-feature`
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.x86-implied.stderr
index 7ec8b04cfce..7ec8b04cfce 100644
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.stderr
+++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.x86-implied.stderr
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.x86.stderr
index 02398d27501..02398d27501 100644
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.stderr
+++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.x86.stderr
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs
deleted file mode 100644
index 12e7e3bc45b..00000000000
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-implied.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//! Ensure that if disabling a target feature implies disabling an ABI-required target feature,
-//! we complain.
-//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
-//@ needs-llvm-components: x86
-//@ compile-flags: -Ctarget-feature=-sse
-// For now this is just a warning.
-//@ build-pass
-
-#![feature(no_core, lang_items)]
-#![no_core]
-
-#[lang = "sized"]
-pub trait Sized {}
-
-//~? WARN target feature `sse2` must be enabled to ensure that the ABI of the current target can be implemented correctly
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs
deleted file mode 100644
index 33e4f12694f..00000000000
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable-neon.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//@ compile-flags: --target=aarch64-unknown-linux-gnu --crate-type=lib
-//@ needs-llvm-components: aarch64
-//@ compile-flags: -Ctarget-feature=-neon
-// For now this is just a warning.
-//@ build-pass
-
-#![feature(no_core, lang_items)]
-#![no_core]
-
-#[lang = "sized"]
-pub trait Sized {}
-
-//~? WARN target feature `neon` must be enabled to ensure that the ABI of the current target can be implemented correctly
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.rs b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.rs
deleted file mode 100644
index e1bd25ffad1..00000000000
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag-disable.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//! Ensure ABI-required features cannot be disabled via `-Ctarget-feature`.
-//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
-//@ needs-llvm-components: x86
-//@ compile-flags: -Ctarget-feature=-x87
-// For now this is just a warning.
-//@ build-pass
-
-#![feature(no_core, lang_items)]
-#![no_core]
-
-#[lang = "sized"]
-pub trait Sized {}
-
-//~? WARN target feature `x87` must be enabled to ensure that the ABI of the current target can be implemented correctly
-//~? WARN unstable feature specified for `-Ctarget-feature`: `x87`
diff --git a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.rs b/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.rs
deleted file mode 100644
index 4ccc6e0e941..00000000000
--- a/tests/ui/target-feature/forbidden-hardfloat-target-feature-flag.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//! Ensure ABI-incompatible features cannot be enabled via `-Ctarget-feature`.
-//@ compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=lib
-//@ needs-llvm-components: x86
-//@ compile-flags: -Ctarget-feature=+soft-float
-// For now this is just a warning.
-//@ build-pass
-
-#![feature(no_core, lang_items, riscv_target_feature)]
-#![no_core]
-
-#[lang = "sized"]
-pub trait Sized {}
-
-//~? WARN target feature `soft-float` must be disabled to ensure that the ABI of the current target can be implemented correctl
-//~? WARN unstable feature specified for `-Ctarget-feature`: `soft-float`