-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Suggest valid crate type if invalid crate type is found #54173
Conversation
r? @davidtwco (rust_highfive has picked a reviewer for you, use r? to override) |
Should this be a machine applicable suggestion? I'm not really sure if the Levenshtein candidate is good enough in this case because |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I think Otherwise, this looks good to me. Assigning someone else to take another look who might be more familiar with this part of the code. r? @oli-obk (based on github's suggestions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes requested. r=me after changing.
--> $DIR/invalid-crate-type.rs:16:15 | ||
| | ||
LL | #![crate_type="statoclib"] | ||
| ^^^^^^^^^^^ help: did you mean: `staticlib` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that the span includes the "
s, but the suggestion doesn't, which would make applying this suggestion generate the code #![crate_type=staticlib]
, which is incorrect. Easiest solution is to include the quotes in the suggestion.
src/librustc_driver/driver.rs
Outdated
span, | ||
"invalid `crate_type` value", | ||
lint::builtin::BuiltinLintDiagnostics:: | ||
UnknownCrateTypes(span, "did you mean".to_string(), candidate.to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to
lint::builtin::BuiltinLintDiagnostics::UnknownCrateTypes(
span,
"did you mean".to_string(),
format!("\"{}\"", candidate),
);
src/librustc/lint/builtin.rs
Outdated
@@ -500,6 +501,9 @@ impl BuiltinLintDiagnostics { | |||
Applicability::MachineApplicable | |||
); | |||
} | |||
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => { | |||
db.span_suggestion(span, ¬e, sugg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in the prior discussion, use span_suggestion_with_applicability
. MaybeIncorrect
is always a safe bet to use, MachineApplicable
is not consistently used throughout the codebase. It sometimes means 100% certainty, while others it means "95% of the cases this error fires, this suggestion is correct". I'm ok with the overly restrictive reading of the meaning.
src/librustc_driver/driver.rs
Outdated
]; | ||
if let ast::MetaItemKind::NameValue(spanned) = a.meta().unwrap().node { | ||
let span = spanned.span; | ||
let lev_candidate = find_best_match_for_name(crate_types.iter(), &n.as_str(), None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is too long, reformat.
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.
8830670
to
7249a1b
Compare
I sort of did a rebase by accident instead of adding new commits, but it should be all good now 👍 |
@bors r+ rollup |
📌 Commit 7249a1b has been approved by |
…=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
Rollup of 8 pull requests Successful merges: - #53218 (Add a implementation of `From` for converting `&'a Option<T>` into `Option<&'a T>`) - #54024 (Fix compiling some rustc crates to wasm) - #54095 (Rename all mentions of `nil` to `unit`) - #54173 (Suggest valid crate type if invalid crate type is found) - #54194 (Remove println!() statement from HashMap unit test) - #54203 (Fix the stable release of os_str_str_ref_eq) - #54207 (re-mark the never docs as unstable) - #54210 (Update Cargo) Failed merges: r? @ghost
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 #53958