From 551748fb702bbb1db6454ee9925272be0cedf197 Mon Sep 17 00:00:00 2001 From: f01dab1e Date: Fri, 1 Dec 2023 08:57:14 +0000 Subject: [PATCH] chore: make clippy happy --- tooling/doc_generator/src/getters.rs | 52 +++++++++---------- tooling/doc_generator/src/pages_generation.rs | 8 +-- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/tooling/doc_generator/src/getters.rs b/tooling/doc_generator/src/getters.rs index e7a1ccb634b..03688636c5d 100644 --- a/tooling/doc_generator/src/getters.rs +++ b/tooling/doc_generator/src/getters.rs @@ -122,7 +122,7 @@ pub(crate) fn fn_signature(tokens: &[Token], index: usize) -> String { } _ => { res.push_str(&tokens[i].to_string()); - res.push_str(" "); + res.push(' '); i += 1; } }; @@ -144,16 +144,16 @@ pub(crate) fn struct_signature(tokens: &[Token], index: usize) -> String { loop { match &tokens[i] { Token::LeftBrace => { - res.push_str("{"); - res.push_str("\n"); + res.push('{'); + res.push('\n'); loop { match tokens[i] { Token::RightBrace => { if is_private { res.push_str("/* private fields */"); } - res.push_str("\n"); - res.push_str("}"); + res.push('\n'); + res.push('}'); break; } Token::Keyword(Keyword::Pub) => { @@ -162,7 +162,7 @@ pub(crate) fn struct_signature(tokens: &[Token], index: usize) -> String { match tokens[i] { Token::Comma => { if tokens[i + 1] == Token::RightBrace { - res.push_str(","); + res.push(','); } else { res.push_str(",\n"); } @@ -174,7 +174,7 @@ pub(crate) fn struct_signature(tokens: &[Token], index: usize) -> String { } _ => { res.push_str(&tokens[i].to_string()); - res.push_str(" "); + res.push(' '); i += 1; } } @@ -189,7 +189,7 @@ pub(crate) fn struct_signature(tokens: &[Token], index: usize) -> String { } _ => { res.push_str(&tokens[i].to_string()); - res.push_str(" "); + res.push(' '); i += 1; } }; @@ -214,12 +214,12 @@ pub(crate) fn trait_info(tokens: &[Token], index: usize) -> (String, Vec { - sign.push_str("{"); - sign.push_str("\n"); + sign.push('{'); + sign.push('\n'); loop { match tokens[i + 1] { Token::RightBrace => { - sign.push_str("}"); + sign.push('}'); break; } Token::Keyword(Keyword::Fn) => { @@ -229,8 +229,8 @@ pub(crate) fn trait_info(tokens: &[Token], index: usize) -> (String, Vec (String, Vec { @@ -254,7 +254,7 @@ pub(crate) fn trait_info(tokens: &[Token], index: usize) -> (String, Vec (String, Vec { sign.push_str(&tokens[i + 1].to_string()); - sign.push_str(" "); + sign.push(' '); i += 1; } } @@ -287,7 +287,7 @@ pub(crate) fn trait_info(tokens: &[Token], index: usize) -> (String, Vec { sign.push_str(&tokens[i + 1].to_string()); - sign.push_str(" "); + sign.push(' '); i += 1; } }; @@ -307,7 +307,7 @@ pub(crate) fn additional_doc(tokens: &[Token], index: usize) -> String { if index == 0 { return "".to_string(); } - let res = match &tokens[index - 1] { + match &tokens[index - 1] { Token::LineComment(dc, Some(DocStyle::Inner)) | Token::BlockComment(dc, Some(DocStyle::Inner)) => { let mut res = dc.to_string(); @@ -352,8 +352,7 @@ pub(crate) fn additional_doc(tokens: &[Token], index: usize) -> String { } res } - }; - res + } } /// Extracts documentation comments for a code element from a list of tokens. @@ -366,7 +365,7 @@ pub(crate) fn doc(tokens: &[Token], index: usize) -> String { if index == 0 { return String::new(); } - let res = match &tokens[index - 1] { + match &tokens[index - 1] { Token::LineComment(dc, _) | Token::BlockComment(dc, _) => { let mut res = dc.to_string(); let mut doc_end = true; @@ -410,8 +409,7 @@ pub(crate) fn doc(tokens: &[Token], index: usize) -> String { } res } - }; - res + } } /// Extracts an outer documentation comment associated with a code element from a list of tokens. @@ -495,11 +493,9 @@ pub(crate) fn get_text(input_file: &str) -> Result, crate::DocErro let file = File::open(input_file).map_err(|_| crate::DocError::FileEditError)?; let reader = BufReader::new(file); let mut code = Vec::new(); - let mut i = 0; - for line in reader.lines() { - i += 1; - code.push(CodeLine { number: i, text: line.map_err(|_| crate::DocError::FileEditError)? }); + for (line, number) in reader.lines().zip(0u32..) { + code.push(CodeLine { number, text: line.map_err(|_| crate::DocError::FileEditError)? }); } Ok(code) diff --git a/tooling/doc_generator/src/pages_generation.rs b/tooling/doc_generator/src/pages_generation.rs index 206a8759e18..51b4481731f 100644 --- a/tooling/doc_generator/src/pages_generation.rs +++ b/tooling/doc_generator/src/pages_generation.rs @@ -118,7 +118,7 @@ impl Implementation { right_impl = true; } signature.push_str(&tokens[i].to_string()); - signature.push_str(" "); + signature.push(' '); i += 1; } Token::LeftBrace => { @@ -138,8 +138,8 @@ impl Implementation { continue; } }; - let doc = doc(&tokens, i); - let sign = fn_signature(&tokens, i); + let doc = doc(tokens, i); + let sign = fn_signature(tokens, i); functions.push(Function { name, @@ -175,7 +175,7 @@ impl Implementation { } _ => { signature.push_str(&tokens[i].to_string()); - signature.push_str(" "); + signature.push(' '); i += 1; } }