diff --git a/compiler/rustc_interface/src/diagnostics.rs b/compiler/rustc_interface/src/diagnostics.rs index 2a2757f814715..191f36ee2f9f1 100644 --- a/compiler/rustc_interface/src/diagnostics.rs +++ b/compiler/rustc_interface/src/diagnostics.rs @@ -122,13 +122,16 @@ pub(crate) struct MultipleOutputTypesToStdout; #[diag( "target feature `{$feature}` 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 ")] pub(crate) struct AbiRequiredTargetFeature<'a> { pub feature: &'a str, pub enabled: &'a str, + #[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 " + )] + pub fcw: bool, } #[derive(Diagnostic)] diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 89907447571ee..c6636383eb1a9 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -29,7 +29,7 @@ use rustc_span::edition::Edition; use rustc_span::source_map::SourceMapInputs; use rustc_span::{SessionGlobals, Symbol, sym}; use rustc_structures::CrateType; -use rustc_target::spec::Target; +use rustc_target::spec::{Arch, Target}; use tracing::info; use crate::diagnostics; @@ -107,16 +107,36 @@ pub(crate) fn check_abi_required_features(sess: &Session) { ); } + // Make this a hard error on ARM since starting with LLVM24, the backend will otherwise + // emit a (less friendly) hard error. + let hard_error = matches!(sess.target.arch, Arch::Arm); + for feature in abi_feature_constraints.required { if !sess.internal_target_features.contains(&Symbol::intern(feature)) { - sess.dcx() - .emit_warn(diagnostics::AbiRequiredTargetFeature { feature, enabled: "enabled" }); + let diag = diagnostics::AbiRequiredTargetFeature { + feature, + enabled: "enabled", + fcw: !hard_error, + }; + if hard_error { + sess.dcx().emit_err(diag); + } else { + sess.dcx().emit_warn(diag); + } } } for feature in abi_feature_constraints.incompatible { if sess.internal_target_features.contains(&Symbol::intern(feature)) { - sess.dcx() - .emit_warn(diagnostics::AbiRequiredTargetFeature { feature, enabled: "disabled" }); + let diag = diagnostics::AbiRequiredTargetFeature { + feature, + enabled: "disabled", + fcw: !hard_error, + }; + if hard_error { + sess.dcx().emit_err(diag); + } else { + sess.dcx().emit_warn(diag); + } } } } diff --git a/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.arm.stderr b/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.arm.stderr index 52862ec5151b3..73b3e5bacd906 100644 --- a/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.arm.stderr +++ b/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.arm.stderr @@ -1,7 +1,4 @@ -warning: target feature `fpregs` 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 +error: target feature `fpregs` must be enabled to ensure that the ABI of the current target can be implemented correctly -warning: 1 warning emitted +error: aborting due to 1 previous error diff --git a/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.rs b/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.rs index e652f321ad33b..59d0ba1a0ba4f 100644 --- a/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.rs +++ b/tests/ui/target-feature/abi-required-target-feature-missing-in-target-cpu.rs @@ -9,14 +9,14 @@ //@[arm] compile-flags: --target=armv8r-none-eabihf -Ctarget-cpu=cortex-r4 //@[arm] needs-llvm-components: arm -// LLVM 24 refuses to compile ARM minicore due to mismatched target features. -// FIXME(#161276): With LLVM rejecting this, we should make Rust's own warning an error. -//@[arm] max-llvm-major-version: 23 +// On x86 this is just a warning. +//@[x86] check-pass +//@[arm] check-fail -// For now this is just a warning. -//@ build-pass //@ ignore-backends: gcc //@ add-minicore +// Don't inherit the target-cpu above for minicore, to avoid errors when building that. +//@ minicore-compile-flags: -Ctarget-cpu=generic #![feature(no_core)] #![no_core] @@ -24,4 +24,5 @@ extern crate minicore; use minicore::*; -//~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly +//[x86]~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly +//[arm]~? ERROR must be enabled to ensure that the ABI of the current target can be implemented correctly