]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/lint-attr-everywhere-late.rs
Rollup merge of #100559 - nnethercote:parser-simplifications, r=compiler-errors
[rust.git] / src / test / ui / lint / lint-attr-everywhere-late.rs
1 // Tests that lint levels can be set for late lints.
2 #![allow(
3     non_snake_case,
4     overflowing_literals,
5     missing_docs,
6     dyn_drop,
7     enum_intrinsics_non_enums,
8     clashing_extern_declarations
9 )]
10
11 extern crate core;
12 use core::mem::{Discriminant, discriminant};
13
14 // The following is a check of the lints used here to verify they do not warn
15 // when allowed.
16 pub fn missing_docs_allowed() {} // missing_docs
17 fn dyn_drop_allowed(_x: Box<dyn Drop>) {} // dyn_drop
18 fn verify_no_warnings() {
19     discriminant::<i32>(&123); // enum_intrinsics_non_enums
20     let x: u8 = 1000; // overflowing_literals
21     let NON_SNAKE_CASE = 1; // non_snake_case
22 }
23 mod clashing_extern_allowed {
24     extern "C" {
25         fn extern_allowed();
26     }
27 }
28 extern "C" {
29     fn extern_allowed(_: i32); // clashing_extern_declarations
30 }
31
32 // ################## Types
33
34 #[deny(missing_docs)]
35 pub type MissingDocType = i32; //~ ERROR missing documentation for a type alias
36
37 // There aren't any late lints that I can find that can be easily used with types.
38 // type BareFnPtr = fn(#[deny()]i32);
39 // type BareFnPtrVariadic = extern "C" fn(i32, #[deny()]...);
40
41 // ################## Items
42 #[deny(missing_docs)]
43 pub struct ItemOuter; //~ ERROR missing documentation for a struct
44
45 pub mod module_inner { //~ ERROR missing documentation for a module
46     #![deny(missing_docs)]
47     pub fn missing_inner() {} //~ ERROR missing documentation for a function
48 }
49
50 pub struct Associated;
51 impl Associated {
52     #![deny(missing_docs)]
53
54     pub fn inherent_denied_from_inner() {} //~ ERROR missing documentation for an associated function
55 }
56
57 impl Associated {
58     #[deny(missing_docs)]
59     pub fn inherent_fn() {} //~ ERROR missing documentation for an associated function
60
61     #[deny(missing_docs)]
62     pub const INHERENT_CONST: i32 = 1; //~ ERROR missing documentation for an associated constant
63 }
64
65 pub trait TraitInner { //~ ERROR missing documentation for a trait
66     #![deny(missing_docs)]
67 }
68
69 pub trait AssociatedTraitInner { //~ ERROR missing documentation for a trait
70     #![deny(missing_docs)]
71
72     fn denied_from_inner() {} //~ ERROR missing documentation for an associated function
73 }
74
75 pub trait AssociatedTrait {
76     fn denied_from_inner(_x: Box<dyn Drop>) {} // Used below
77
78     #[deny(missing_docs)]
79     fn assoc_fn() {} //~ ERROR missing documentation for an associated function
80
81     #[deny(missing_docs)]
82     const ASSOC_CONST: u8 = 1; //~ ERROR missing documentation for an associated constant
83
84     #[deny(missing_docs)]
85     type AssocType; //~ ERROR missing documentation for an associated type
86 }
87
88 struct Foo;
89
90 impl AssociatedTrait for Associated {
91     #![deny(dyn_drop)]
92
93     fn denied_from_inner(_x: Box<dyn Drop>) {} //~ ERROR types that do not implement `Drop`
94
95     #[deny(enum_intrinsics_non_enums)]
96     fn assoc_fn() { discriminant::<i32>(&123); } //~ ERROR the return value of
97
98     #[deny(overflowing_literals)] const ASSOC_CONST: u8 = 1000; //~ ERROR literal out of range
99     type AssocType = i32;
100 }
101
102
103 // There aren't any late lints that can apply to a field that I can find.
104 // non_snake_case doesn't work on fields
105 // struct StructFields {
106 //     #[deny()]f1: i32,
107 // }
108 // struct StructTuple(#[deny()]i32);
109
110 pub enum Enum {
111     #[deny(missing_docs)]
112     Variant1, //~ ERROR missing documentation for a variant
113 }
114
115 mod clashing_extern {
116     extern "C" {
117         fn clashing1();
118         fn clashing2();
119     }
120 }
121 extern "C" {
122     #![deny(clashing_extern_declarations)]
123     fn clashing1(_: i32); //~ ERROR `clashing1` redeclared with a different signature
124 }
125
126 extern "C" {
127     #[deny(clashing_extern_declarations)]
128     fn clashing2(_: i32); //~ ERROR `clashing2` redeclared with a different signature
129 }
130
131 fn function(#[deny(non_snake_case)] PARAM: i32) {} //~ ERROR variable `PARAM` should have a snake case name
132 // There aren't any late lints that can apply to generics that I can find.
133 // fn generics<#[deny()]T>() {}
134
135
136 // ################## Statements
137 fn statements() {
138     #[deny(enum_intrinsics_non_enums)]
139     let _ = discriminant::<i32>(&123); //~ ERROR the return value of
140 }
141
142
143 // ################## Expressions
144 fn expressions() {
145     let closure = |#[deny(non_snake_case)] PARAM: i32| {}; //~ ERROR variable `PARAM` should have a snake case name
146
147     struct Match{f1: i32}
148     // I can't find any late lints for patterns.
149     // let f = Match{#[deny()]f1: 123};
150
151     let f = Match{f1: 123};
152     match f {
153         #![deny(enum_intrinsics_non_enums)]
154         Match{f1} => {
155             discriminant::<i32>(&123); //~ ERROR the return value of
156         }
157     }
158     match f {
159         #[deny(enum_intrinsics_non_enums)]
160         Match{f1} => {
161             discriminant::<i32>(&123); //~ ERROR the return value of
162         }
163     }
164
165     // Statement Block
166     {
167         #![deny(enum_intrinsics_non_enums)]
168         discriminant::<i32>(&123); //~ ERROR the return value of
169     }
170     let block_tail = {
171         #[deny(enum_intrinsics_non_enums)]
172         discriminant::<i32>(&123); //~ ERROR the return value of
173     };
174
175     // Before expression as a statement.
176     #[deny(enum_intrinsics_non_enums)]
177     discriminant::<i32>(&123); //~ ERROR the return value of
178
179     [#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)]; //~ ERROR the return value of
180     (#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123),); //~ ERROR the return value of
181     fn call(p: Discriminant<i32>) {}
182     call(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)); //~ ERROR the return value of
183     struct TupleStruct(Discriminant<i32>);
184     TupleStruct(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)); //~ ERROR the return value of
185 }
186
187
188 // ################## Patterns
189 fn patterns() {
190     // There aren't any late lints that I can find that apply to pattern fields.
191     //
192     // struct PatField{f1: i32, f2: i32};
193     // let f = PatField{f1: 1, f2: 2};
194     // let PatField{#[deny()]f1, #[deny()]..} = f;
195 }
196
197 fn main() {}