1
Fork 0

Suggest removing unnecessary prefix let in patterns

This commit is contained in:
Michael Goulet 2022-09-03 05:39:46 +00:00
parent 8c6ce6b91b
commit 91674cc56c
6 changed files with 74 additions and 1 deletions

View file

@ -705,6 +705,14 @@ pub(crate) struct LeftArrowOperator {
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[diag(parser::remove_let)]
pub(crate) struct RemoveLet {
#[primary_span]
#[suggestion(applicability = "machine-applicable", code = "")]
pub span: Span,
}
// SnapshotParser is used to create a snapshot of the parser
// without causing duplicate errors being emitted when the `Parser`
// is dropped.

View file

@ -1,4 +1,5 @@
use super::{ForceCollect, Parser, PathStyle, TrailingToken};
use crate::parser::diagnostics::RemoveLet;
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
use rustc_ast::ptr::P;
@ -320,7 +321,13 @@ impl<'a> Parser<'a> {
maybe_recover_from_interpolated_ty_qpath!(self, true);
maybe_whole!(self, NtPat, |x| x);
let lo = self.token.span;
let mut lo = self.token.span;
if self.token.is_keyword(kw::Let) && self.look_ahead(1, |tok| tok.can_begin_pattern()) {
self.bump();
self.sess.emit_err(RemoveLet { span: lo });
lo = self.token.span;
}
let pat = if self.check(&token::BinOp(token::And)) || self.token.kind == token::AndAnd {
self.parse_pat_deref(expected)?