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

Invalid crate type should helpfully suggest valid crate type #53958

Closed
Havvy opened this issue Sep 5, 2018 · 1 comment
Closed

Invalid crate type should helpfully suggest valid crate type #53958

Havvy opened this issue Sep 5, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@Havvy
Copy link
Contributor

Havvy commented Sep 5, 2018

Errornous code: Yes, it's only a single line

#![crate_type = "proc_macro"]

Current output:

   Compiling playground v0.0.1 (file:///playground)
error: invalid `crate_type` value
 --> src/lib.rs:1:1
  |
1 | #![crate_type = "proc_macro"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[deny(unknown_crate_types)] on by default

error: aborting due to previous error

error: Could not compile `playground`.

Expected:

   Compiling playground v0.0.1 (file:///playground)
error: invalid `crate_type` value
 --> src/lib.rs:1:1
  |
1 | #![crate_type = "proc_macro"]
  |                 ^^^^^^^^^^^^ did you mean "proc-macro"?
  |
  = note: #[deny(unknown_crate_types)] on by default

error: aborting due to previous error

error: Could not compile `playground`.

The change here is that the error is on the value of the attribute and it asks the "did you mean" question that you get when you mistype a variable.

@Havvy Havvy added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 5, 2018
@phansch
Copy link
Member

phansch commented Sep 5, 2018

I would like to work on this.

From a first look, I would re-use

pub fn find_best_match_for_name<'a, T>(iter_names: T,

somewhere around here:

session.buffer_lint(
lint::builtin::UNKNOWN_CRATE_TYPES,
ast::CRATE_NODE_ID,
a.span,
"invalid `crate_type` value",
);

kennytm added a commit to kennytm/rust that referenced this issue Sep 14, 2018
…=estebank

Suggest valid crate type if invalid crate type is found

This adds a suggestion to the `invalid_crate_types` lint.

The suggestion is based on the Levenshtein distance to existing crate
types. If no suggestion is found it will show the lint without any
suggestions.

Closes rust-lang#53958
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants