]> git.proxmox.com Git - rustc.git/blame - src/librustc/lint/builtin.rs
New upstream version 1.17.0+dfsg1
[rustc.git] / src / librustc / lint / builtin.rs
CommitLineData
c34b1796 1// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
1a4d82fc
JJ
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
c34b1796 11//! Some lints that are built in to the compiler.
1a4d82fc 12//!
c34b1796
AL
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`.
1a4d82fc 16
b039eaaf
SL
17use lint::{LintPass, LateLintPass, LintArray};
18
19declare_lint! {
20 pub CONST_ERR,
21 Warn,
22 "constant evaluation detected erroneous expression"
23}
1a4d82fc
JJ
24
25declare_lint! {
26 pub UNUSED_IMPORTS,
27 Warn,
28 "imports that are never used"
29}
30
31declare_lint! {
32 pub UNUSED_EXTERN_CRATES,
33 Allow,
34 "extern crates that are never used"
35}
36
37declare_lint! {
38 pub UNUSED_QUALIFICATIONS,
39 Allow,
40 "detects unnecessarily qualified names"
41}
42
43declare_lint! {
44 pub UNKNOWN_LINTS,
45 Warn,
46 "unrecognized lint attribute"
47}
48
49declare_lint! {
50 pub UNUSED_VARIABLES,
51 Warn,
52 "detect variables which are not used in any way"
53}
54
55declare_lint! {
56 pub UNUSED_ASSIGNMENTS,
57 Warn,
58 "detect assignments that will never be read"
59}
60
61declare_lint! {
62 pub DEAD_CODE,
63 Warn,
64 "detect unused, unexported items"
65}
66
67declare_lint! {
68 pub UNREACHABLE_CODE,
69 Warn,
70 "detects unreachable code paths"
71}
72
32a655c1
SL
73declare_lint! {
74 pub UNREACHABLE_PATTERNS,
75 Warn,
76 "detects unreachable patterns"
77}
78
1a4d82fc
JJ
79declare_lint! {
80 pub WARNINGS,
81 Warn,
82 "mass-change the level for lints which produce warnings"
83}
84
85declare_lint! {
85aaf69f
SL
86 pub UNUSED_FEATURES,
87 Warn,
88 "unused or unknown features found in crate-level #[feature] directives"
89}
90
91declare_lint! {
92 pub STABLE_FEATURES,
93 Warn,
94 "stable features found in #[feature] directive"
1a4d82fc
JJ
95}
96
97declare_lint! {
98 pub UNKNOWN_CRATE_TYPES,
99 Deny,
100 "unknown crate type found in #[crate_type] directive"
101}
102
1a4d82fc
JJ
103declare_lint! {
104 pub FAT_PTR_TRANSMUTES,
105 Allow,
106 "detects transmutes of fat pointers"
107}
108
109declare_lint! {
c34b1796 110 pub TRIVIAL_CASTS,
85aaf69f 111 Allow,
c34b1796 112 "detects trivial casts which could be removed"
1a4d82fc
JJ
113}
114
c34b1796
AL
115declare_lint! {
116 pub TRIVIAL_NUMERIC_CASTS,
117 Allow,
118 "detects trivial casts of numeric types which could be removed"
119}
92a42be0 120
9cc50fc6
SL
121declare_lint! {
122 pub PRIVATE_IN_PUBLIC,
123 Warn,
124 "detect private items in public interfaces not caught by the old implementation"
125}
126
7453a54e
SL
127declare_lint! {
128 pub INACCESSIBLE_EXTERN_CRATE,
c30ab7b3 129 Deny,
7453a54e
SL
130 "use of inaccessible extern crate erroneously allowed"
131}
132
9cc50fc6
SL
133declare_lint! {
134 pub INVALID_TYPE_PARAM_DEFAULT,
c30ab7b3 135 Deny,
9cc50fc6
SL
136 "type parameter default erroneously allowed in invalid location"
137}
138
54a0048b
SL
139declare_lint! {
140 pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
c30ab7b3 141 Deny,
54a0048b
SL
142 "floating-point constants cannot be used in patterns"
143}
144
145declare_lint! {
146 pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
c30ab7b3 147 Deny,
54a0048b
SL
148 "constants of struct or enum type can only be used in a pattern if \
149 the struct or enum has `#[derive(PartialEq, Eq)]`"
150}
151
92a42be0
SL
152declare_lint! {
153 pub RAW_POINTER_DERIVE,
154 Warn,
155 "uses of #[derive] with raw pointers are rarely correct"
156}
157
a7813a04
XL
158declare_lint! {
159 pub HR_LIFETIME_IN_ASSOC_TYPE,
476ff2be 160 Deny,
a7813a04
XL
161 "binding for associated type references higher-ranked lifetime \
162 that does not appear in the trait input types"
163}
164
54a0048b
SL
165declare_lint! {
166 pub OVERLAPPING_INHERENT_IMPLS,
c30ab7b3 167 Deny,
54a0048b
SL
168 "two overlapping inherent impls define an item with the same name were erroneously allowed"
169}
170
171declare_lint! {
172 pub RENAMED_AND_REMOVED_LINTS,
173 Warn,
174 "lints that have been renamed or removed"
175}
176
177declare_lint! {
178 pub SUPER_OR_SELF_IN_GLOBAL_PATH,
c30ab7b3 179 Deny,
54a0048b
SL
180 "detects super or self keywords at the beginning of global path"
181}
182
a7813a04 183declare_lint! {
9e0c209e 184 pub LIFETIME_UNDERSCORE,
c30ab7b3 185 Deny,
9e0c209e 186 "lifetimes or labels named `'_` were erroneously allowed"
a7813a04
XL
187}
188
8bb4bdeb
XL
189declare_lint! {
190 pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
191 Warn,
192 "attempt to resolve a trait on an expression whose type cannot be inferred but which \
193 currently defaults to ()"
194}
195
3157f602 196declare_lint! {
9e0c209e 197 pub SAFE_EXTERN_STATICS,
3157f602 198 Warn,
9e0c209e 199 "safe access to extern statics was erroneously allowed"
3157f602
XL
200}
201
c30ab7b3
SL
202declare_lint! {
203 pub PATTERNS_IN_FNS_WITHOUT_BODY,
204 Warn,
205 "patterns in functions without body were erroneously allowed"
206}
207
208declare_lint! {
209 pub EXTRA_REQUIREMENT_IN_IMPL,
32a655c1 210 Deny,
c30ab7b3
SL
211 "detects extra requirements in impls that were erroneously allowed"
212}
213
476ff2be
SL
214declare_lint! {
215 pub LEGACY_DIRECTORY_OWNERSHIP,
216 Warn,
217 "non-inline, non-`#[path]` modules (e.g. `mod foo;`) were erroneously allowed in some files \
218 not named `mod.rs`"
219}
220
221declare_lint! {
222 pub LEGACY_IMPORTS,
223 Warn,
224 "detects names that resolve to ambiguous glob imports with RFC 1560"
225}
226
8bb4bdeb
XL
227declare_lint! {
228 pub LEGACY_CONSTRUCTOR_VISIBILITY,
229 Deny,
230 "detects use of struct constructors that would be invisible with new visibility rules"
231}
232
233declare_lint! {
234 pub MISSING_FRAGMENT_SPECIFIER,
235 Warn,
236 "detects missing fragment specifiers in unused `macro_rules!` patterns"
237}
238
476ff2be
SL
239declare_lint! {
240 pub DEPRECATED,
241 Warn,
242 "detects use of deprecated items"
243}
244
1a4d82fc
JJ
245/// Does nothing as a lint pass, but registers some `Lint`s
246/// which are used by other parts of the compiler.
c34b1796 247#[derive(Copy, Clone)]
1a4d82fc
JJ
248pub struct HardwiredLints;
249
250impl LintPass for HardwiredLints {
251 fn get_lints(&self) -> LintArray {
252 lint_array!(
253 UNUSED_IMPORTS,
254 UNUSED_EXTERN_CRATES,
255 UNUSED_QUALIFICATIONS,
256 UNKNOWN_LINTS,
257 UNUSED_VARIABLES,
258 UNUSED_ASSIGNMENTS,
259 DEAD_CODE,
260 UNREACHABLE_CODE,
32a655c1 261 UNREACHABLE_PATTERNS,
1a4d82fc 262 WARNINGS,
85aaf69f
SL
263 UNUSED_FEATURES,
264 STABLE_FEATURES,
1a4d82fc 265 UNKNOWN_CRATE_TYPES,
c34b1796
AL
266 FAT_PTR_TRANSMUTES,
267 TRIVIAL_CASTS,
b039eaaf 268 TRIVIAL_NUMERIC_CASTS,
9cc50fc6 269 PRIVATE_IN_PUBLIC,
7453a54e 270 INACCESSIBLE_EXTERN_CRATE,
9cc50fc6 271 INVALID_TYPE_PARAM_DEFAULT,
54a0048b
SL
272 ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
273 ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
92a42be0 274 CONST_ERR,
54a0048b 275 RAW_POINTER_DERIVE,
54a0048b
SL
276 OVERLAPPING_INHERENT_IMPLS,
277 RENAMED_AND_REMOVED_LINTS,
a7813a04 278 SUPER_OR_SELF_IN_GLOBAL_PATH,
3157f602 279 HR_LIFETIME_IN_ASSOC_TYPE,
9e0c209e 280 LIFETIME_UNDERSCORE,
8bb4bdeb 281 RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
c30ab7b3
SL
282 SAFE_EXTERN_STATICS,
283 PATTERNS_IN_FNS_WITHOUT_BODY,
476ff2be
SL
284 EXTRA_REQUIREMENT_IN_IMPL,
285 LEGACY_DIRECTORY_OWNERSHIP,
286 LEGACY_IMPORTS,
8bb4bdeb
XL
287 LEGACY_CONSTRUCTOR_VISIBILITY,
288 MISSING_FRAGMENT_SPECIFIER,
476ff2be 289 DEPRECATED
1a4d82fc
JJ
290 )
291 }
292}
b039eaaf 293
476ff2be 294impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {}