mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #154561 - FranciscoTGouveia:typo-detection-after-visibility, r=TaKO8Ki
Suggest similar keyword when visibility is not followed by an item Fixes rust-lang/rust#153353. I would appreciate feedback on the following: - I inlined [`find_similar_kw`](https://github.com/rust-lang/rust/blob/cd14b73b4a41542d921f59e362a5b5005fa4f2ef/compiler/rustc_parse/src/parser/diagnostics.rs#L218-L224) instead of changing its visibility to `pub(super)`. I am happy to switch if it is preferred; - I didn't add a comment to the new test. Although the rustc-dev-guide specifies that a [comment should be added](https://rustc-dev-guide.rust-lang.org/tests/adding.html#comment-explaining-what-the-test-is-about) to every new test, this is not common in `tests/ui/parser/misspelled_keywords/` and the test seems self-explanatory. Let me know if you would like me to add a comment; Thank you in advance for your time and input!
This commit is contained in:
@@ -192,7 +192,22 @@ pub(super) fn parse_item_common(
|
||||
|
||||
// At this point, we have failed to parse an item.
|
||||
if !matches!(vis.kind, VisibilityKind::Inherited) {
|
||||
this.dcx().emit_err(errors::VisibilityNotFollowedByItem { span: vis.span, vis });
|
||||
let mut err = this
|
||||
.dcx()
|
||||
.create_err(errors::VisibilityNotFollowedByItem { span: vis.span, vis });
|
||||
if let Some((ident, _)) = this.token.ident()
|
||||
&& !ident.is_used_keyword()
|
||||
&& let Some((similar_kw, is_incorrect_case)) = ident
|
||||
.name
|
||||
.find_similar(&rustc_span::symbol::used_keywords(|| ident.span.edition()))
|
||||
{
|
||||
err.subdiagnostic(errors::MisspelledKw {
|
||||
similar_kw: similar_kw.to_string(),
|
||||
span: ident.span,
|
||||
is_incorrect_case,
|
||||
});
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
|
||||
if let Defaultness::Default(span) = def {
|
||||
|
||||
Reference in New Issue
Block a user