Rollup merge of #134720 - malezjaa:feat/crate-type-valid-values, r=jieyouxu

Display valid crate types in error message for --crate-type flag

This PR improves the error message for the --crate-type flag. When an invalid crate type is provided, the compiler will now show a list of valid options.

### Before
![image](https://github.com/user-attachments/assets/4922e4e5-eeca-40cd-ac1c-1c6319a81aee)

### After
![image](https://github.com/user-attachments/assets/67ea1f35-aa41-4e4f-8691-47c273d0cff9)

I based the implementation on `OutputType::shorthands_display`

Closes #70183
This commit is contained in:
León Orell Valerian Liehr 2025-03-14 17:26:13 +01:00 committed by GitHub
commit f8842bd752
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 18 additions and 7 deletions

View file

@ -2709,7 +2709,12 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
"cdylib" => CrateType::Cdylib,
"bin" => CrateType::Executable,
"proc-macro" => CrateType::ProcMacro,
_ => return Err(format!("unknown crate type: `{part}`")),
_ => {
return Err(format!(
"unknown crate type: `{part}`, expected one of: \
`lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`",
));
}
};
if !crate_types.contains(&new_part) {
crate_types.push(new_part)