]> git.proxmox.com Git - rustc.git/blob - src/librustc/lint/builtin.rs
New upstream version 1.14.0+dfsg1
[rustc.git] / src / librustc / lint / builtin.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Some lints that are built in to the compiler.
12 //!
13 //! These are the built-in lints that are emitted direct in the main
14 //! compiler code, rather than using their own custom pass. Those
15 //! lints are all available in `rustc_lint::builtin`.
16
17 use lint::{LintPass, LateLintPass, LintArray};
18
19 declare_lint! {
20 pub CONST_ERR,
21 Warn,
22 "constant evaluation detected erroneous expression"
23 }
24
25 declare_lint! {
26 pub UNUSED_IMPORTS,
27 Warn,
28 "imports that are never used"
29 }
30
31 declare_lint! {
32 pub UNUSED_EXTERN_CRATES,
33 Allow,
34 "extern crates that are never used"
35 }
36
37 declare_lint! {
38 pub UNUSED_QUALIFICATIONS,
39 Allow,
40 "detects unnecessarily qualified names"
41 }
42
43 declare_lint! {
44 pub UNKNOWN_LINTS,
45 Warn,
46 "unrecognized lint attribute"
47 }
48
49 declare_lint! {
50 pub UNUSED_VARIABLES,
51 Warn,
52 "detect variables which are not used in any way"
53 }
54
55 declare_lint! {
56 pub UNUSED_ASSIGNMENTS,
57 Warn,
58 "detect assignments that will never be read"
59 }
60
61 declare_lint! {
62 pub DEAD_CODE,
63 Warn,
64 "detect unused, unexported items"
65 }
66
67 declare_lint! {
68 pub UNREACHABLE_CODE,
69 Warn,
70 "detects unreachable code paths"
71 }
72
73 declare_lint! {
74 pub WARNINGS,
75 Warn,
76 "mass-change the level for lints which produce warnings"
77 }
78
79 declare_lint! {
80 pub UNUSED_FEATURES,
81 Warn,
82 "unused or unknown features found in crate-level #[feature] directives"
83 }
84
85 declare_lint! {
86 pub STABLE_FEATURES,
87 Warn,
88 "stable features found in #[feature] directive"
89 }
90
91 declare_lint! {
92 pub UNKNOWN_CRATE_TYPES,
93 Deny,
94 "unknown crate type found in #[crate_type] directive"
95 }
96
97 declare_lint! {
98 pub FAT_PTR_TRANSMUTES,
99 Allow,
100 "detects transmutes of fat pointers"
101 }
102
103 declare_lint! {
104 pub TRIVIAL_CASTS,
105 Allow,
106 "detects trivial casts which could be removed"
107 }
108
109 declare_lint! {
110 pub TRIVIAL_NUMERIC_CASTS,
111 Allow,
112 "detects trivial casts of numeric types which could be removed"
113 }
114
115 declare_lint! {
116 pub PRIVATE_IN_PUBLIC,
117 Warn,
118 "detect private items in public interfaces not caught by the old implementation"
119 }
120
121 declare_lint! {
122 pub INACCESSIBLE_EXTERN_CRATE,
123 Deny,
124 "use of inaccessible extern crate erroneously allowed"
125 }
126
127 declare_lint! {
128 pub INVALID_TYPE_PARAM_DEFAULT,
129 Deny,
130 "type parameter default erroneously allowed in invalid location"
131 }
132
133 declare_lint! {
134 pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
135 Deny,
136 "floating-point constants cannot be used in patterns"
137 }
138
139 declare_lint! {
140 pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
141 Deny,
142 "constants of struct or enum type can only be used in a pattern if \
143 the struct or enum has `#[derive(PartialEq, Eq)]`"
144 }
145
146 declare_lint! {
147 pub RAW_POINTER_DERIVE,
148 Warn,
149 "uses of #[derive] with raw pointers are rarely correct"
150 }
151
152 declare_lint! {
153 pub TRANSMUTE_FROM_FN_ITEM_TYPES,
154 Deny,
155 "transmute from function item type to pointer-sized type erroneously allowed"
156 }
157
158 declare_lint! {
159 pub HR_LIFETIME_IN_ASSOC_TYPE,
160 Warn,
161 "binding for associated type references higher-ranked lifetime \
162 that does not appear in the trait input types"
163 }
164
165 declare_lint! {
166 pub OVERLAPPING_INHERENT_IMPLS,
167 Deny,
168 "two overlapping inherent impls define an item with the same name were erroneously allowed"
169 }
170
171 declare_lint! {
172 pub RENAMED_AND_REMOVED_LINTS,
173 Warn,
174 "lints that have been renamed or removed"
175 }
176
177 declare_lint! {
178 pub SUPER_OR_SELF_IN_GLOBAL_PATH,
179 Deny,
180 "detects super or self keywords at the beginning of global path"
181 }
182
183 declare_lint! {
184 pub LIFETIME_UNDERSCORE,
185 Deny,
186 "lifetimes or labels named `'_` were erroneously allowed"
187 }
188
189 declare_lint! {
190 pub SAFE_EXTERN_STATICS,
191 Warn,
192 "safe access to extern statics was erroneously allowed"
193 }
194
195 declare_lint! {
196 pub PATTERNS_IN_FNS_WITHOUT_BODY,
197 Warn,
198 "patterns in functions without body were erroneously allowed"
199 }
200
201 declare_lint! {
202 pub EXTRA_REQUIREMENT_IN_IMPL,
203 Warn,
204 "detects extra requirements in impls that were erroneously allowed"
205 }
206
207 /// Does nothing as a lint pass, but registers some `Lint`s
208 /// which are used by other parts of the compiler.
209 #[derive(Copy, Clone)]
210 pub struct HardwiredLints;
211
212 impl LintPass for HardwiredLints {
213 fn get_lints(&self) -> LintArray {
214 lint_array!(
215 UNUSED_IMPORTS,
216 UNUSED_EXTERN_CRATES,
217 UNUSED_QUALIFICATIONS,
218 UNKNOWN_LINTS,
219 UNUSED_VARIABLES,
220 UNUSED_ASSIGNMENTS,
221 DEAD_CODE,
222 UNREACHABLE_CODE,
223 WARNINGS,
224 UNUSED_FEATURES,
225 STABLE_FEATURES,
226 UNKNOWN_CRATE_TYPES,
227 FAT_PTR_TRANSMUTES,
228 TRIVIAL_CASTS,
229 TRIVIAL_NUMERIC_CASTS,
230 PRIVATE_IN_PUBLIC,
231 INACCESSIBLE_EXTERN_CRATE,
232 INVALID_TYPE_PARAM_DEFAULT,
233 ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
234 ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
235 CONST_ERR,
236 RAW_POINTER_DERIVE,
237 TRANSMUTE_FROM_FN_ITEM_TYPES,
238 OVERLAPPING_INHERENT_IMPLS,
239 RENAMED_AND_REMOVED_LINTS,
240 SUPER_OR_SELF_IN_GLOBAL_PATH,
241 HR_LIFETIME_IN_ASSOC_TYPE,
242 LIFETIME_UNDERSCORE,
243 SAFE_EXTERN_STATICS,
244 PATTERNS_IN_FNS_WITHOUT_BODY,
245 EXTRA_REQUIREMENT_IN_IMPL
246 )
247 }
248 }
249
250 impl LateLintPass for HardwiredLints {}