Fix even more clippy warnings
This commit is contained in:
parent
bfecb18771
commit
57c6ed0c07
53 changed files with 276 additions and 520 deletions
|
@ -606,7 +606,7 @@ fn prepend_attrs(
|
|||
) -> Option<tokenstream::TokenStream> {
|
||||
let tokens = tokens?.clone().into_token_stream();
|
||||
if attrs.is_empty() {
|
||||
return Some(tokens.clone());
|
||||
return Some(tokens);
|
||||
}
|
||||
let mut builder = tokenstream::TokenStreamBuilder::new();
|
||||
for attr in attrs {
|
||||
|
@ -622,6 +622,6 @@ fn prepend_attrs(
|
|||
.into_token_stream(),
|
||||
);
|
||||
}
|
||||
builder.push(tokens.clone());
|
||||
builder.push(tokens);
|
||||
Some(builder.build())
|
||||
}
|
||||
|
|
|
@ -1359,11 +1359,7 @@ impl<'a> Parser<'a> {
|
|||
(self.token == token::Lt && // `foo:<bar`, likely a typoed turbofish.
|
||||
self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident()))
|
||||
|| self.token.is_ident() &&
|
||||
match node {
|
||||
// `foo::` → `foo:` or `foo.bar::` → `foo.bar:`
|
||||
ast::ExprKind::Path(..) | ast::ExprKind::Field(..) => true,
|
||||
_ => false,
|
||||
} &&
|
||||
matches!(node, ast::ExprKind::Path(..) | ast::ExprKind::Field(..)) &&
|
||||
!self.token.is_reserved_ident() && // v `foo:bar(baz)`
|
||||
self.look_ahead(1, |t| t == &token::OpenDelim(token::Paren))
|
||||
|| self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace)) // `foo:bar {`
|
||||
|
|
|
@ -376,21 +376,19 @@ impl<'a> Parser<'a> {
|
|||
format!(" {} ", kw),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else if let Ok(snippet) = self.span_to_snippet(ident_sp) {
|
||||
err.span_suggestion(
|
||||
full_sp,
|
||||
"if you meant to call a macro, try",
|
||||
format!("{}!", snippet),
|
||||
// this is the `ambiguous` conditional branch
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
if let Ok(snippet) = self.span_to_snippet(ident_sp) {
|
||||
err.span_suggestion(
|
||||
full_sp,
|
||||
"if you meant to call a macro, try",
|
||||
format!("{}!", snippet),
|
||||
// this is the `ambiguous` conditional branch
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.help(
|
||||
"if you meant to call a macro, remove the `pub` \
|
||||
and add a trailing `!` after the identifier",
|
||||
);
|
||||
}
|
||||
err.help(
|
||||
"if you meant to call a macro, remove the `pub` \
|
||||
and add a trailing `!` after the identifier",
|
||||
);
|
||||
}
|
||||
Err(err)
|
||||
} else if self.look_ahead(1, |t| *t == token::Lt) {
|
||||
|
@ -982,10 +980,7 @@ impl<'a> Parser<'a> {
|
|||
if token.is_keyword(kw::Move) {
|
||||
return true;
|
||||
}
|
||||
match token.kind {
|
||||
token::BinOp(token::Or) | token::OrOr => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(token.kind, token::BinOp(token::Or) | token::OrOr)
|
||||
})
|
||||
} else {
|
||||
false
|
||||
|
|
|
@ -38,16 +38,13 @@ impl<'a> Parser<'a> {
|
|||
},
|
||||
NonterminalKind::Block => match token.kind {
|
||||
token::OpenDelim(token::Brace) => true,
|
||||
token::Interpolated(ref nt) => match **nt {
|
||||
token::NtItem(_)
|
||||
token::Interpolated(ref nt) => !matches!(**nt, token::NtItem(_)
|
||||
| token::NtPat(_)
|
||||
| token::NtTy(_)
|
||||
| token::NtIdent(..)
|
||||
| token::NtMeta(_)
|
||||
| token::NtPath(_)
|
||||
| token::NtVis(_) => false, // none of these may start with '{'.
|
||||
_ => true,
|
||||
},
|
||||
| token::NtVis(_)),
|
||||
_ => false,
|
||||
},
|
||||
NonterminalKind::Path | NonterminalKind::Meta => match token.kind {
|
||||
|
@ -76,17 +73,14 @@ impl<'a> Parser<'a> {
|
|||
},
|
||||
NonterminalKind::Lifetime => match token.kind {
|
||||
token::Lifetime(_) => true,
|
||||
token::Interpolated(ref nt) => match **nt {
|
||||
token::NtLifetime(_) | token::NtTT(_) => true,
|
||||
_ => false,
|
||||
},
|
||||
token::Interpolated(ref nt) => {
|
||||
matches!(**nt, token::NtLifetime(_) | token::NtTT(_))
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
NonterminalKind::TT | NonterminalKind::Item | NonterminalKind::Stmt => match token.kind
|
||||
{
|
||||
token::CloseDelim(_) => false,
|
||||
_ => true,
|
||||
},
|
||||
NonterminalKind::TT | NonterminalKind::Item | NonterminalKind::Stmt => {
|
||||
!matches!(token.kind, token::CloseDelim(_))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -149,8 +149,10 @@ impl<'a> Parser<'a> {
|
|||
/// Note that there are more tokens such as `@` for which we know that the `|`
|
||||
/// is an illegal parse. However, the user's intent is less clear in that case.
|
||||
fn recover_trailing_vert(&mut self, lo: Option<Span>) -> bool {
|
||||
let is_end_ahead = self.look_ahead(1, |token| match &token.uninterpolate().kind {
|
||||
token::FatArrow // e.g. `a | => 0,`.
|
||||
let is_end_ahead = self.look_ahead(1, |token| {
|
||||
matches!(
|
||||
&token.uninterpolate().kind,
|
||||
token::FatArrow // e.g. `a | => 0,`.
|
||||
| token::Ident(kw::If, false) // e.g. `a | if expr`.
|
||||
| token::Eq // e.g. `let a | = 0`.
|
||||
| token::Semi // e.g. `let a |;`.
|
||||
|
@ -158,8 +160,8 @@ impl<'a> Parser<'a> {
|
|||
| token::Comma // e.g. `let (a |,)`.
|
||||
| token::CloseDelim(token::Bracket) // e.g. `let [a | ]`.
|
||||
| token::CloseDelim(token::Paren) // e.g. `let (a | )`.
|
||||
| token::CloseDelim(token::Brace) => true, // e.g. `let A { f: a | }`.
|
||||
_ => false,
|
||||
| token::CloseDelim(token::Brace)
|
||||
)
|
||||
});
|
||||
match (is_end_ahead, &self.token.kind) {
|
||||
(true, token::BinOp(token::Or) | token::OrOr) => {
|
||||
|
@ -766,14 +768,11 @@ impl<'a> Parser<'a> {
|
|||
&& !self.token.is_path_segment_keyword() // Avoid e.g. `Self` as it is a path.
|
||||
// Avoid `in`. Due to recovery in the list parser this messes with `for ( $pat in $expr )`.
|
||||
&& !self.token.is_keyword(kw::In)
|
||||
&& self.look_ahead(1, |t| match t.kind { // Try to do something more complex?
|
||||
token::OpenDelim(token::Paren) // A tuple struct pattern.
|
||||
&& self.look_ahead(1, |t| !matches!(t.kind, token::OpenDelim(token::Paren) // A tuple struct pattern.
|
||||
| token::OpenDelim(token::Brace) // A struct pattern.
|
||||
| token::DotDotDot | token::DotDotEq | token::DotDot // A range pattern.
|
||||
| token::ModSep // A tuple / struct variant pattern.
|
||||
| token::Not => false, // A macro expanding to a pattern.
|
||||
_ => true,
|
||||
})
|
||||
| token::Not))
|
||||
}
|
||||
|
||||
/// Parses `ident` or `ident @ pat`.
|
||||
|
|
|
@ -187,12 +187,14 @@ impl<'a> Parser<'a> {
|
|||
pub(super) fn parse_path_segment(&mut self, style: PathStyle) -> PResult<'a, PathSegment> {
|
||||
let ident = self.parse_path_segment_ident()?;
|
||||
|
||||
let is_args_start = |token: &Token| match token.kind {
|
||||
token::Lt
|
||||
| token::BinOp(token::Shl)
|
||||
| token::OpenDelim(token::Paren)
|
||||
| token::LArrow => true,
|
||||
_ => false,
|
||||
let is_args_start = |token: &Token| {
|
||||
matches!(
|
||||
token.kind,
|
||||
token::Lt
|
||||
| token::BinOp(token::Shl)
|
||||
| token::OpenDelim(token::Paren)
|
||||
| token::LArrow
|
||||
)
|
||||
};
|
||||
let check_args_start = |this: &mut Self| {
|
||||
this.expected_tokens.extend_from_slice(&[
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue