]> git.lizzy.rs Git - rust.git/blob - src/librustc/lint/builtin.rs
Reexport -> re-export in error messages
[rust.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 UNREACHABLE_PATTERNS,
75     Warn,
76     "detects unreachable patterns"
77 }
78
79 declare_lint! {
80     pub UNUSED_MACROS,
81     Warn,
82     "detects macros that were not used"
83 }
84
85 declare_lint! {
86     pub WARNINGS,
87     Warn,
88     "mass-change the level for lints which produce warnings"
89 }
90
91 declare_lint! {
92     pub UNUSED_FEATURES,
93     Warn,
94     "unused or unknown features found in crate-level #[feature] directives"
95 }
96
97 declare_lint! {
98     pub STABLE_FEATURES,
99     Warn,
100     "stable features found in #[feature] directive"
101 }
102
103 declare_lint! {
104     pub UNKNOWN_CRATE_TYPES,
105     Deny,
106     "unknown crate type found in #[crate_type] directive"
107 }
108
109 declare_lint! {
110     pub TRIVIAL_CASTS,
111     Allow,
112     "detects trivial casts which could be removed"
113 }
114
115 declare_lint! {
116     pub TRIVIAL_NUMERIC_CASTS,
117     Allow,
118     "detects trivial casts of numeric types which could be removed"
119 }
120
121 declare_lint! {
122     pub PRIVATE_IN_PUBLIC,
123     Warn,
124     "detect private items in public interfaces not caught by the old implementation"
125 }
126
127 declare_lint! {
128     pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
129     Deny,
130     "detect public re-exports of private extern crates"
131 }
132
133 declare_lint! {
134     pub INVALID_TYPE_PARAM_DEFAULT,
135     Deny,
136     "type parameter default erroneously allowed in invalid location"
137 }
138
139 declare_lint! {
140     pub RENAMED_AND_REMOVED_LINTS,
141     Warn,
142     "lints that have been renamed or removed"
143 }
144
145 declare_lint! {
146     pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
147     Deny,
148     "attempt to resolve a trait on an expression whose type cannot be inferred but which \
149      currently defaults to ()"
150 }
151
152 declare_lint! {
153     pub SAFE_EXTERN_STATICS,
154     Deny,
155     "safe access to extern statics was erroneously allowed"
156 }
157
158 declare_lint! {
159     pub SAFE_PACKED_BORROWS,
160     Warn,
161     "safe borrows of fields of packed structs were was erroneously allowed"
162 }
163
164 declare_lint! {
165     pub PATTERNS_IN_FNS_WITHOUT_BODY,
166     Warn,
167     "patterns in functions without body were erroneously allowed"
168 }
169
170 declare_lint! {
171     pub LEGACY_DIRECTORY_OWNERSHIP,
172     Deny,
173     "non-inline, non-`#[path]` modules (e.g. `mod foo;`) were erroneously allowed in some files \
174      not named `mod.rs`"
175 }
176
177 declare_lint! {
178     pub LEGACY_IMPORTS,
179     Deny,
180     "detects names that resolve to ambiguous glob imports with RFC 1560"
181 }
182
183 declare_lint! {
184     pub LEGACY_CONSTRUCTOR_VISIBILITY,
185     Deny,
186     "detects use of struct constructors that would be invisible with new visibility rules"
187 }
188
189 declare_lint! {
190     pub MISSING_FRAGMENT_SPECIFIER,
191     Deny,
192     "detects missing fragment specifiers in unused `macro_rules!` patterns"
193 }
194
195 declare_lint! {
196     pub PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
197     Deny,
198     "detects parenthesized generic parameters in type and module names"
199 }
200
201 declare_lint! {
202     pub LATE_BOUND_LIFETIME_ARGUMENTS,
203     Warn,
204     "detects generic lifetime arguments in path segments with late bound lifetime parameters"
205 }
206
207 declare_lint! {
208     pub INCOHERENT_FUNDAMENTAL_IMPLS,
209     Warn,
210     "potentially-conflicting impls were erroneously allowed"
211 }
212
213 declare_lint! {
214     pub DEPRECATED,
215     Warn,
216     "detects use of deprecated items"
217 }
218
219 declare_lint! {
220     pub UNUSED_UNSAFE,
221     Warn,
222     "unnecessary use of an `unsafe` block"
223 }
224
225 declare_lint! {
226     pub UNUSED_MUT,
227     Warn,
228     "detect mut variables which don't need to be mutable"
229 }
230
231 declare_lint! {
232     pub COERCE_NEVER,
233     Deny,
234     "detect coercion to !"
235 }
236
237 declare_lint! {
238     pub SINGLE_USE_LIFETIME,
239     Allow,
240    "detects single use lifetimes"
241 }
242
243 declare_lint! {
244     pub TYVAR_BEHIND_RAW_POINTER,
245     Warn,
246     "raw pointer to an inference variable"
247 }
248
249 /// Does nothing as a lint pass, but registers some `Lint`s
250 /// which are used by other parts of the compiler.
251 #[derive(Copy, Clone)]
252 pub struct HardwiredLints;
253
254 impl LintPass for HardwiredLints {
255     fn get_lints(&self) -> LintArray {
256         lint_array!(
257             UNUSED_IMPORTS,
258             UNUSED_EXTERN_CRATES,
259             UNUSED_QUALIFICATIONS,
260             UNKNOWN_LINTS,
261             UNUSED_VARIABLES,
262             UNUSED_ASSIGNMENTS,
263             DEAD_CODE,
264             UNREACHABLE_CODE,
265             UNREACHABLE_PATTERNS,
266             UNUSED_MACROS,
267             WARNINGS,
268             UNUSED_FEATURES,
269             STABLE_FEATURES,
270             UNKNOWN_CRATE_TYPES,
271             TRIVIAL_CASTS,
272             TRIVIAL_NUMERIC_CASTS,
273             PRIVATE_IN_PUBLIC,
274             PUB_USE_OF_PRIVATE_EXTERN_CRATE,
275             INVALID_TYPE_PARAM_DEFAULT,
276             CONST_ERR,
277             RENAMED_AND_REMOVED_LINTS,
278             RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
279             SAFE_EXTERN_STATICS,
280             SAFE_PACKED_BORROWS,
281             PATTERNS_IN_FNS_WITHOUT_BODY,
282             LEGACY_DIRECTORY_OWNERSHIP,
283             LEGACY_IMPORTS,
284             LEGACY_CONSTRUCTOR_VISIBILITY,
285             MISSING_FRAGMENT_SPECIFIER,
286             PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES,
287             LATE_BOUND_LIFETIME_ARGUMENTS,
288             INCOHERENT_FUNDAMENTAL_IMPLS,
289             DEPRECATED,
290             UNUSED_UNSAFE,
291             UNUSED_MUT,
292             COERCE_NEVER,
293             SINGLE_USE_LIFETIME,
294             TYVAR_BEHIND_RAW_POINTER
295         )
296     }
297 }
298
299 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {}