Rust-GCC / Rust-GCC/gccrs

Do not warn for unused variables on trait method declaration

Open
#541 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug diagnostic
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

On the following code, gccrs should not warn about unused variables:

pub trait Foo {
    fn Bar(self) -> i32;
}

Since we are simply "declaring" (in C/C++ terms) a trait method, the self variable is not intended to be used here. However, each type that implement the Foo trait will need to use the self variable (or rename it) in their implementation of the Bar method.

The following code, which provides a default implementation for the trait method, should warn:

pub trait Foo {
    fn Bar(self) -> i32 {
        -1 // default implementation returns -1 for example
    }
}

So there should be a distinction between a default trait method implementation and just a 'declaration' like here for unused variables

Originally posted in https://github.com/Rust-GCC/gccrs/pull/540#discussion_r662380851

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

No source file or test is named. Start by tracing the unused-variable warning entry point for Rust trait methods, then compare declaration-only methods with default implementations. Done means declaration-only trait parameters do not warn, while parameters in default implementations still do.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, 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.