rust-lang / rust-lang/rust-clippy
`clippy::default_trait_access` can give incorrect suggestion
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
There seems to be another issue with default_trait_access in this code.
#![warn(clippy::pedantic)]
mod data {
#[derive(Default)]
pub struct Data<T> {
pub _data: T,
}
}
fn main() {
let _s22: data::Data<u8> = Default::default();
}
cargo clippy suggests
Checking vectors v0.1.0 (/home/hamir/vectors)
warning: calling `Data::default()` is more clear than this expression
--> src/main.rs:10:32
|
10 | let _s22: data::Data<u8> = Default::default();
| ^^^^^^^^^^^^^^^^^^ help: try: `Data::default()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_trait_access
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[warn(clippy::default_trait_access)]` implied by `#[warn(clippy::pedantic)]`
warning: `vectors` (bin "vectors") generated 1 warning
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
but Data::default() results in a compilation error whereas data::Data::default() would have worked fine.
Originally posted by @hamirmahal in https://github.com/rust-lang/rust-clippy/issues/8342#issuecomment-2156213527
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the incorrect default_trait_access suggestion with the Rust snippet in the issue using cargo clippy. Then locate the lint implementation and its existing tests, add a regression case for the generic data::Data<u8> example, and verify that the suggested path compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100