rust-lang / rust-lang/rust

Unsized parameters are not flagged in trait definitions

Open
#129,252 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
trait Trait<T: ?Sized> {
    fn method(t: T); 
}
Current output
<none>
Desired output
A warning that the `?Sized` constraint is useless
Rationale and extra context

Any concrete choice of T that's unsized will result in E0277 when the trait is implemented, so marking it as unsized isn't allowing anything that wasn't already valid. This exact error will appear if method has a default implementation.

Similar redundant constructions like comparing unsigned values to 0 are flagged, so I'd expect this to be too.

Other cases

No response

Rust Version
stable 1.80.1
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported trait definition and compare its handling with existing diagnostics for redundant constructions. Add a warning for the useless ?Sized constraint on an unsized parameter in a trait method, and verify that the example produces the warning without changing valid cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.