Questions tagged [rust-clippy]
45 questions
0
votes
1 answer
how to validate a cli argument in clap 4.0.9
I'm currently restricted to clap 4.0.9 and I have the following code:
#[derive(Debug, clap::Parser)]
pub struct RunCmd {
#[clap(long, default_value_t = 7000)]
pub port: u16,
}
I want to create a function that validates the port that is…

ezio
- 359
- 2
- 13
0
votes
2 answers
Is there any SonarQube static code analysis for scanning Rust or Elixir code repositories?
I have a Gitlab Pipeline for SonarQube which can scan technologies like Node.js, Java, and PHP, but not with Rust and Elixir.
I tried the links below for Rust, but it seems like Rust lacks…

Lorel Carpo
- 19
- 5
0
votes
0 answers
JetBrains CLion giving false positives in no_std nightly Rust, saying builtin types aren't `Sized`
I am part of a project writing a kernel and OS in Rust. I am getting many false positives from the external linter (Clippy), such as:
The size for values of type &str cannot be known at compilation time
The size for values of type…

CATboardBETA
- 418
- 6
- 29
0
votes
2 answers
Check for obsolete clippy allowances
Sometimes you want to suppress a clippy warning for the time being and you let clippy ignore a specific rule for a specific code block by adding lines like the following:
#[allow(dead_code)]
But as the project continues, it can actually happen that…

Dalit Sairio
- 125
- 3
0
votes
0 answers
Fork Rust Clippy and run built executable on other project
I altered the linting messages in Clippy by forking the Clippy repo and changing for example "clippy_lints/no_panics.rs" to alter the message shown when clippy is not told what to do in the presence of panicking code. (my real use case requires…

The Coding Wombat
- 805
- 1
- 10
- 29
0
votes
0 answers
Clippy fix does not persist changes to disk
I'm trying to lint my Rust project using cargo clippy --fix. In VSCode, while the command is running, I can see changes to the files being made in the Git submenu. However, after the command is complete, all changes seem to be reverted and all files…

Bobface
- 2,782
- 4
- 24
- 61
0
votes
1 answer
Bad enforcement of clippy rule?
I have disallowed unrelated shadowing in variable declarations.
But now this rule gives me an error on these two lines
let overflow: bool;
(self.standing, overflow) = self.standing.overflowing_add(reason.to_severity());
The linting error I get…

Thorkil Værge
- 2,727
- 5
- 32
- 48
0
votes
0 answers
How to use `clippy::disallowed_method` with methods inside the same crate
I have some functions defined in my crate that I want to disallow the use of inside of the same, using clippy::disallowed_methods.
For example:
fn f() { ... }
fn g() {
f(); // Warning
}
I've tried the following clippy.toml
disallowed-methods =…

Filipe Rodrigues
- 1,843
- 2
- 12
- 21
0
votes
1 answer
How to fix this clippy warning (needless collect)
I have a hard time fixing the needless collect clippy warning.
pub fn import_selection(packages: &mut Vec) -> io::Result<()> {
let file = fs::File::open("uad_exported_selection.txt")?;
let reader = BufReader::new(file);
let…

Rand0mMan
- 115
- 4
0
votes
0 answers
Does collapsing a nested if using && as suggested by Clippy change the behavior?
I am just starting using rust and discovered the clippy assistant. I am generally very satisfied with its functionalities, but i encountered a recommendation which I do not know if I should follow.
while working with a HashMap, I want to test if a…

Louis
- 83
- 6
0
votes
1 answer
clippy::missing_const_for_fn fires on constructor and getters. Is that a true positive?
I decided to use a bit of a heftier version of clippy to get myself ready for a version change. I was expecting some false positives but I'm not sure about this one. I got the following struct, and clippy tells me that every single function should…

Typhaon
- 828
- 8
- 27
0
votes
1 answer
How do I fix the Clippy warning for clippy::or_fun_call for or_insert / or_insert_with?
I need to count duplicates of a custom struct in a Vec. I've found count partial duplicates in Vec of structs with a custom function.
My code is:
pub fn check_index_duplicates(
dataset: &[main_index::MotiveImageDefinition],
) -> Result<(),…

user1432966
- 523
- 1
- 9
- 20
-1
votes
1 answer
how to rephrase this code to get past clippy::manual_let_else
after some upgrade of msrv I get this (In a project I dont own, just doing the msrv upgrade, so removing the 'pedantic' is not OK)
error: this could be rewritten as `let...else`
--> asyncgit/src/sync/config.rs:99:2
|
99 | / let entry =…

pm100
- 48,078
- 23
- 82
- 145
-1
votes
3 answers
How does flatten behave diffrently with Vec> and Vec> or Vec
The official docs of iter::flatten states :
An iterator that flattens one level of nesting in an iterator of things that can be turned into iterators.
But for this code:
if let Ok(entries) = fs::read_dir("/path/to/dir") {
for entry in…

atamakahere
- 3
- 3
-3
votes
1 answer
How to remove Rust clippy warning `consider using the `vec![]` macro: `let mut https: Vec = vec![..];`
I have below rust code.
let mut https: Vec= Vec::new();
https.push(b'/');
When I am running cargo clippy, I am getting below warning
warning: calls to `push` immediately after creation
https.push(b'/');
^ help: consider…

Ayush Mishra
- 567
- 1
- 7
- 19