-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
pub trait MyTrait {
fn func(&self, arg: &str) -> bool {
false
}
}
The current output is:
warning: unused variable: `arg`
--> src/lib.rs:2:20
|
2 | fn func(&self, arg: &str) -> bool {
| ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
|
= note: `#[warn(unused_variables)]` on by default
I think rustc should not output this warning in this case since the parameter name is part of the public API. The parameter names show up in the documentation generated by rustdoc and having underscores there looks very weird.
Yes I am aware that I can suppress the warning by doing:
pub trait MyTrait {
fn func(&self, #[allow(unused_variables)] arg: &str) -> bool {
false
}
}
However I would argue that this makes the code quite unreadable (and moving the attribute before the function would mean no more warnings for actually unused variables within the default implementation).
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.