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 #![feature(tool_lints)]
15 #![allow(clippy::blacklisted_name)]
16 #![warn(clippy::used_underscore_binding)]
18 macro_rules! test_macro {
25 /// Test that we lint if we use a binding with a single leading underscore
26 fn prefix_underscore(_foo: u32) -> u32 {
30 /// Test that we lint if we use a `_`-variable defined outside within a macro expansion
31 fn in_macro(_foo: u32) {
33 assert_eq!(_foo, _foo);
38 // Struct for testing use of fields prefixed with an underscore
39 struct StructFieldTest {
40 _underscore_field: u32,
43 /// Test that we lint the use of a struct field which is prefixed with an underscore
44 fn in_struct_field() {
45 let mut s = StructFieldTest { _underscore_field: 0 };
46 s._underscore_field += 1;
49 /// Test that we do not lint if the underscore is not a prefix
50 fn non_prefix_underscore(some_foo: u32) -> u32 {
54 /// Test that we do not lint if we do not use the binding (simple case)
55 fn unused_underscore_simple(_foo: u32) -> u32 {
59 /// Test that we do not lint if we do not use the binding (complex case). This checks for
60 /// compatibility with the built-in `unused_variables` lint.
61 fn unused_underscore_complex(mut _foo: u32) -> u32 {
67 ///Test that we do not lint for multiple underscores
68 fn multiple_underscores(__foo: u32) -> u32 {
72 // Non-variable bindings with preceding underscore
80 /// Test that we do not lint for non-variable bindings
84 let _e = match _EnumTest::_Value(_StructTest) {
85 _EnumTest::_Empty => 0,
86 _EnumTest::_Value(_st) => 1,
94 // tests of unused_underscore lint
95 let _ = prefix_underscore(foo);
98 // possible false positives
99 let _ = non_prefix_underscore(foo);
100 let _ = unused_underscore_simple(foo);
101 let _ = unused_underscore_complex(foo);
102 let _ = multiple_underscores(foo);