From 3607eb8124d0ff7c5e6a5b453ecad85f24726cc4 Mon Sep 17 00:00:00 2001 From: Ilya Bylich Date: Fri, 29 Oct 2021 00:29:23 +0300 Subject: [PATCH] fix clippy warnings --- examples/real/compare_with_mri.rs | 8 ++++---- examples/real/helpers/input_files.rs | 2 +- examples/real/helpers/parse.rs | 2 +- examples/real/helpers/printer.rs | 6 +++--- examples/real/helpers/profiler.rs | 6 +++--- examples/real/helpers/token_list.rs | 2 +- examples/real/parse.rs | 6 +++--- examples/real/tokenize.rs | 3 +-- 8 files changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/real/compare_with_mri.rs b/examples/real/compare_with_mri.rs index ff5db5f2..d340485c 100644 --- a/examples/real/compare_with_mri.rs +++ b/examples/real/compare_with_mri.rs @@ -32,13 +32,13 @@ fn compare(file: InputFile) -> Output { // emits multibyte UTF chars as separate tSTRING_CONTENT chunks } else { return Output::Skip { - reason: format!("has multibyte UTF-8 chars"), + reason: "has multibyte UTF-8 chars".to_string(), }; } } Err(_) => { return Output::Skip { - reason: format!("has invalid utf-8 source"), + reason: "has invalid utf-8 source".to_string(), }; } } @@ -50,7 +50,7 @@ fn compare(file: InputFile) -> Output { if expected.status.code() != Some(0) { // invalid file, even popular gems have them return Output::Skip { - reason: format!("contains invalid Ruby code"), + reason: "contains invalid Ruby code".to_string(), }; } @@ -111,7 +111,7 @@ pub(crate) fn main() -> Result<(), Box> { let files = args .pattern .map(|pattern| InputFiles::new_pattern(&pattern)) - .unwrap_or_else(|| InputFiles::empty()); + .unwrap_or_else(InputFiles::empty); let mut warnings = vec![]; let mut errors = vec![]; diff --git a/examples/real/helpers/input_files.rs b/examples/real/helpers/input_files.rs index 73c3cb77..b091133d 100644 --- a/examples/real/helpers/input_files.rs +++ b/examples/real/helpers/input_files.rs @@ -25,7 +25,7 @@ impl InputFiles { } pub(crate) fn new_pattern(pattern: &str) -> Self { - let files: Vec = glob::glob(&pattern) + let files: Vec = glob::glob(pattern) .expect("invalid glob pattern") .map(|f| f.unwrap().to_str().unwrap().to_string()) .map(|filepath| InputFile { diff --git a/examples/real/helpers/parse.rs b/examples/real/helpers/parse.rs index 5af66344..931a650c 100644 --- a/examples/real/helpers/parse.rs +++ b/examples/real/helpers/parse.rs @@ -4,7 +4,7 @@ use lib_ruby_parser::{Parser, ParserOptions, ParserResult}; #[allow(dead_code)] pub(crate) fn parse(input: InputFile, drop_tokens: bool) -> ParserResult { let options = ParserOptions { - buffer_name: input.filepath.into(), + buffer_name: input.filepath, record_tokens: !drop_tokens, ..Default::default() }; diff --git a/examples/real/helpers/printer.rs b/examples/real/helpers/printer.rs index 364a4ecb..c9ce4580 100644 --- a/examples/real/helpers/printer.rs +++ b/examples/real/helpers/printer.rs @@ -28,15 +28,15 @@ mod formatters { pub(crate) fn print_compact_ast_with_locations(result: &ParserResult) { let src = result.input.as_shared_bytes(); - let src = std::str::from_utf8(src.as_ref()).unwrap_or_else(|_| "invalid-source"); + let src = std::str::from_utf8(src).unwrap_or("invalid-source"); println!("{}", src); - print_only_diagnostics(&result); + print_only_diagnostics(result); if let Some(ast) = result.ast.as_ref() { ast.print_with_locs() } } pub(crate) fn print_compact_ast(result: &ParserResult) { - print_only_diagnostics(&result); + print_only_diagnostics(result); if let Some(ast) = result.ast.as_ref() { println!("{}", ast.inspect(0)); } diff --git a/examples/real/helpers/profiler.rs b/examples/real/helpers/profiler.rs index 6cf6a6da..fa66ddc9 100644 --- a/examples/real/helpers/profiler.rs +++ b/examples/real/helpers/profiler.rs @@ -1,5 +1,5 @@ #[cfg(feature = "pprof")] -mod profiler { +mod implementation { extern crate pprof; pub(crate) struct Profiler { @@ -58,7 +58,7 @@ mod profiler { } #[cfg(not(feature = "pprof"))] -mod profiler { +mod implementation { pub(crate) struct Profiler {} impl Profiler { @@ -74,4 +74,4 @@ mod profiler { } } -pub(crate) use profiler::Profiler; +pub(crate) use implementation::Profiler; diff --git a/examples/real/helpers/token_list.rs b/examples/real/helpers/token_list.rs index 452c53e1..bf9ea7b0 100644 --- a/examples/real/helpers/token_list.rs +++ b/examples/real/helpers/token_list.rs @@ -42,7 +42,7 @@ impl std::fmt::Debug for TokenList { .iter() .map(|token| { let name = rpad(&token.token_name(), tok_name_length); - let value = rpad(&token_value(&token), tok_value_length); + let value = rpad(&token_value(token), tok_value_length); format!( " :{}{}[{}, {}]", diff --git a/examples/real/parse.rs b/examples/real/parse.rs index 8816a1a7..74100059 100644 --- a/examples/real/parse.rs +++ b/examples/real/parse.rs @@ -38,10 +38,10 @@ impl From<&Args> for Option { fn from(args: &Args) -> Self { if let Some(code_to_eval) = &args.code_to_eval { Some(InputFiles::new_eval(code_to_eval.clone().into_bytes())) - } else if let Some(pattern) = &args.pattern { - Some(InputFiles::new_pattern(&pattern)) } else { - None + args.pattern + .as_ref() + .map(|pattern| InputFiles::new_pattern(pattern)) } } } diff --git a/examples/real/tokenize.rs b/examples/real/tokenize.rs index 029c93e4..c531144e 100644 --- a/examples/real/tokenize.rs +++ b/examples/real/tokenize.rs @@ -1,7 +1,6 @@ extern crate clap; use clap::Parser; -#[allow(dead_code)] use super::helpers::*; #[derive(Debug, Parser)] @@ -35,5 +34,5 @@ pub(crate) fn main() -> Result<(), Box> { callback(TokenList { tokens }); } - return Ok(()); + Ok(()) }