Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings and cliippy lints #669

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions enums/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[macro_use]
macro_rules! mk_enum {
( $( $camel:ident ),* ) => {
#[derive(Clone, Debug, IntoEnumIterator, PartialEq)]
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -43,7 +40,6 @@ macro_rules! mk_get_language_name {
};
}

#[macro_use]
macro_rules! mk_langs {
( $( ($camel:ident, $name:ident) ),* ) => {
mk_enum!($( $camel ),*);
Expand Down
6 changes: 3 additions & 3 deletions enums/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust-code-analysis-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/asttools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub fn get_parent<'a>(node: &'a Node<'a>, level: usize) -> Option<Node<'a>> {
Some(node)
}

#[macro_use]
macro_rules! has_ancestors {
($node:expr, $( $typs:pat )|*, $( $typ:pat ),+) => {{
let mut res = false;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/languages/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Luni-4 marked this conversation as resolved.
Show resolved Hide resolved

pub mod language_ccomment;
pub use language_ccomment::*;

Expand Down
12 changes: 0 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[macro_use]
macro_rules! mk_checker {
( $name:ident, $( $type:ident ),* ) => {
#[inline(always)]
Expand All @@ -13,7 +12,6 @@ macro_rules! mk_checker {
};
}

#[macro_use]
macro_rules! mk_else_if {
($if_type:ident) => {
#[inline(always)]
Expand All @@ -30,7 +28,6 @@ macro_rules! mk_else_if {
};
}

#[macro_use]
macro_rules! get_language {
(tree_sitter_cpp) => {
tree_sitter_mozcpp::language()
Expand All @@ -46,7 +43,6 @@ macro_rules! get_language {
};
}

#[macro_use]
macro_rules! mk_enum {
( $( $camel:ident, $description:expr ),* ) => {
/// The list of supported languages.
Expand All @@ -60,7 +56,6 @@ macro_rules! mk_enum {
};
}

#[macro_use]
macro_rules! mk_impl_lang {
( $( ($camel:ident, $name:ident, $display: expr) ),* ) => {
impl LANG {
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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) ),* ) => {
$(
Expand Down Expand Up @@ -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 ),*);
Expand All @@ -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)))?;
Expand All @@ -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)? )$(,)* )* ]$(,)*
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/cognitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
2 changes: 1 addition & 1 deletion src/metrics/halstead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/output/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -136,7 +136,7 @@ fn dump_tree_helper(
loop {
i -= 1;
dump_tree_helper(
&code,
code,
&Node::new(cursor.node()),
&prefix,
i == 0,
Expand Down Expand Up @@ -178,7 +178,7 @@ impl Callback for Dump {

fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res {
dump_node(
&parser.get_code(),
parser.get_code(),
&parser.get_root(),
-1,
cfg.line_start,
Expand Down
4 changes: 2 additions & 2 deletions src/output/dump_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/preproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn fix_includes<S: ::std::hash::BuildHasher>(
};
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()) {
Expand Down Expand Up @@ -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());
}
Expand Down
2 changes: 1 addition & 1 deletion src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn read_file_with_eol(path: &Path) -> std::io::Result<Option<Vec<u8>>> {
};

// 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
Expand All @@ -74,7 +74,7 @@ pub fn read_file_with_eol(path: &Path) -> std::io::Result<Option<Vec<u8>>> {
}

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)?;

Expand Down Expand Up @@ -327,7 +327,7 @@ pub(crate) fn guess_file<S: ::std::hash::BuildHasher>(
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;
Expand Down