Emit suggestion when trying to write exclusive ranges as ..<
This commit is contained in:
parent
ca663b06c5
commit
6dd0772707
4 changed files with 117 additions and 7 deletions
|
@ -23,7 +23,7 @@ use crate::parser;
|
|||
use crate::parser::attr::InnerAttrPolicy;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, Delimiter, Lit, LitKind, TokenKind};
|
||||
use rustc_ast::token::{self, Delimiter, Lit, LitKind, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::AttrTokenTree;
|
||||
use rustc_ast::util::parser::AssocOp;
|
||||
use rustc_ast::{
|
||||
|
@ -448,12 +448,11 @@ impl<'a> Parser<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
let mut expected = edible
|
||||
self.expected_tokens.extend(edible.iter().chain(inedible).cloned().map(TokenType::Token));
|
||||
let mut expected = self
|
||||
.expected_tokens
|
||||
.iter()
|
||||
.chain(inedible)
|
||||
.cloned()
|
||||
.map(TokenType::Token)
|
||||
.chain(self.expected_tokens.iter().cloned())
|
||||
.filter(|token| {
|
||||
// Filter out suggestions that suggest the same token which was found and deemed incorrect.
|
||||
fn is_ident_eq_keyword(found: &TokenKind, expected: &TokenType) -> bool {
|
||||
|
@ -2927,6 +2926,22 @@ impl<'a> Parser<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Check for exclusive ranges written as `..<`
|
||||
pub(crate) fn maybe_err_dotdotlt_syntax(&self, maybe_lt: Token, mut err: PErr<'a>) -> PErr<'a> {
|
||||
if maybe_lt == token::Lt
|
||||
&& (self.expected_tokens.contains(&TokenType::Token(token::Gt))
|
||||
|| matches!(self.token.kind, token::Literal(..)))
|
||||
{
|
||||
err.span_suggestion(
|
||||
maybe_lt.span,
|
||||
"remove the `<` to write an exclusive range",
|
||||
"",
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
err
|
||||
}
|
||||
|
||||
pub fn is_diff_marker(&mut self, long_kind: &TokenKind, short_kind: &TokenKind) -> bool {
|
||||
(0..3).all(|i| self.look_ahead(i, |tok| tok == long_kind))
|
||||
&& self.look_ahead(3, |tok| tok == short_kind)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue