Rollup merge of #45782 - frewsxcv:frewsxcv-shorthands-helpers, r=manishearth
Display all emission types in error msg if user inputs invalid option. before: ``` > rustc --emit foo error: unknown emission type: `foo` ``` after: ``` > rustc --emit foo error: unknown emission type: `foo` - expected one of: `llvm-bc`, `asm`, `llvm-ir`, `mir`, `obj`, `metadata`, `link`, `dep-info` ```
This commit is contained in:
commit
1683b830a8
1 changed files with 35 additions and 13 deletions
|
@ -138,6 +138,34 @@ impl OutputType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_shorthand(shorthand: &str) -> Option<Self> {
|
||||||
|
Some(match shorthand {
|
||||||
|
"asm" => OutputType::Assembly,
|
||||||
|
"llvm-ir" => OutputType::LlvmAssembly,
|
||||||
|
"mir" => OutputType::Mir,
|
||||||
|
"llvm-bc" => OutputType::Bitcode,
|
||||||
|
"obj" => OutputType::Object,
|
||||||
|
"metadata" => OutputType::Metadata,
|
||||||
|
"link" => OutputType::Exe,
|
||||||
|
"dep-info" => OutputType::DepInfo,
|
||||||
|
_ => return None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shorthands_display() -> String {
|
||||||
|
format!(
|
||||||
|
"`{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`",
|
||||||
|
OutputType::Bitcode.shorthand(),
|
||||||
|
OutputType::Assembly.shorthand(),
|
||||||
|
OutputType::LlvmAssembly.shorthand(),
|
||||||
|
OutputType::Mir.shorthand(),
|
||||||
|
OutputType::Object.shorthand(),
|
||||||
|
OutputType::Metadata.shorthand(),
|
||||||
|
OutputType::Exe.shorthand(),
|
||||||
|
OutputType::DepInfo.shorthand(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn extension(&self) -> &'static str {
|
pub fn extension(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
OutputType::Bitcode => "bc",
|
OutputType::Bitcode => "bc",
|
||||||
|
@ -1485,19 +1513,13 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
|
||||||
for list in matches.opt_strs("emit") {
|
for list in matches.opt_strs("emit") {
|
||||||
for output_type in list.split(',') {
|
for output_type in list.split(',') {
|
||||||
let mut parts = output_type.splitn(2, '=');
|
let mut parts = output_type.splitn(2, '=');
|
||||||
let output_type = match parts.next().unwrap() {
|
let shorthand = parts.next().unwrap();
|
||||||
"asm" => OutputType::Assembly,
|
let output_type = match OutputType::from_shorthand(shorthand) {
|
||||||
"llvm-ir" => OutputType::LlvmAssembly,
|
Some(output_type) => output_type,
|
||||||
"mir" => OutputType::Mir,
|
None => early_error(error_format, &format!(
|
||||||
"llvm-bc" => OutputType::Bitcode,
|
"unknown emission type: `{}` - expected one of: {}",
|
||||||
"obj" => OutputType::Object,
|
shorthand, OutputType::shorthands_display(),
|
||||||
"metadata" => OutputType::Metadata,
|
)),
|
||||||
"link" => OutputType::Exe,
|
|
||||||
"dep-info" => OutputType::DepInfo,
|
|
||||||
part => {
|
|
||||||
early_error(error_format, &format!("unknown emission type: `{}`",
|
|
||||||
part))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let path = parts.next().map(PathBuf::from);
|
let path = parts.next().map(PathBuf::from);
|
||||||
output_types.insert(output_type, path);
|
output_types.insert(output_type, path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue