Skip to content

Commit

Permalink
fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRTA committed Jan 6, 2024
1 parent f443bbb commit e08baa0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
14 changes: 7 additions & 7 deletions crates/dtacheck/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ pub struct Token {
pub span: Range<usize>,
}

fn trim_delimiters(lex: &mut Lexer<TokenKind>) -> Option<String> {
let slice = lex.slice();
let len = slice.len();
slice[1..len - 1].parse().ok()
fn trim_delimiters(lexer: &mut Lexer<TokenKind>) -> Option<String> {
let slice = lexer.slice();
let length = slice.len();
slice[1..length - 1].parse().ok()
}

pub fn lex(data: &str) -> Vec<Token> {
let mut tokens: Vec<_> = TokenKind::lexer(data)
.spanned()
.map(|(tok, span)| match tok {
Ok(tok) => Token { kind: tok, span },
Err(_) => Token {
Err(()) => Token {
kind: TokenKind::Invalid,
span,
},
Expand All @@ -84,13 +84,13 @@ pub fn lex(data: &str) -> Vec<Token> {
tokens.push(Token {
kind: TokenKind::Eof,
span: 0..0,
})
});
} else {
let last = tokens.last().unwrap().span.end;
tokens.push(Token {
kind: TokenKind::Eof,
span: last..last,
})
});
}

tokens
Expand Down
19 changes: 8 additions & 11 deletions crates/dtacheck/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn lint_node(lints: &mut Vec<Box<dyn Lint>>, ast: &[Node], funcs: &Function) {
lint_node(lints, array, funcs);

let has_preprocessor_directive =
array.iter().any(|tok| tok.is_preproc());
array.iter().any(Node::is_preproc);

if !has_preprocessor_directive {
lint_fn_args(lints, array, node.span.clone(), funcs);
Expand Down Expand Up @@ -138,9 +138,9 @@ fn lint_fn_args(
let (func, depth) = funcs.lookup(stmt);
let name = generate_function_name(&stmt[..depth]);
if stmt.len() > func.max_args + depth {
lints.push(Box::new(FunctionArgLint::TooManyArgs(name, span)))
lints.push(Box::new(FunctionArgLint::TooManyArgs(name, span)));
} else if stmt.len() < func.min_args + depth {
lints.push(Box::new(FunctionArgLint::NotEnoughArgs(name, span)))
lints.push(Box::new(FunctionArgLint::NotEnoughArgs(name, span)));
}
}

Expand Down Expand Up @@ -181,34 +181,31 @@ pub fn lint_preprocs(lints: &mut Vec<Box<dyn Lint>>, tokens: &[Token]) {
let mut directive_stack: Vec<(Range<usize>, bool)> = Vec::new();
for token in tokens {
match token.kind {
TokenKind::IfNDef => {
directive_stack.push((token.span.clone(), false));
}
TokenKind::IfDef => {
TokenKind::IfNDef | TokenKind::IfDef => {
directive_stack.push((token.span.clone(), false));
}
TokenKind::Else => {
if let Some(entry) = directive_stack.pop() {
if entry.1 {
lints.push(Box::new(PreProcLint::Extra(
token.span.clone(),
)))
)));
}
directive_stack.push((token.span.clone(), true));
} else {
lints.push(Box::new(PreProcLint::Extra(token.span.clone())))
lints.push(Box::new(PreProcLint::Extra(token.span.clone())));
}
}
TokenKind::EndIf => {
if directive_stack.pop().is_none() {
lints.push(Box::new(PreProcLint::Extra(token.span.clone())))
lints.push(Box::new(PreProcLint::Extra(token.span.clone())));
}
}
_ => (),
}
}

for lint in directive_stack {
lints.push(Box::new(PreProcLint::Unmatched(lint.0)))
lints.push(Box::new(PreProcLint::Unmatched(lint.0)));
}
}
2 changes: 1 addition & 1 deletion crates/dtacheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn load_funcs(path: &Path) -> Function {
let max_args = tokens[len - 1].parse::<usize>().unwrap();
let min_args = tokens[len - 2].parse::<usize>().unwrap();

tree.insert(&tokens[0..len - 2], min_args, max_args)
tree.insert(&tokens[0..len - 2], min_args, max_args);
}

tree
Expand Down
3 changes: 1 addition & 2 deletions crates/dtacheck/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a> Parser<'a> {
}
}

return false;
false
}

fn parse_list(
Expand Down Expand Up @@ -277,7 +277,6 @@ pub enum NodeKind {
}

#[derive(Debug)]
#[allow(unused)]
pub struct Node {
pub kind: NodeKind,
pub span: Range<usize>,
Expand Down

0 comments on commit e08baa0

Please sign in to comment.