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

Silence clippy lints in ascent!{ … } & ascent_run!{ … } macro expansions #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

regexident
Copy link
Contributor

Given a program

# Cargo.toml

[dependencies]
ascent = "0.4.0"
// main.rs

use ascent::ascent;

ascent! {
   relation edge(i32, i32);
   relation path(i32, i32);

   path(x, y) <-- edge(x, y);
   path(x, z) <-- edge(x, y), path(y, z);
}

fn main() {
    let mut prog = AscentProgram {
        edge: vec![(1, 2), (2, 3)],
        ..Default::default()
    };
    prog.run();
    println!("path: {:?}", prog.path);
}

Running cargo clippy results in a couple of clippy warnings:

  • clippy::clone_on_copy
  • clippy::let_unit_value
Full terminal output
warning: using `clone` on type `i32` which implements the `Copy` trait
 --> src/main.rs:5:13
  |
5 |    relation path(i32, i32);
  |             ^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
  = note: `#[warn(clippy::clone_on_copy)]` on by default
help: try removing the `clone` call
  |
5 ~    relation ascent! {
6 +    relation edge(i32, i32);
7 +    relation path(i32, i32);
8 + 
9 +    path(x, y) <-- edge(x, y);
10+    path(x, z) <-- edge(x, y), path(y, z);
11~ }(i32, i32);
  |

warning: using `clone` on type `i32` which implements the `Copy` trait
 --> src/main.rs:8:36
  |
8 |    path(x, z) <-- edge(x, y), path(y, z);
  |                                    ^ help: try dereferencing it: `*y`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on type `i32` which implements the `Copy` trait
 --> src/main.rs:8:27
  |
8 |    path(x, z) <-- edge(x, y), path(y, z);
  |                           ^ help: try dereferencing it: `*y`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on type `i32` which implements the `Copy` trait
 --> src/main.rs:4:13
  |
4 |    relation edge(i32, i32);
  |             ^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
help: try removing the `clone` call
  |
4 ~    relation ascent! {
5 +    relation edge(i32, i32);
6 +    relation path(i32, i32);
7 + 
8 +    path(x, y) <-- edge(x, y);
9 +    path(x, z) <-- edge(x, y), path(y, z);
10~ }(i32, i32);
  |

warning: this let-binding has unit value
 --> src/main.rs:4:13
  |
4 |    relation edge(i32, i32);
  |             ^^^^ help: omit the `let` binding: `edge;`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
  = note: `#[warn(clippy::let_unit_value)]` on by default

warning: `graph_queries` (bin "graph_queries") generated 5 warnings (run `cargo clippy --fix --bin "graph_queries"` to apply 5 suggestions)
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s

@regexident regexident force-pushed the avoid-clippy-warnings branch 2 times, most recently from 647f841 to 120466e Compare May 5, 2023 22:46
@regexident
Copy link
Contributor Author

For development purposes it might make sense to control lint-silencing with a feature that's enable by default.

[features]
default = ["silence-lints"]
silence-lints = []

So instead of …

#![allow(clippy::all)]

… the lints would be silenced like this:

#![cfg_attr(feature = "silence-lints", allow(clippy::all))]

This would allow for disabling the silencing during development for the purpose of catching anti-patterns, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant