Skip to content

Commit 1586c0b

Browse files
authored
Unrolled build for rust-lang#134720
Rollup merge of rust-lang#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 rust-lang#70183
2 parents cb50d4d + 90bf2b1 commit 1586c0b

7 files changed

+18
-7
lines changed

compiler/rustc_session/src/config.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2709,7 +2709,12 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
27092709
"cdylib" => CrateType::Cdylib,
27102710
"bin" => CrateType::Executable,
27112711
"proc-macro" => CrateType::ProcMacro,
2712-
_ => return Err(format!("unknown crate type: `{part}`")),
2712+
_ => {
2713+
return Err(format!(
2714+
"unknown crate type: `{part}`, expected one of: \
2715+
`lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`",
2716+
));
2717+
}
27132718
};
27142719
if !crate_types.contains(&new_part) {
27152720
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: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `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: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
2+
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: unknown crate type: ``
1+
error: unknown crate type: ``, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
22

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

tests/ui/invalid-compile-flags/crate-type-flag.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@
4545
// `proc-macro` is accepted, but `proc_macro` is not.
4646
//@ revisions: proc_underscore_macro
4747
//@[proc_underscore_macro] compile-flags: --crate-type=proc_macro
48-
//@[proc_underscore_macro] error-pattern: "unknown crate type: `proc_macro`"
48+
//@[proc_underscore_macro] error-pattern: unknown crate type: `proc_macro`
4949

5050
// Empty `--crate-type` not accepted.
5151
//@ revisions: empty_crate_type
5252
//@[empty_crate_type] compile-flags: --crate-type=
53-
//@[empty_crate_type] error-pattern: "unknown crate type: ``"
53+
//@[empty_crate_type] error-pattern: unknown crate type: ``
5454

5555
// Random unknown crate type. Also check that we can handle non-ASCII.
5656
//@ revisions: unknown
5757
//@[unknown] compile-flags: --crate-type=🤡
58-
//@[unknown] error-pattern: "unknown crate type: `🤡`"
58+
//@[unknown] error-pattern: unknown crate type: `🤡`
5959

6060
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: unknown crate type: `🤡`
1+
error: unknown crate type: `🤡`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`
22

0 commit comments

Comments
 (0)