Skip to content

Add test for derives for used_underscore_binding lint #4011

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

Merged
merged 1 commit into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/ui/auxiliary/proc_macro_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ use proc_macro::{quote, TokenStream};

#[proc_macro_derive(DeriveSomething)]
pub fn derive(_: TokenStream) -> TokenStream {
// Shound not trigger `used_underscore_binding`
let _inside_derive = 1;
assert_eq!(_inside_derive, _inside_derive);

let output = quote! {
// Should not trigger `useless_attribute`
#[allow(dead_code)]
extern crate clippy_lints;
};
Expand Down
12 changes: 11 additions & 1 deletion tests/ui/used_underscore_binding.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
// aux-build:proc_macro_derive.rs

#![warn(clippy::all)]
#![allow(clippy::blacklisted_name)]
#![warn(clippy::used_underscore_binding)]

#[macro_use]
extern crate proc_macro_derive;

// This should not trigger the lint. There's underscore binding inside the external derive that
// would trigger the `used_underscore_binding` lint.
#[derive(DeriveSomething)]
struct Baz;

macro_rules! test_macro {
() => {{
let _foo = 42;
Expand Down Expand Up @@ -51,7 +61,7 @@ fn unused_underscore_complex(mut _foo: u32) -> u32 {
1
}

///Test that we do not lint for multiple underscores
/// Test that we do not lint for multiple underscores
fn multiple_underscores(__foo: u32) -> u32 {
__foo + 1
}
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/used_underscore_binding.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:14:5
--> $DIR/used_underscore_binding.rs:24:5
|
LL | _foo + 1
| ^^^^
|
= note: `-D clippy::used-underscore-binding` implied by `-D warnings`

error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:19:20
--> $DIR/used_underscore_binding.rs:29:20
|
LL | println!("{}", _foo);
| ^^^^

error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:20:16
--> $DIR/used_underscore_binding.rs:30:16
|
LL | assert_eq!(_foo, _foo);
| ^^^^

error: used binding `_foo` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:20:22
--> $DIR/used_underscore_binding.rs:30:22
|
LL | assert_eq!(_foo, _foo);
| ^^^^

error: used binding `_underscore_field` which is prefixed with an underscore. A leading underscore signals that a binding will not be used.
--> $DIR/used_underscore_binding.rs:33:5
--> $DIR/used_underscore_binding.rs:43:5
|
LL | s._underscore_field += 1;
| ^^^^^^^^^^^^^^^^^^^
Expand Down