Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused_variables lint shouldn't warn for unused parameter to default method in trait #26487

Closed
sfackler opened this issue Jun 22, 2015 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@sfackler
Copy link
Member

trait Foo {
    fn bar(&self, a: i32) {}
}

fn main() {}
<anon>:2:19: 2:20 warning: unused variable: `a`, #[warn(unused_variables)] on by default
<anon>:2     fn bar(&self, a: i32) {}
                           ^

The arguments to default methods in traits form part of the documentation, but it is not uncommon for a default implementation of a method to be a no-op that uses none of its arguments.

@sfackler sfackler added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Jun 22, 2015
@sanxiyn
Copy link
Member

sanxiyn commented Jun 24, 2015

I implemented this in #26502, but @brson doesn't seem to think it is a good idea. You may want to comment.

@nikomatsakis
Copy link
Contributor

After some discussion in the lang team meeting, our feeling was that we ought to not make this change: it's just a bit too special-cased and subtle, and to be consistent the rules ought to apply to other kinds of public functions as well. Instead, the recommended course is to add an #[allow] declaration to your trait or default method.

@SoniEx2
Copy link
Contributor

SoniEx2 commented May 26, 2016

I'd recommend let _=x; personally, it's essentially the Rust equivalent of the C (void)x;.

That way you neither use #[allow], which can cause issues, nor _x, which produces ugly docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

4 participants