1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
11 #![allow(clippy::blacklisted_name)]
12 #![warn(clippy::used_underscore_binding)]
14 macro_rules! test_macro {
21 /// Test that we lint if we use a binding with a single leading underscore
22 fn prefix_underscore(_foo: u32) -> u32 {
26 /// Test that we lint if we use a `_`-variable defined outside within a macro expansion
27 fn in_macro(_foo: u32) {
29 assert_eq!(_foo, _foo);
34 // Struct for testing use of fields prefixed with an underscore
35 struct StructFieldTest {
36 _underscore_field: u32,
39 /// Test that we lint the use of a struct field which is prefixed with an underscore
40 fn in_struct_field() {
41 let mut s = StructFieldTest { _underscore_field: 0 };
42 s._underscore_field += 1;
45 /// Test that we do not lint if the underscore is not a prefix
46 fn non_prefix_underscore(some_foo: u32) -> u32 {
50 /// Test that we do not lint if we do not use the binding (simple case)
51 fn unused_underscore_simple(_foo: u32) -> u32 {
55 /// Test that we do not lint if we do not use the binding (complex case). This checks for
56 /// compatibility with the built-in `unused_variables` lint.
57 fn unused_underscore_complex(mut _foo: u32) -> u32 {
63 ///Test that we do not lint for multiple underscores
64 fn multiple_underscores(__foo: u32) -> u32 {
68 // Non-variable bindings with preceding underscore
76 /// Test that we do not lint for non-variable bindings
80 let _e = match _EnumTest::_Value(_StructTest) {
81 _EnumTest::_Empty => 0,
82 _EnumTest::_Value(_st) => 1,
90 // tests of unused_underscore lint
91 let _ = prefix_underscore(foo);
94 // possible false positives
95 let _ = non_prefix_underscore(foo);
96 let _ = unused_underscore_simple(foo);
97 let _ = unused_underscore_complex(foo);
98 let _ = multiple_underscores(foo);