Open T-Dark0 opened 3 years ago
Thanks! Any lints other than single_component_path_imports
and items_after_statements
not working? This bug will have to be fixed for individual lints.
now you mention it, i've seen a similar problem with clippy::print_stderr
, where the behaviour is different whether the lint is used in the crate root, or in a module.
see https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/172#note_2767740
This makes Clippy hard to use with generated files, like lalrpop output, because the offending patterns may occur hundreds of times, and the legitimate warnings are hard to find.
Here's another case, with a single source file:
mod foo {
#![allow(clippy::single_component_path_imports)]
use regex;
pub fn foo() {
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
}
}
fn main() {
foo::foo();
}
Output:
$ cargo clippy --version
clippy 0.1.61 (fe5b13d 2022-05-18)
$ cargo clippy
warning: this import is redundant
--> src/main.rs:3:5
|
3 | use regex;
| ^^^^^^^^^^ help: remove it entirely
|
= note: `#[warn(clippy::single_component_path_imports)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
warning: `clippy-bug` (bin "clippy-bug") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
$
Finding that single_component_path_imports = "allow"
(lint configuration in Cargo.toml) also doesn't seem to have an effect.
Another way to trigger the effect is to use the command line option: -A clippy::single_component_path_imports
I tried this code:
I expected to see this happen: The lint is silenced for the module
Instead, this happened: The lint was not silenced, and fired anyway in the output of
cargo clippy
It may be worth mentioning that the lint is silenced if and only if the
allow
exists both in the crate root and in the moduleThis bug also occurs with other lints, but does not occur with all lints: I've been able to cause it with
items_after_statements
, but not withenum_glob_use
ormatch_same_arms
. In the case of the latter two, the lint was silenced for the module without the need toallow
it in the crate root as well.Meta
cargo clippy -V
: clippy 0.1.54 (1c6868aa 2021-05-27)rustc -Vv
: