Apply a few clippy suggestions

This commit is contained in:
Clemens Wasser 2021-06-03 11:45:10 +02:00
parent e8e14e1b13
commit 3c6dc0f89d
4 changed files with 121 additions and 47 deletions

View file

@ -252,13 +252,11 @@ fn closure_expr(p: &mut Parser) -> CompletedMarker {
// test lambda_ret_block
// fn main() { || -> i32 { 92 }(); }
block_expr(p);
} else {
if p.at_ts(EXPR_FIRST) {
} else if p.at_ts(EXPR_FIRST) {
expr(p);
} else {
p.error("expected expression");
}
}
m.complete(p, CLOSURE_EXPR)
}

View file

@ -260,33 +260,116 @@ pub enum SyntaxKind {
use self::SyntaxKind::*;
impl SyntaxKind {
pub fn is_keyword(self) -> bool {
match self {
AS_KW | ASYNC_KW | AWAIT_KW | BOX_KW | BREAK_KW | CONST_KW | CONTINUE_KW | CRATE_KW
| DYN_KW | ELSE_KW | ENUM_KW | EXTERN_KW | FALSE_KW | FN_KW | FOR_KW | IF_KW
| IMPL_KW | IN_KW | LET_KW | LOOP_KW | MACRO_KW | MATCH_KW | MOD_KW | MOVE_KW
| MUT_KW | PUB_KW | REF_KW | RETURN_KW | SELF_KW | STATIC_KW | STRUCT_KW | SUPER_KW
| TRAIT_KW | TRUE_KW | TRY_KW | TYPE_KW | UNSAFE_KW | USE_KW | WHERE_KW | WHILE_KW
| YIELD_KW | AUTO_KW | DEFAULT_KW | EXISTENTIAL_KW | UNION_KW | RAW_KW
| MACRO_RULES_KW => true,
_ => false,
}
matches!(
self,
AS_KW
| ASYNC_KW
| AWAIT_KW
| BOX_KW
| BREAK_KW
| CONST_KW
| CONTINUE_KW
| CRATE_KW
| DYN_KW
| ELSE_KW
| ENUM_KW
| EXTERN_KW
| FALSE_KW
| FN_KW
| FOR_KW
| IF_KW
| IMPL_KW
| IN_KW
| LET_KW
| LOOP_KW
| MACRO_KW
| MATCH_KW
| MOD_KW
| MOVE_KW
| MUT_KW
| PUB_KW
| REF_KW
| RETURN_KW
| SELF_KW
| STATIC_KW
| STRUCT_KW
| SUPER_KW
| TRAIT_KW
| TRUE_KW
| TRY_KW
| TYPE_KW
| UNSAFE_KW
| USE_KW
| WHERE_KW
| WHILE_KW
| YIELD_KW
| AUTO_KW
| DEFAULT_KW
| EXISTENTIAL_KW
| UNION_KW
| RAW_KW
| MACRO_RULES_KW
)
}
pub fn is_punct(self) -> bool {
match self {
SEMICOLON | COMMA | L_PAREN | R_PAREN | L_CURLY | R_CURLY | L_BRACK | R_BRACK
| L_ANGLE | R_ANGLE | AT | POUND | TILDE | QUESTION | DOLLAR | AMP | PIPE | PLUS
| STAR | SLASH | CARET | PERCENT | UNDERSCORE | DOT | DOT2 | DOT3 | DOT2EQ | COLON
| COLON2 | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | THIN_ARROW | LTEQ | GTEQ
| PLUSEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ | SLASHEQ | STAREQ | PERCENTEQ | AMP2
| PIPE2 | SHL | SHR | SHLEQ | SHREQ => true,
_ => false,
}
matches!(
self,
SEMICOLON
| COMMA
| L_PAREN
| R_PAREN
| L_CURLY
| R_CURLY
| L_BRACK
| R_BRACK
| L_ANGLE
| R_ANGLE
| AT
| POUND
| TILDE
| QUESTION
| DOLLAR
| AMP
| PIPE
| PLUS
| STAR
| SLASH
| CARET
| PERCENT
| UNDERSCORE
| DOT
| DOT2
| DOT3
| DOT2EQ
| COLON
| COLON2
| EQ
| EQ2
| FAT_ARROW
| BANG
| NEQ
| MINUS
| THIN_ARROW
| LTEQ
| GTEQ
| PLUSEQ
| MINUSEQ
| PIPEEQ
| AMPEQ
| CARETEQ
| SLASHEQ
| STAREQ
| PERCENTEQ
| AMP2
| PIPE2
| SHL
| SHR
| SHLEQ
| SHREQ
)
}
pub fn is_literal(self) -> bool {
match self {
INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE | STRING | BYTE_STRING => true,
_ => false,
}
matches!(self, INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE | STRING | BYTE_STRING)
}
pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
let kw = match ident {

View file

@ -238,14 +238,9 @@ fn extract_line_annotations(mut line: &str) -> Vec<LineAnnotation> {
let mut res = Vec::new();
let mut offset: TextSize = 0.into();
let marker: fn(char) -> bool = if line.contains('^') { |c| c == '^' } else { |c| c == '|' };
loop {
match line.find(marker) {
Some(idx) => {
while let Some(idx) = line.find(marker) {
offset += TextSize::try_from(idx).unwrap();
line = &line[idx..];
}
None => break,
};
let mut len = line.chars().take_while(|&it| it == '^').count();
let mut continuation = false;

View file

@ -94,8 +94,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
support::children(&self.syntax)
}
}
} else {
if let Some(token_kind) = field.token_kind() {
} else if let Some(token_kind) = field.token_kind() {
quote! {
pub fn #method_name(&self) -> Option<#ty> {
support::token(&self.syntax, #token_kind)
@ -108,7 +107,6 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
}
}
}
}
});
(
quote! {