parser will not give wrong help message for 'public'
This commit is contained in:
parent
38528d4dc0
commit
351acc87f5
7 changed files with 65 additions and 10 deletions
|
@ -22,7 +22,7 @@ use rustc_errors::{
|
|||
use rustc_errors::{pluralize, struct_span_err, Diagnostic, ErrorGuaranteed};
|
||||
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::symbol::{kw, sym, Ident};
|
||||
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
|
@ -977,15 +977,6 @@ impl<'a> Parser<'a> {
|
|||
let mut err = self.struct_span_err(self.token.span, &msg_exp);
|
||||
|
||||
if let TokenKind::Ident(symbol, _) = &self.prev_token.kind {
|
||||
if symbol.as_str() == "public" {
|
||||
err.span_suggestion_short(
|
||||
self.prev_token.span,
|
||||
"write `pub` instead of `public` to make the item public",
|
||||
"pub",
|
||||
appl,
|
||||
);
|
||||
}
|
||||
|
||||
if ["def", "fun", "func", "function"].contains(&symbol.as_str()) {
|
||||
err.span_suggestion_short(
|
||||
self.prev_token.span,
|
||||
|
@ -996,6 +987,19 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// `pub` may be used for an item or `pub(crate)`
|
||||
if self.prev_token.is_ident_named(sym::public)
|
||||
&& (self.token.can_begin_item()
|
||||
|| self.token.kind == TokenKind::OpenDelim(Delimiter::Parenthesis))
|
||||
{
|
||||
err.span_suggestion_short(
|
||||
self.prev_token.span,
|
||||
"write `pub` instead of `public` to make the item public",
|
||||
"pub",
|
||||
appl,
|
||||
);
|
||||
}
|
||||
|
||||
// Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens
|
||||
// there are unclosed angle brackets
|
||||
if self.unmatched_angle_bracket_count > 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue