rust-lang / rust-lang/rust-clippy
Lint against Sized constraints where appropriate
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I've used Rust for a while now, and a long time ago struggled with needing to add : Sized to some types. Apparently quite a while ago, this changed to Sized being default and needing to request unsizedness in certain contexts. I had been struggling thinking
trait Foo {
type Assoc;
fn foo(&self, in: &Assoc);
}
struct Bar {}
impl Foo for Bar {
type Assoc = [AType];
fn foo(&self, in: &[AType]) { ... }
}
Had simply become impossible (I haven't needed it since pre-1.0 so it could've been true) until I went on the Rust Discord and had it revealed that, in fact, Sized is the default and ?Sized needs to be requested; an un-constraint rather than a constraint.
Unfortunately, I've been operating under this assumption for a while so I have some code with associated types that needs Sized behavior that explicitly calls for type Assoc: Sized or <T: Sized>. It might be worth linting against Sized constraints and noting it's effectively a non-constraint.
One consideration is that : Sized could potentially be seen as documentation (i.e. "hello future coder do not change this to ?Sized please or things will break"), so I don't know if it should be on by default or not.
Related to #1368.
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
The issue names no implementation files or tests. Start by reading related issue #1368 and the Rust examples in the report, then survey how Clippy lints are specified and tested. Done means the applicable Sized constraints, default lint behavior, documentation intent, and test coverage are agreed and implemented.
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