diff --git a/enums/src/macros.rs b/enums/src/macros.rs index da8dcc1d8..2842b1cba 100644 --- a/enums/src/macros.rs +++ b/enums/src/macros.rs @@ -1,4 +1,3 @@ -#[macro_use] macro_rules! mk_enum { ( $( $camel:ident ),* ) => { #[derive(Clone, Debug, IntoEnumIterator, PartialEq)] @@ -10,7 +9,6 @@ macro_rules! mk_enum { }; } -#[macro_use] macro_rules! mk_get_language { ( $( ($camel:ident, $name:ident) ),* ) => { pub fn get_language(lang: &Lang) -> Language { @@ -30,7 +28,6 @@ macro_rules! mk_get_language { }; } -#[macro_use] macro_rules! mk_get_language_name { ( $( $camel:ident ),* ) => { pub fn get_language_name(lang: &Lang) -> &'static str { @@ -43,7 +40,6 @@ macro_rules! mk_get_language_name { }; } -#[macro_use] macro_rules! mk_langs { ( $( ($camel:ident, $name:ident) ),* ) => { mk_enum!($( $camel ),*); diff --git a/enums/src/main.rs b/enums/src/main.rs index cd84abb6e..01aa1476f 100644 --- a/enums/src/main.rs +++ b/enums/src/main.rs @@ -45,17 +45,17 @@ fn main() { match language { "rust" => { - if let Some(err) = generate_rust(&output, &file_template).err() { + if let Some(err) = generate_rust(output, file_template).err() { eprintln!("{:?}", err); } } "go" => { - if let Some(err) = generate_go(&output, &file_template).err() { + if let Some(err) = generate_go(output, file_template).err() { eprintln!("{:?}", err); } } "json" => { - if let Some(err) = generate_json(&output, &file_template).err() { + if let Some(err) = generate_json(output, file_template).err() { eprintln!("{:?}", err); } } diff --git a/rust-code-analysis-cli/src/main.rs b/rust-code-analysis-cli/src/main.rs index b9c0bd472..a8f32b1fe 100644 --- a/rust-code-analysis-cli/src/main.rs +++ b/rust-code-analysis-cli/src/main.rs @@ -236,14 +236,14 @@ fn explore( }; } - send_file(path, &cfg, language, &sender); + send_file(path, cfg, language, sender); } } } else if (include.is_empty() || include.is_match(&path)) && (exclude.is_empty() || !exclude.is_match(&path)) && path.is_file() { - send_file(path, &cfg, language, &sender); + send_file(path, cfg, language, sender); } } diff --git a/src/asttools.rs b/src/asttools.rs index 1b446c80d..53a680669 100644 --- a/src/asttools.rs +++ b/src/asttools.rs @@ -16,7 +16,6 @@ pub fn get_parent<'a>(node: &'a Node<'a>, level: usize) -> Option> { Some(node) } -#[macro_use] macro_rules! has_ancestors { ($node:expr, $( $typs:pat )|*, $( $typ:pat ),+) => {{ let mut res = false; @@ -54,7 +53,6 @@ macro_rules! has_ancestors { }}; } -#[macro_use] macro_rules! count_specific_ancestors { ($node:expr, $( $typs:pat )|*, $( $stops:pat )|*) => {{ let mut count = 0; diff --git a/src/languages/mod.rs b/src/languages/mod.rs index 8073d95b6..46da5780d 100644 --- a/src/languages/mod.rs +++ b/src/languages/mod.rs @@ -1,3 +1,7 @@ +// FIXME: this should be fixed in some way to avoid useless allocations +#![allow(clippy::cmp_owned)] +#![allow(clippy::enum_variant_names)] + pub mod language_ccomment; pub use language_ccomment::*; diff --git a/src/macros.rs b/src/macros.rs index 375ea71e1..ada6515c2 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,4 +1,3 @@ -#[macro_use] macro_rules! mk_checker { ( $name:ident, $( $type:ident ),* ) => { #[inline(always)] @@ -13,7 +12,6 @@ macro_rules! mk_checker { }; } -#[macro_use] macro_rules! mk_else_if { ($if_type:ident) => { #[inline(always)] @@ -30,7 +28,6 @@ macro_rules! mk_else_if { }; } -#[macro_use] macro_rules! get_language { (tree_sitter_cpp) => { tree_sitter_mozcpp::language() @@ -46,7 +43,6 @@ macro_rules! get_language { }; } -#[macro_use] macro_rules! mk_enum { ( $( $camel:ident, $description:expr ),* ) => { /// The list of supported languages. @@ -60,7 +56,6 @@ macro_rules! mk_enum { }; } -#[macro_use] macro_rules! mk_impl_lang { ( $( ($camel:ident, $name:ident, $display: expr) ),* ) => { impl LANG { @@ -85,7 +80,6 @@ macro_rules! mk_impl_lang { }; } -#[macro_use] macro_rules! mk_action { ( $( ($camel:ident, $parser:ident) ),* ) => { /// Runs a function, which implements the [`Callback`] trait, @@ -161,7 +155,6 @@ macro_rules! mk_action { }; } -#[macro_use] macro_rules! mk_extensions { ( $( ($camel:ident, [ $( $ext:ident ),* ]) ),* ) => { /// Detects the language associated to the input file extension. @@ -188,7 +181,6 @@ macro_rules! mk_extensions { }; } -#[macro_use] macro_rules! mk_emacs_mode { ( $( ($camel:ident, [ $( $emacs_mode:expr ),* ]) ),* ) => { /// Detects the language associated to the input `Emacs` mode. @@ -218,7 +210,6 @@ macro_rules! mk_emacs_mode { }; } -#[macro_use] macro_rules! mk_code { ( $( ($camel:ident, $code:ident, $parser:ident, $name:ident, $docname:expr) ),* ) => { $( @@ -249,7 +240,6 @@ macro_rules! mk_code { }; } -#[macro_use] macro_rules! mk_langs { ( $( ($camel:ident, $description: expr, $display: expr, $code:ident, $parser:ident, $name:ident, [ $( $ext:ident ),* ], [ $( $emacs_mode:expr ),* ]) ),* ) => { mk_enum!($( $camel, $description ),*); @@ -261,7 +251,6 @@ macro_rules! mk_langs { }; } -#[macro_use] macro_rules! color { ( $stdout: ident, $color: ident) => { $stdout.set_color(ColorSpec::new().set_fg(Some(Color::$color)))?; @@ -276,7 +265,6 @@ macro_rules! color { } #[cfg(test)] -#[macro_use] macro_rules! check_metrics { ($source: expr, $file: expr, $parser: ident, $metric: ident, [ $( ( $func_int: ident, $true_int_value: expr $(,$type_int: ty)? )$(,)* )* ]$(,)* diff --git a/src/metrics/cognitive.rs b/src/metrics/cognitive.rs index d671783af..096c61259 100644 --- a/src/metrics/cognitive.rs +++ b/src/metrics/cognitive.rs @@ -252,7 +252,7 @@ impl Cognitive for RustCode { match node.object().kind_id().into() { IfExpression | IfLetExpression => { // Check if a node is not an else-if - if !Self::is_else_if(&node) { + if !Self::is_else_if(node) { nesting_levels!( node, stats, [FunctionItem => SourceFile], @@ -298,7 +298,7 @@ impl Cognitive for CppCode { match node.object().kind_id().into() { IfStatement => { - if !Self::is_else_if(&node) { + if !Self::is_else_if(node) { nesting_levels!( node, stats, [LambdaExpression => TranslationUnit], diff --git a/src/metrics/halstead.rs b/src/metrics/halstead.rs index 459105251..ea42fb7ee 100644 --- a/src/metrics/halstead.rs +++ b/src/metrics/halstead.rs @@ -266,7 +266,7 @@ fn compute_halstead<'a, T: Getter>( code: &'a [u8], halstead_maps: &mut HalsteadMaps<'a>, ) { - match T::get_op_type(&node) { + match T::get_op_type(node) { HalsteadType::Operator => { *halstead_maps .operators diff --git a/src/output/dump.rs b/src/output/dump.rs index aaea93ce7..0430ee053 100644 --- a/src/output/dump.rs +++ b/src/output/dump.rs @@ -43,8 +43,8 @@ pub fn dump_node( let stdout = StandardStream::stdout(ColorChoice::Always); let mut stdout = stdout.lock(); let ret = dump_tree_helper( - &code, - &node, + code, + node, "", true, &mut stdout, @@ -136,7 +136,7 @@ fn dump_tree_helper( loop { i -= 1; dump_tree_helper( - &code, + code, &Node::new(cursor.node()), &prefix, i == 0, @@ -178,7 +178,7 @@ impl Callback for Dump { fn call(cfg: Self::Cfg, parser: &T) -> Self::Res { dump_node( - &parser.get_code(), + parser.get_code(), &parser.get_root(), -1, cfg.line_start, diff --git a/src/output/dump_metrics.rs b/src/output/dump_metrics.rs index 92e9a1a6f..286c13281 100644 --- a/src/output/dump_metrics.rs +++ b/src/output/dump_metrics.rs @@ -43,7 +43,7 @@ use crate::spaces::{CodeMetrics, FuncSpace}; pub fn dump_root(space: &FuncSpace) -> std::io::Result<()> { let stdout = StandardStream::stdout(ColorChoice::Always); let mut stdout = stdout.lock(); - dump_space(&space, "", true, &mut stdout)?; + dump_space(space, "", true, &mut stdout)?; color!(stdout, White); Ok(()) @@ -64,7 +64,7 @@ fn dump_space( write!(stdout, "{}: ", space.kind)?; color!(stdout, Cyan, true); - write!(stdout, "{}", space.name.as_ref().map_or("", |name| &name))?; + write!(stdout, "{}", space.name.as_ref().map_or("", |name| name))?; color!(stdout, Red, true); writeln!(stdout, " (@{})", space.start_line)?; diff --git a/src/preproc.rs b/src/preproc.rs index 07e428d5d..29cffe0c5 100644 --- a/src/preproc.rs +++ b/src/preproc.rs @@ -86,7 +86,7 @@ pub fn fix_includes( }; let direct_includes = &pf.direct_includes; for i in direct_includes { - let possibilities = guess_file(&file, i, all_files); + let possibilities = guess_file(file, i, all_files); for i in possibilities { if &i != file { let i = match nodes.entry(i.clone()) { @@ -213,7 +213,7 @@ pub fn preprocess(parser: &PreprocParser, path: &Path, results: &mut PreprocResu let identifier = cursor.node(); if identifier.kind_id() == Preproc::Identifier { - let r#macro = identifier.utf8_text(&code).unwrap(); + let r#macro = identifier.utf8_text(code).unwrap(); if !SPECIALS.contains(r#macro) { file_result.macros.insert(r#macro.to_string()); } diff --git a/src/spaces.rs b/src/spaces.rs index eada6d78a..26601e88f 100644 --- a/src/spaces.rs +++ b/src/spaces.rs @@ -156,7 +156,7 @@ impl FuncSpace { ), }; Self { - name: T::get_func_space_name(&node, code).map(|name| name.to_string()), + name: T::get_func_space_name(node, code).map(|name| name.to_string()), spaces: Vec::new(), metrics: CodeMetrics::default(), kind, diff --git a/src/tools.rs b/src/tools.rs index 8238af30a..df45342f7 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -65,7 +65,7 @@ pub fn read_file_with_eol(path: &Path) -> std::io::Result>> { }; // so start contains more or less 64 chars - let mut head = String::from_utf8_lossy(&start).into_owned(); + let mut head = String::from_utf8_lossy(start).into_owned(); // The last char could be wrong because we were in the middle of an utf-8 sequence head.pop(); // now check if there is an invalid char @@ -74,7 +74,7 @@ pub fn read_file_with_eol(path: &Path) -> std::io::Result>> { } let mut data = Vec::with_capacity(file_size + 2); - data.extend_from_slice(&start); + data.extend_from_slice(start); file.read_to_end(&mut data)?; @@ -327,7 +327,7 @@ pub(crate) fn guess_file( if current_path == p { continue; } - if let Some(dist) = get_paths_dist(current_path, &p) { + if let Some(dist) = get_paths_dist(current_path, p) { match dist.cmp(&dist_min) { Ordering::Less => { dist_min = dist;