Questions tagged [rust-clippy]
45 questions
2
votes
1 answer
Why does calling .into() within its own From implementation not give a recursion warning?
Why doesn't Rust give a "unconditional recursion" warning for using x.into() method when it gives warning for Self::from(x)?
Consider below example, in rust playground:
struct Foo;
struct Bar;
impl From for Bar {
fn from(x: Foo) -> Self {
…

akhildevelops
- 159
- 1
- 8
2
votes
1 answer
Cargo Clippy throws error 'Question mark operator is useless here' - are suggestions okay to implement?
I've taken over a deploy process and part of this runs Cargo Clippy which was working fine up until late last week, when I started getting this error:
error: Question mark operator is useless here
I've read the suggested link…

Irene
- 181
- 1
- 4
2
votes
1 answer
Clippy complaining on strict f32 comparison
I have a test assertion that looks like this
assert_eq!(-0.000031989493, res);
which works for the test. But when I run Clippy on my test it complains.
error: strict comparison of `f32` or `f64`
--> src/main.rs:351:9
|
351 | …

mottosson
- 3,283
- 4
- 35
- 73
2
votes
1 answer
Clippy redundant allocation lint
So I have this trait and a struct that implements it:
trait Trait {
fn foo(&self) -> u64;
}
/// No Copy trait supported because it's expensive
struct Expensive {
id: u64,
}
impl Trait for Expensive {
fn foo(&self) -> u64 {
…

wrongusername
- 18,564
- 40
- 130
- 214
1
vote
0 answers
How to find code (eg functions) that is not referenced by any other code?
Every time I come back to rust I am baffled by how the warnings for unused code work, they're transitive! Even if function f is called from function g, f will still be considered unused if g is unused.
I'm sure this is very useful behavior for some…

withstanding_crepe
- 11
- 3
1
vote
1 answer
Method can be confused for the standard trait method
I have this warning, and I don't how to fix this warning.
warning: method `next` can be confused for the standard trait method `std::iter::Iterator::next`
--> src/util/mod.rs:51:5
|
51 | / pub fn next(&mut self) -> Option {
52 | | …

bichanna
- 954
- 2
- 21
1
vote
1 answer
Using a type definition to simplify a function signature
Clippy is giving the following warning:
warning: very complex type used. Consider factoring parts into `type` definitions
--> src/regexp/mod.rs:845:56
|
845 | pub fn get_by_name<'b>(&'b self, name: &'b str) -> Vec<(&'b String, (usize,…

russell
- 660
- 1
- 10
- 18
1
vote
1 answer
How can I prune superfluous generic bounds?
I rely on the compiler to tell me when generic bounds on my types/impls are insufficient and which trait constraints are missing, but the compiler never tells me when my generics are over-constrained.
Is there a tool for finding generics with…

Mitchell Turner
- 163
- 6
1
vote
1 answer
How to pretty-print inlined variables when formatting strings
Normally one can print strings the following way: println!("{:#?}", foo) where the {:#?} syntax will make a pretty-print of the value. But I know it's also possible to inline the variable directly in the string between the curly braces, instead of…

Milkncookiez
- 6,817
- 10
- 57
- 96
1
vote
0 answers
How can I create a Rust Clippy binary to use as part of a separate standalone application?
I am trying to build a standalone application through which I can run Rust Clippy without needing to install it locally. Essentially, I want to run a command like cargo-clippy -- --message-format=json through my application when a Rust project is…

slowhand
- 35
- 4
1
vote
0 answers
New linting tool cloned from Clippy still tries to handle clippy lints
I cloned clippy and want to make my own standalone linting tool "myclippy" that should still be able to work besides clippy, but should also work without it.
I changed the names of the cargo-clippy and clippy-driver bins to "cargo-myclippy" and…

The Coding Wombat
- 805
- 1
- 10
- 29
1
vote
1 answer
What is the difference between "reborrow"-ing and "deref"-ing?
Clippy is warning me about a "deref on an immutable reference" in my code, an example being &*s where s is a &String.
Clippy suggests,
if you would like to reborrow, try removing &*
or
if you would like to deref, try using &**
What is the…

suchapalaver
- 13
- 6
1
vote
2 answers
1
vote
0 answers
How to increase the length of messages displayed by clippy or rustc
How can I increase the number of source code lines shown in rustc or clippy messages? I have the problem that one of the changes suggested by clippy is truncated because it's too long.
For example, the warning message that I see is this:
warning:…

Federico
- 1,925
- 14
- 19
0
votes
1 answer
Rust dead code analysis for code exposed only to the binary in the same lib crate
Across our database, many crates expose both lib.rs, and main.rs, effectively forcing the binary to be an "external" user of its own crate.
The crate usually exposes a configuration and a set of public functions that consume the configuration in…

sukhmel
- 1,402
- 16
- 29