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  ### After  I based the implementation on `OutputType::shorthands_display` Closes #70183
This commit is contained in:
commit
f8842bd752
7 changed files with 18 additions and 7 deletions
|
@ -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)
|
||||
|
|
4
tests/ui/crate_type_flag.rs
Normal file
4
tests/ui/crate_type_flag.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
//@ compile-flags: --crate-type dynlib
|
||||
//@ error-pattern: unknown crate type: `dynlib`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
|
||||
|
||||
fn main() {}
|
2
tests/ui/crate_type_flag.stderr
Normal file
2
tests/ui/crate_type_flag.stderr
Normal file
|
@ -0,0 +1,2 @@
|
|||
error: unknown crate type: `dynlib`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
error: unknown crate type: ``
|
||||
error: unknown crate type: ``, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
error: unknown crate type: `proc_macro`
|
||||
error: unknown crate type: `proc_macro`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
|
||||
|
||||
|
|
|
@ -45,16 +45,16 @@
|
|||
// `proc-macro` is accepted, but `proc_macro` is not.
|
||||
//@ revisions: proc_underscore_macro
|
||||
//@[proc_underscore_macro] compile-flags: --crate-type=proc_macro
|
||||
//@[proc_underscore_macro] error-pattern: "unknown crate type: `proc_macro`"
|
||||
//@[proc_underscore_macro] error-pattern: unknown crate type: `proc_macro`
|
||||
|
||||
// Empty `--crate-type` not accepted.
|
||||
//@ revisions: empty_crate_type
|
||||
//@[empty_crate_type] compile-flags: --crate-type=
|
||||
//@[empty_crate_type] error-pattern: "unknown crate type: ``"
|
||||
//@[empty_crate_type] error-pattern: unknown crate type: ``
|
||||
|
||||
// Random unknown crate type. Also check that we can handle non-ASCII.
|
||||
//@ revisions: unknown
|
||||
//@[unknown] compile-flags: --crate-type=🤡
|
||||
//@[unknown] error-pattern: "unknown crate type: `🤡`"
|
||||
//@[unknown] error-pattern: unknown crate type: `🤡`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
error: unknown crate type: `🤡`
|
||||
error: unknown crate type: `🤡`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue