Skip to content

rustc --crate-type flag should display valid values #70183

New issue

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

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

Already on GitHub? # to your account

Closed
disconnect3d opened this issue Mar 20, 2020 · 1 comment · Fixed by #134720
Closed

rustc --crate-type flag should display valid values #70183

disconnect3d opened this issue Mar 20, 2020 · 1 comment · Fixed by #134720
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@disconnect3d
Copy link

Hello,

When we provide wrong value for the --emit flag, we will get a list of valid values. This is not the case for --crate-type flag, which should also display valid values.

The --emit example:

$ cargo rustc -- --emit=asd
   Compiling tokio v0.2.13 (/host/tokio/tokio)
error: unknown emission type: `asd` - expected one of: `llvm-bc`, `asm`, `llvm-ir`, `mir`, `obj`, `metadata`, `link`, `dep-info`

The --crate-type example:

$ cargo rustc -- --crate-type=dynlib
   Compiling tokio v0.2.13 (/host/tokio/tokio)
error: unknown crate type: `dynlib`

error: could not compile `tokio`.

To learn more, run the command again with --verbose.

Versions:

$ cargo --version
cargo 1.41.0 (626f0f40e 2019-12-03)
r$ rustc --version
rustc 1.41.0 (5e1a79984 2020-01-27)

I have also tested this on rustc 1.42.0 and it is the same.

@disconnect3d disconnect3d added the C-bug Category: This is a bug. label Mar 20, 2020
@jonas-schievink jonas-schievink added A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Mar 20, 2020
@Centril Centril added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 21, 2020
@fmease fmease added A-CLI Area: Command-line interface (CLI) to the compiler E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. and removed A-frontend Area: Compiler frontend (errors, parsing and HIR) C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Dec 21, 2024
@fmease
Copy link
Member

fmease commented Dec 21, 2024

let new_part = match part {
"lib" => default_lib_output(),
"rlib" => CrateType::Rlib,
"staticlib" => CrateType::Staticlib,
"dylib" => CrateType::Dylib,
"cdylib" => CrateType::Cdylib,
"bin" => CrateType::Executable,
"proc-macro" => CrateType::ProcMacro,
_ => return Err(format!("unknown crate type: `{part}`")),
};

@fmease fmease added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Dec 21, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 25, 2024
…s, 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
jhpratt added a commit to jhpratt/rust that referenced this issue Jan 7, 2025
…ues, 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
jhpratt added a commit to jhpratt/rust that referenced this issue Mar 14, 2025
…ues, 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
@bors bors closed this as completed in f8842bd Mar 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 14, 2025
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants