Unused variable pass flags variables in derived trait functions
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.9k
- Forks
- 231
- Avg merge
- 20h 2m
- Merged PRs (30d)
- 66
Description
Summary
The unused variable analysis pass currently checks variables inside trait implementations generated via #[derive(...)]. However, since these functions are not written by the user and are automatically generated by the compiler, such warnings can be confusing and should likely be suppressed.
Reproducer
I tried this code:
#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
#[lang = "structural_peq"]
trait StructuralPartialEq {}
#[lang = "eq"]
pub trait PartialEq<Rhs: ?Sized = Self> {
fn eq(&self, other: &Rhs) -> bool;
fn ne(&self, other: &Rhs) -> bool {
!self.eq(other)
}
}
#[derive(PartialEq, Copy)] // { dg-warning "unused name" }
struct Foo;
Does the code make use of any (1.49) nightly feature ?
- Nightly
Godbolt link
No response
Actual behavior
<source>:29:3: warning: unused name 'other' [-Wunused-variable]
29 | #[derive(PartialEq, Copy)] // { dg-warning "unused name" }
| ^~~~~~
Expected behavior
No response
GCC Version
dd7a656cb13f83cd32671b34865d0a4b265162c0
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 reproducing the warning with the provided #[derive(PartialEq, Copy)] example, then trace the unused-variable analysis for trait implementations generated by derives. The change is done when the generated function no longer reports the unused parameter while equivalent user-written code still does; no source file or test path is named in the issue.
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
- 45/100