Skip to content

Commit e5fa9e3

Browse files
committed
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` ```
2 parents d053310 + c3ea358 commit e5fa9e3

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

src/librustc/session/config.rs

+35-13
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,34 @@ impl OutputType {
138138
}
139139
}
140140

141+
fn from_shorthand(shorthand: &str) -> Option<Self> {
142+
Some(match shorthand {
143+
"asm" => OutputType::Assembly,
144+
"llvm-ir" => OutputType::LlvmAssembly,
145+
"mir" => OutputType::Mir,
146+
"llvm-bc" => OutputType::Bitcode,
147+
"obj" => OutputType::Object,
148+
"metadata" => OutputType::Metadata,
149+
"link" => OutputType::Exe,
150+
"dep-info" => OutputType::DepInfo,
151+
_ => return None,
152+
})
153+
}
154+
155+
fn shorthands_display() -> String {
156+
format!(
157+
"`{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`, `{}`",
158+
OutputType::Bitcode.shorthand(),
159+
OutputType::Assembly.shorthand(),
160+
OutputType::LlvmAssembly.shorthand(),
161+
OutputType::Mir.shorthand(),
162+
OutputType::Object.shorthand(),
163+
OutputType::Metadata.shorthand(),
164+
OutputType::Exe.shorthand(),
165+
OutputType::DepInfo.shorthand(),
166+
)
167+
}
168+
141169
pub fn extension(&self) -> &'static str {
142170
match *self {
143171
OutputType::Bitcode => "bc",
@@ -1485,19 +1513,13 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
14851513
for list in matches.opt_strs("emit") {
14861514
for output_type in list.split(',') {
14871515
let mut parts = output_type.splitn(2, '=');
1488-
let output_type = match parts.next().unwrap() {
1489-
"asm" => OutputType::Assembly,
1490-
"llvm-ir" => OutputType::LlvmAssembly,
1491-
"mir" => OutputType::Mir,
1492-
"llvm-bc" => OutputType::Bitcode,
1493-
"obj" => OutputType::Object,
1494-
"metadata" => OutputType::Metadata,
1495-
"link" => OutputType::Exe,
1496-
"dep-info" => OutputType::DepInfo,
1497-
part => {
1498-
early_error(error_format, &format!("unknown emission type: `{}`",
1499-
part))
1500-
}
1516+
let shorthand = parts.next().unwrap();
1517+
let output_type = match OutputType::from_shorthand(shorthand) {
1518+
Some(output_type) => output_type,
1519+
None => early_error(error_format, &format!(
1520+
"unknown emission type: `{}` - expected one of: {}",
1521+
shorthand, OutputType::shorthands_display(),
1522+
)),
15011523
};
15021524
let path = parts.next().map(PathBuf::from);
15031525
output_types.insert(output_type, path);

0 commit comments

Comments
 (0)