rust-lang / rust-lang/rust-clippy
Detect incorrect forwarding impls of Display
Open
Nobody has claimed this yet.
A-lint
E-medium
L-correctness
T-middle
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
If forwarding to the inner type's Display is done incorrectly then it won't work properly with many of the nice formatting options that our macros allow us to use.
use std::fmt;
struct Correct(&'static str);
impl fmt::Display for Correct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
}
}
struct Incorrect(&'static str);
impl fmt::Display for Incorrect {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
fn main() {
println!("{: <10} World", Correct("Hello"));
println!("{: <10} World", Incorrect("Hello"));
}
Output:
Hello World
Hello World
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
Start with the Rust playpen example in the issue, comparing the Correct and Incorrect Display implementations and their formatting output. Identify the lint entry point and existing lint tests for analogous implementation patterns; done means incorrect forwarding implementations are detected while correct formatter forwarding remains accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100