Skip to content

Commit 8b4f2c2

Browse files
committed
feat: display valid values in --crate-type
1 parent 32c8a9f commit 8b4f2c2

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

compiler/rustc_session/src/config.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::path::{Path, PathBuf};
1313
use std::str::{self, FromStr};
1414
use std::sync::LazyLock;
1515
use std::{cmp, fmt, fs, iter};
16-
1716
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1817
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
1918
use rustc_errors::emitter::HumanReadableErrorType;
@@ -1296,6 +1295,29 @@ impl CrateType {
12961295
CrateType::Executable | CrateType::Cdylib | CrateType::Staticlib => false,
12971296
}
12981297
}
1298+
1299+
pub fn shorthand(&self) -> &'static str {
1300+
match *self {
1301+
CrateType::Executable => "bin",
1302+
CrateType::Dylib => "dylib",
1303+
CrateType::Rlib => "rlib",
1304+
CrateType::Staticlib => "lib",
1305+
CrateType::Cdylib => "cdylib",
1306+
CrateType::ProcMacro => "proc-macro",
1307+
}
1308+
}
1309+
1310+
fn shorthands_display() -> String {
1311+
format!(
1312+
"`{}`, `{}`, `{}`, `{}`, `{}`, `{}`",
1313+
CrateType::Executable.shorthand(),
1314+
CrateType::Dylib.shorthand(),
1315+
CrateType::Rlib.shorthand(),
1316+
CrateType::Staticlib.shorthand(),
1317+
CrateType::Cdylib.shorthand(),
1318+
CrateType::ProcMacro.shorthand(),
1319+
)
1320+
}
12991321
}
13001322

13011323
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
@@ -2678,7 +2700,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
26782700
"cdylib" => CrateType::Cdylib,
26792701
"bin" => CrateType::Executable,
26802702
"proc-macro" => CrateType::ProcMacro,
2681-
_ => return Err(format!("unknown crate type: `{part}`")),
2703+
_ => return Err(format!("unknown crate type: `{part}` - expected one of: {display}", display = CrateType::shorthands_display())),
26822704
};
26832705
if !crate_types.contains(&new_part) {
26842706
crate_types.push(new_part)

0 commit comments

Comments
 (0)