Skip to content

Commit 6315245

Browse files
committed
Display valid values in --crate-type
1 parent 32c8a9f commit 6315245

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

compiler/rustc_session/src/config.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,29 @@ impl CrateType {
12961296
CrateType::Executable | CrateType::Cdylib | CrateType::Staticlib => false,
12971297
}
12981298
}
1299+
1300+
pub fn shorthand(&self) -> &'static str {
1301+
match *self {
1302+
CrateType::Executable => "bin",
1303+
CrateType::Dylib => "dylib",
1304+
CrateType::Rlib => "rlib",
1305+
CrateType::Staticlib => "lib",
1306+
CrateType::Cdylib => "cdylib",
1307+
CrateType::ProcMacro => "proc-macro",
1308+
}
1309+
}
1310+
1311+
fn shorthands_display() -> String {
1312+
format!(
1313+
"`{}`, `{}`, `{}`, `{}`, `{}`, `{}`",
1314+
CrateType::Executable.shorthand(),
1315+
CrateType::Dylib.shorthand(),
1316+
CrateType::Rlib.shorthand(),
1317+
CrateType::Staticlib.shorthand(),
1318+
CrateType::Cdylib.shorthand(),
1319+
CrateType::ProcMacro.shorthand(),
1320+
)
1321+
}
12991322
}
13001323

13011324
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
@@ -2678,7 +2701,12 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
26782701
"cdylib" => CrateType::Cdylib,
26792702
"bin" => CrateType::Executable,
26802703
"proc-macro" => CrateType::ProcMacro,
2681-
_ => return Err(format!("unknown crate type: `{part}`")),
2704+
_ => {
2705+
return Err(format!(
2706+
"unknown crate type: `{part}` - expected one of: {display}",
2707+
display = CrateType::shorthands_display()
2708+
));
2709+
}
26822710
};
26832711
if !crate_types.contains(&new_part) {
26842712
crate_types.push(new_part)

tests/ui/crate_type_flag.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ compile-flags: --crate-type dynlib
2+
//@ error-pattern: unknown crate type: `dynlib` - expected one of: `bin`, `dylib`, `rlib`, `lib`, `cdylib`, `proc-macro`
3+
4+
fn main() {}

tests/ui/crate_type_flag.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: unknown crate type: `dynlib` - expected one of: `bin`, `dylib`, `rlib`, `lib`, `cdylib`, `proc-macro`
2+

0 commit comments

Comments
 (0)