Skip to content

Commit 702c67c

Browse files
committed
Use a macro to impl FromStr for target spec data structures
1 parent 283a074 commit 702c67c

File tree

4 files changed

+306
-621
lines changed

4 files changed

+306
-621
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ use rustc_middle::util::Providers;
4646
use rustc_session::Session;
4747
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4848
use rustc_span::Symbol;
49+
use rustc_target::spec::{CodeModel, RelocModel, TlsModel};
4950

5051
mod back {
5152
pub(crate) mod archive;
@@ -267,32 +268,27 @@ impl CodegenBackend for LlvmCodegenBackend {
267268
match req.kind {
268269
PrintKind::RelocationModels => {
269270
writeln!(out, "Available relocation models:").unwrap();
270-
for name in &[
271-
"static",
272-
"pic",
273-
"pie",
274-
"dynamic-no-pic",
275-
"ropi",
276-
"rwpi",
277-
"ropi-rwpi",
278-
"default",
279-
] {
271+
for name in RelocModel::ALL
272+
.iter()
273+
.copied()
274+
.map(RelocModel::as_str)
275+
.into_iter()
276+
.chain(["default"])
277+
{
280278
writeln!(out, " {name}").unwrap();
281279
}
282280
writeln!(out).unwrap();
283281
}
284282
PrintKind::CodeModels => {
285283
writeln!(out, "Available code models:").unwrap();
286-
for name in &["tiny", "small", "kernel", "medium", "large"] {
284+
for name in CodeModel::ALL.iter().copied().map(CodeModel::as_str) {
287285
writeln!(out, " {name}").unwrap();
288286
}
289287
writeln!(out).unwrap();
290288
}
291289
PrintKind::TlsModels => {
292290
writeln!(out, "Available TLS models:").unwrap();
293-
for name in
294-
&["global-dynamic", "local-dynamic", "initial-exec", "local-exec", "emulated"]
295-
{
291+
for name in TlsModel::ALL.iter().copied().map(TlsModel::as_str) {
296292
writeln!(out, " {name}").unwrap();
297293
}
298294
writeln!(out).unwrap();

compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl IntoDiagArg for PathBuf {
200200

201201
impl IntoDiagArg for PanicStrategy {
202202
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
203-
DiagArgValue::Str(Cow::Owned(self.desc().to_string()))
203+
DiagArgValue::Str(Cow::Owned(self.as_str().to_string()))
204204
}
205205
}
206206

compiler/rustc_session/src/config/cfg.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,12 @@ impl CheckCfg {
375375

376376
ins!(sym::overflow_checks, no_values);
377377

378-
ins!(sym::panic, empty_values).extend(&PanicStrategy::all());
378+
ins!(sym::panic, empty_values).extend(PanicStrategy::ALL.iter().map(|p| p.desc_symbol()));
379379

380380
ins!(sym::proc_macro, no_values);
381381

382-
ins!(sym::relocation_model, empty_values).extend(RelocModel::all());
382+
ins!(sym::relocation_model, empty_values)
383+
.extend(RelocModel::ALL.iter().map(|m| m.desc_symbol()));
383384

384385
let sanitize_values = SanitizerSet::all()
385386
.into_iter()

0 commit comments

Comments
 (0)