mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Use an error struct instead of a panic
This commit is contained in:
parent
518becf5ea
commit
b780fa9219
@ -18,6 +18,8 @@ codegen_llvm_error_creating_import_library =
|
||||
codegen_llvm_error_writing_def_file =
|
||||
Error writing .DEF file: {$error}
|
||||
|
||||
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
|
||||
|
||||
codegen_llvm_from_llvm_diag = {$message}
|
||||
|
||||
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}
|
||||
|
@ -254,3 +254,9 @@ pub struct MismatchedDataLayout<'a> {
|
||||
pub(crate) struct InvalidTargetFeaturePrefix<'a> {
|
||||
pub feature: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_llvm_fixed_x18_invalid_arch)]
|
||||
pub(crate) struct FixedX18InvalidArch<'a> {
|
||||
pub arch: &'a str,
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::back::write::create_informational_target_machine;
|
||||
use crate::errors::{
|
||||
InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
|
||||
FixedX18InvalidArch, InvalidTargetFeaturePrefix, PossibleFeature, TargetFeatureDisableOrEnable,
|
||||
UnknownCTargetFeature, UnknownCTargetFeaturePrefix, UnstableCTargetFeature,
|
||||
};
|
||||
use crate::llvm;
|
||||
@ -618,11 +618,10 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
|
||||
// -Zfixed-x18
|
||||
if sess.opts.unstable_opts.fixed_x18 {
|
||||
if sess.target.arch != "aarch64" {
|
||||
// TODO: What's the correct way to return a error here?
|
||||
panic!("-Zfixed-x18 only allowed on aarch64");
|
||||
sess.dcx().emit_fatal(FixedX18InvalidArch { arch: &sess.target.arch });
|
||||
} else {
|
||||
features.push("+reserve-x18".into());
|
||||
}
|
||||
|
||||
features.push("+reserve-x18".into());
|
||||
}
|
||||
|
||||
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
|
||||
|
2
tests/ui/abi/fixed_x18.aarch64.stderr
Normal file
2
tests/ui/abi/fixed_x18.aarch64.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: the `-Zfixed-x18` flag is not supported on the `x86_64` architecture
|
||||
|
2
tests/ui/abi/fixed_x18.arm.stderr
Normal file
2
tests/ui/abi/fixed_x18.arm.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: the `-Zfixed-x18` flag is not supported on the `arm` architecture
|
||||
|
2
tests/ui/abi/fixed_x18.i686.stderr
Normal file
2
tests/ui/abi/fixed_x18.i686.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: the `-Zfixed-x18` flag is not supported on the `x86` architecture
|
||||
|
2
tests/ui/abi/fixed_x18.riscv32.stderr
Normal file
2
tests/ui/abi/fixed_x18.riscv32.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: the `-Zfixed-x18` flag is not supported on the `riscv32` architecture
|
||||
|
2
tests/ui/abi/fixed_x18.riscv64.stderr
Normal file
2
tests/ui/abi/fixed_x18.riscv64.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: the `-Zfixed-x18` flag is not supported on the `riscv64` architecture
|
||||
|
23
tests/ui/abi/fixed_x18.rs
Normal file
23
tests/ui/abi/fixed_x18.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// This tests that -Zfixed-x18 causes a compilation failure on targets other than aarch64.
|
||||
// Behavior on aarch64 is tested by tests/codegen/fixed-x18.rs.
|
||||
//
|
||||
//@ revisions: x64 i686 aarch64 arm riscv32 riscv64
|
||||
//
|
||||
//@ compile-flags: -Zfixed-x18
|
||||
//@ [x64] needs-llvm-components: x86
|
||||
//@ [x64] compile-flags: --target=x86_64-unknown-linux-gnu --crate-type=rlib
|
||||
//@ [i686] needs-llvm-components: x86
|
||||
//@ [i686] compile-flags: --target=i686-unknown-linux-gnu --crate-type=rlib
|
||||
//@ [arm] needs-llvm-components: arm
|
||||
//@ [arm] compile-flags: --target=armv7-unknown-linux-gnueabihf --crate-type=rlib
|
||||
//@ [riscv32] needs-llvm-components: riscv
|
||||
//@ [riscv32] compile-flags: --target=riscv32i-unknown-none-elf --crate-type=rlib
|
||||
//@ [riscv64] needs-llvm-components: riscv
|
||||
//@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf --crate-type=rlib
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![feature(no_core, lang_items)]
|
||||
#![no_core]
|
||||
|
||||
#[lang = "sized"]
|
||||
trait Sized {}
|
2
tests/ui/abi/fixed_x18.x64.stderr
Normal file
2
tests/ui/abi/fixed_x18.x64.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: the `-Zfixed-x18` flag is not supported on the `x86_64` architecture
|
||||
|
Loading…
Reference in New Issue
Block a user