Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use rustc_middle::util::Providers;
use rustc_session::Session;
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
use rustc_span::Symbol;
use rustc_target::spec::{RelocModel, TlsModel};

mod abi;
mod allocator;
Expand Down Expand Up @@ -244,16 +245,7 @@ impl CodegenBackend for LlvmCodegenBackend {
match req.kind {
PrintKind::RelocationModels => {
writeln!(out, "Available relocation models:").unwrap();
for name in &[
"static",
"pic",
"pie",
"dynamic-no-pic",
"ropi",
"rwpi",
"ropi-rwpi",
"default",
] {
for name in RelocModel::ALL.iter().map(RelocModel::desc).chain(["default"]) {
writeln!(out, " {name}").unwrap();
}
writeln!(out).unwrap();
Expand All @@ -267,9 +259,7 @@ impl CodegenBackend for LlvmCodegenBackend {
}
PrintKind::TlsModels => {
writeln!(out, "Available TLS models:").unwrap();
for name in
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
{
for name in TlsModel::ALL.iter().map(TlsModel::desc) {
writeln!(out, " {name}").unwrap();
}
writeln!(out).unwrap();
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_session/src/config/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,13 @@ impl CheckCfg {

ins!(sym::overflow_checks, no_values);

ins!(sym::panic, empty_values).extend(&PanicStrategy::all());
ins!(sym::panic, empty_values)
.extend(PanicStrategy::ALL.iter().map(PanicStrategy::desc_symbol));

ins!(sym::proc_macro, no_values);

ins!(sym::relocation_model, empty_values).extend(RelocModel::all());
ins!(sym::relocation_model, empty_values)
.extend(RelocModel::ALL.iter().map(RelocModel::desc_symbol));

let sanitize_values = SanitizerSet::all()
.into_iter()
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_target/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,31 @@ fn find_relative_libdir(sysroot: &Path) -> std::borrow::Cow<'static, str> {
macro_rules! target_spec_enum {
(
$( #[$attr:meta] )*
pub enum $name:ident {
pub enum $Name:ident {
$(
$( #[$variant_attr:meta] )*
$variant:ident = $string:literal,
$Variant:ident = $string:literal,
)*
}
parse_error_type = $parse_error_type:literal;
) => {
$( #[$attr] )*
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
#[derive(schemars::JsonSchema)]
pub enum $name {
pub enum $Name {
$(
$( #[$variant_attr] )*
#[serde(rename = $string)] // for JSON schema generation only
$variant,
$Variant,
)*
}

impl FromStr for $name {
impl FromStr for $Name {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
$( $string => Self::$variant, )*
$( $string => Self::$Variant, )*
_ => {
let all = [$( concat!("'", $string, "'") ),*].join(", ");
return Err(format!("invalid {}: '{s}'. allowed values: {all}", $parse_error_type));
Expand All @@ -109,24 +109,25 @@ macro_rules! target_spec_enum {
}
}

impl $name {
impl $Name {
pub const ALL: &'static [$Name] = &[ $( $Name::$Variant, )* ];
pub fn desc(&self) -> &'static str {
match self {
$( Self::$variant => $string, )*
$( Self::$Variant => $string, )*
}
}
}

impl crate::json::ToJson for $name {
impl crate::json::ToJson for $Name {
fn to_json(&self) -> crate::json::Json {
self.desc().to_json()
}
}

crate::json::serde_deserialize_from_str!($name);
crate::json::serde_deserialize_from_str!($Name);


impl std::fmt::Display for $name {
impl std::fmt::Display for $Name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.desc())
}
Expand Down
16 changes: 0 additions & 16 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,6 @@ impl PanicStrategy {
PanicStrategy::Abort => sym::abort,
}
}

pub const fn all() -> [Symbol; 2] {
[Self::Abort.desc_symbol(), Self::Unwind.desc_symbol()]
}
}

crate::target_spec_enum! {
Expand Down Expand Up @@ -974,18 +970,6 @@ impl RelocModel {
RelocModel::RopiRwpi => sym::ropi_rwpi,
}
}

pub const fn all() -> [Symbol; 7] {
[
RelocModel::Static.desc_symbol(),
RelocModel::Pic.desc_symbol(),
RelocModel::Pie.desc_symbol(),
RelocModel::DynamicNoPic.desc_symbol(),
RelocModel::Ropi.desc_symbol(),
RelocModel::Rwpi.desc_symbol(),
RelocModel::RopiRwpi.desc_symbol(),
]
}
}

crate::target_spec_enum! {
Expand Down
Loading