From a533045ea403e2c8851c16db587d53917e6880c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Tue, 20 Feb 2024 09:40:55 +0100 Subject: [PATCH 1/2] chore(docs): cleanup examples Apply nightly clippy fixes --- examples/json.rs | 8 ++++---- examples/json_borrowed.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/json.rs b/examples/json.rs index e72e9dd1..dd9e440b 100644 --- a/examples/json.rs +++ b/examples/json.rs @@ -85,7 +85,7 @@ enum Value { /* ANCHOR: value */ /// Parse a token stream into a JSON value. -fn parse_value<'source>(lexer: &mut Lexer<'source, Token>) -> Result { +fn parse_value(lexer: &mut Lexer<'_, Token>) -> Result { if let Some(token) = lexer.next() { match token { Ok(Token::Bool(b)) => Ok(Value::Bool(b)), @@ -110,7 +110,7 @@ fn parse_value<'source>(lexer: &mut Lexer<'source, Token>) -> Result { /// a valid terminator is found. /// /// > NOTE: we assume '[' was consumed. -fn parse_array<'source>(lexer: &mut Lexer<'source, Token>) -> Result { +fn parse_array(lexer: &mut Lexer<'_, Token>) -> Result { let mut array = Vec::new(); let span = lexer.span(); let mut awaits_comma = false; @@ -164,7 +164,7 @@ fn parse_array<'source>(lexer: &mut Lexer<'source, Token>) -> Result { /// a valid terminator is found. /// /// > NOTE: we assume '{' was consumed. -fn parse_object<'source>(lexer: &mut Lexer<'source, Token>) -> Result { +fn parse_object(lexer: &mut Lexer<'_, Token>) -> Result { let mut map = HashMap::new(); let span = lexer.span(); let mut awaits_comma = false; @@ -217,7 +217,7 @@ fn main() { let a = colors.next(); Report::build(ReportKind::Error, &filename, 12) - .with_message(format!("Invalid JSON")) + .with_message("Invalid JSON".to_string()) .with_label( Label::new((&filename, span)) .with_message(msg) diff --git a/examples/json_borrowed.rs b/examples/json_borrowed.rs index 256774dd..c1ec104f 100644 --- a/examples/json_borrowed.rs +++ b/examples/json_borrowed.rs @@ -213,7 +213,7 @@ fn main() { let a = colors.next(); Report::build(ReportKind::Error, &filename, 12) - .with_message(format!("Invalid JSON")) + .with_message("Invalid JSON".to_string()) .with_label( Label::new((&filename, span)) .with_message(msg) From d95849c3e783e0598b5caf947bdc43f7ea8b3564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Tue, 20 Feb 2024 09:44:42 +0100 Subject: [PATCH 2/2] chore(docs): simplify match logic --- examples/extras.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/extras.rs b/examples/extras.rs index 4e89c2e3..eb1bdb9a 100644 --- a/examples/extras.rs +++ b/examples/extras.rs @@ -65,11 +65,8 @@ fn main() { let mut lex = Token::lexer(src.as_str()); while let Some(token) = lex.next() { - match token { - Ok(Token::Word((line, column))) => { - println!("Word '{}' found at ({}, {})", lex.slice(), line, column); - } - _ => (), + if let Ok(Token::Word((line, column))) = token { + println!("Word '{}' found at ({}, {})", lex.slice(), line, column); } } }