1 // Tests that lint levels can be set for early lints.
2 #![allow(non_camel_case_types, unsafe_code, while_true, unused_parens)]
4 // The following is a check of the lints used here to verify they do not warn
6 fn verify_no_warnings() {
7 type non_camel_type = i32; // non_camel_case_types
8 struct NON_CAMEL_IS_ALLOWED; // non_camel_case_types
9 unsafe {} // unsafe_code
11 VARIANT_CAMEL // non_camel_case_types
13 fn generics<foo>() {} // non_camel_case_types
14 while true {} // while_true
15 type T = (i32); // unused_parens
19 // ################## Types
21 #[deny(non_camel_case_types)]
22 type type_outer = i32; //~ ERROR type `type_outer` should have an upper camel case name
24 type BareFnPtr = fn(#[deny(unused_parens)](i32)); //~ ERROR unnecessary parentheses around type
25 // There aren't any early lints that currently apply to the variadic spot.
26 // type BareFnPtrVariadic = extern "C" fn(i32, #[deny()]...);
28 // ################## Items
29 #[deny(non_camel_case_types)]
30 struct ITEM_OUTER; //~ ERROR type `ITEM_OUTER` should have an upper camel case name
35 unsafe {} //~ ERROR usage of an `unsafe` block
43 fn inherent_denied_from_inner() { unsafe {} } //~ usage of an `unsafe` block
46 fn inherent_fn() { while true {} } //~ ERROR denote infinite loops with
49 const INHERENT_CONST: i32 = {while true {} 1}; //~ ERROR denote infinite loops with
52 trait trait_inner { //~ ERROR trait `trait_inner` should have an upper camel case name
53 #![deny(non_camel_case_types)]
56 trait AssociatedTrait {
59 fn denied_from_inner() { unsafe {} } //~ ERROR usage of an `unsafe` block
62 fn assoc_fn() { while true {} } //~ ERROR denote infinite loops with
65 const ASSOC_CONST: i32 = {while true {} 1}; //~ ERROR denote infinite loops with
67 #[deny(non_camel_case_types)]
68 type assoc_type; //~ ERROR associated type `assoc_type` should have an upper camel case name
71 impl AssociatedTrait for Associated {
74 fn denied_from_inner() { unsafe {} } //~ ERROR usage of an `unsafe` block
77 fn assoc_fn() { while true {} } //~ ERROR denote infinite loops with
80 const ASSOC_CONST: i32 = {while true {} 1}; //~ ERROR denote infinite loops with
82 #[deny(unused_parens)]
83 type assoc_type = (i32); //~ ERROR unnecessary parentheses around type
87 #[deny(unused_parens)]f1: (i32), //~ ERROR unnecessary parentheses around type
89 struct StructTuple(#[deny(unused_parens)](i32)); //~ ERROR unnecessary parentheses around type
92 #[deny(non_camel_case_types)]
93 VARIANT_CAMEL, //~ ERROR variant `VARIANT_CAMEL` should have an upper camel case name
97 #![deny(unused_parens)]
99 fn foreign_denied_from_inner(x: (i32)); //~ ERROR unnecessary parentheses around type
103 #[deny(unused_parens)]
104 fn foreign_denied_from_outer(x: (i32)); //~ ERROR unnecessary parentheses around type
107 fn function(#[deny(unused_parens)] param: (i32)) {} //~ ERROR unnecessary parentheses around type
109 fn generics<#[deny(non_camel_case_types)]foo>() {} //~ ERROR type parameter `foo` should have an upper camel case name
112 // ################## Statements
114 #[deny(unused_parens)]
115 let x = (1); //~ ERROR unnecessary parentheses around assigned value
119 // ################## Expressions
121 let closure = |#[deny(unused_parens)] param: (i32)| {}; //~ ERROR unnecessary parentheses around type
123 struct Match{f1: i32}
124 // Strangely unused_parens doesn't fire with {f1: (123)}
125 let f = Match{#[deny(unused_parens)]f1: {(123)}}; //~ ERROR unnecessary parentheses around block return value
128 #![deny(unsafe_code)]
132 unsafe {} //~ ERROR usage of an `unsafe` block
133 while true {} //~ ERROR denote infinite loops with
139 #![deny(unsafe_code)]
140 unsafe {} //~ ERROR usage of an `unsafe` block
144 unsafe {} //~ ERROR usage of an `unsafe` block
147 // Before expression as a statement.
149 unsafe {}; //~ ERROR usage of an `unsafe` block
151 [#[deny(unsafe_code)] unsafe {123}]; //~ ERROR usage of an `unsafe` block
152 (#[deny(unsafe_code)] unsafe {123},); //~ ERROR usage of an `unsafe` block
154 call(#[deny(unsafe_code)] unsafe {123}); //~ ERROR usage of an `unsafe` block
155 struct TupleStruct(i32);
156 TupleStruct(#[deny(unsafe_code)] unsafe {123}); //~ ERROR usage of an `unsafe` block
160 // ################## Patterns
162 struct PatField{f1: i32, f2: i32};
163 let f = PatField{f1: 1, f2: 2};
166 #[deny(ellipsis_inclusive_range_patterns)]
168 //~^ ERROR range patterns are deprecated
169 //~| WARNING this is accepted in the current edition