rust-lang / rust-lang/rust-clippy
Add a lint to check for functions/methods that could be From
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Checks for functions and methods that could be a From impl (we could even do this for TryFrom)
Advantage
- Makes the code more idiomatic
Drawbacks
No response
Example
struct StructA {
some_field: String
}
struct StructB {
some_field: String
}
fn map_to_struct_b(a: StructA) -> StructB {
StructB {
some_field: a.some_field
}
}
impl StructA {
fn to_struct_b(self) -> StructB {
StructB {
some_field: self.some_field
}
}
}
Could be written as:
impl From<StructA> for StructB {
fn from(a: StructA) -> Self {
StructB {
some_field: a.some_field
}
}
}
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 from the function and method examples in the issue, then review existing Clippy lint conventions and tests for how new lints are structured. Define the qualifying conversion cases and exclusions before implementation; done means the lint reliably identifies the intended cases and has coverage for the examples and relevant edge cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100