Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/crate_type_flag.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/ui/crate_type_flag.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: unknown crate type: `dynlib`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`

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

Original file line number Diff line number Diff line change
@@ -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`

6 changes: 3 additions & 3 deletions tests/ui/invalid-compile-flags/crate-type-flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
error: unknown crate type: `🤡`
error: unknown crate type: `🤡`, expected one of: `lib`, `rlib`, `staticlib`, `dylib`, `cdylib`, `bin`, `proc-macro`

Loading