Unsized types in required trait methods
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
so this issue is a follow up for #134422 (closed as not planned) to suggest making a lint instead.
What the issue talked about
Rust does not check for T: Sized in required trait methods
trait Foo {
fn bar(self: Self, x: str);
}
The above code compiles, even though Self and str are both ?Sized
this makes the trait unimplementable
impl Foo for [u8] {
fn bar(self: Self, x: str) {}
}
Produces:
The size for values of type `[u8]` cannot be known at compile time
The size for values of type `str` cannot be known at compile time
For more information please see the RFC
Meta
for anyone who cares, here is rustc --version --verbose
rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
Here is the RFC
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 by reading RFC 3745 and the discussion in issue #134422, then examine the reported examples of required trait methods with unsized Self and parameters. Define the lint's intended diagnostics and applicability, and add coverage demonstrating the unsized cases are reported without making valid methods fail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100