]>
Commit | Line | Data |
---|---|---|
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 |
17 | use lint::{LintPass, LateLintPass, LintArray}; |
18 | ||
19 | declare_lint! { | |
20 | pub CONST_ERR, | |
21 | Warn, | |
22 | "constant evaluation detected erroneous expression" | |
23 | } | |
1a4d82fc JJ |
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! { | |
85aaf69f SL |
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" | |
1a4d82fc JJ |
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 VARIANT_SIZE_DIFFERENCES, | |
99 | Allow, | |
100 | "detects enums with widely varying variant sizes" | |
101 | } | |
102 | ||
103 | declare_lint! { | |
104 | pub FAT_PTR_TRANSMUTES, | |
105 | Allow, | |
106 | "detects transmutes of fat pointers" | |
107 | } | |
108 | ||
109 | declare_lint! { | |
c34b1796 | 110 | pub TRIVIAL_CASTS, |
85aaf69f | 111 | Allow, |
c34b1796 | 112 | "detects trivial casts which could be removed" |
1a4d82fc JJ |
113 | } |
114 | ||
c34b1796 AL |
115 | declare_lint! { |
116 | pub TRIVIAL_NUMERIC_CASTS, | |
117 | Allow, | |
118 | "detects trivial casts of numeric types which could be removed" | |
119 | } | |
92a42be0 | 120 | |
9cc50fc6 SL |
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 | ||
7453a54e SL |
127 | declare_lint! { |
128 | pub INACCESSIBLE_EXTERN_CRATE, | |
129 | Warn, | |
130 | "use of inaccessible extern crate erroneously allowed" | |
131 | } | |
132 | ||
9cc50fc6 SL |
133 | declare_lint! { |
134 | pub INVALID_TYPE_PARAM_DEFAULT, | |
135 | Warn, | |
136 | "type parameter default erroneously allowed in invalid location" | |
137 | } | |
138 | ||
54a0048b SL |
139 | declare_lint! { |
140 | pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN, | |
141 | Warn, | |
142 | "floating-point constants cannot be used in patterns" | |
143 | } | |
144 | ||
145 | declare_lint! { | |
146 | pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN, | |
147 | Warn, | |
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 |
152 | declare_lint! { |
153 | pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT, | |
7453a54e | 154 | Deny, |
92a42be0 SL |
155 | "unit struct or enum variant erroneously allowed to match via path::ident(..)" |
156 | } | |
157 | ||
158 | declare_lint! { | |
159 | pub RAW_POINTER_DERIVE, | |
160 | Warn, | |
161 | "uses of #[derive] with raw pointers are rarely correct" | |
162 | } | |
163 | ||
54a0048b SL |
164 | declare_lint! { |
165 | pub TRANSMUTE_FROM_FN_ITEM_TYPES, | |
166 | Warn, | |
167 | "transmute from function item type to pointer-sized type erroneously allowed" | |
168 | } | |
169 | ||
170 | declare_lint! { | |
171 | pub OVERLAPPING_INHERENT_IMPLS, | |
172 | Warn, | |
173 | "two overlapping inherent impls define an item with the same name were erroneously allowed" | |
174 | } | |
175 | ||
176 | declare_lint! { | |
177 | pub RENAMED_AND_REMOVED_LINTS, | |
178 | Warn, | |
179 | "lints that have been renamed or removed" | |
180 | } | |
181 | ||
182 | declare_lint! { | |
183 | pub SUPER_OR_SELF_IN_GLOBAL_PATH, | |
184 | Warn, | |
185 | "detects super or self keywords at the beginning of global path" | |
186 | } | |
187 | ||
1a4d82fc JJ |
188 | /// Does nothing as a lint pass, but registers some `Lint`s |
189 | /// which are used by other parts of the compiler. | |
c34b1796 | 190 | #[derive(Copy, Clone)] |
1a4d82fc JJ |
191 | pub struct HardwiredLints; |
192 | ||
193 | impl LintPass for HardwiredLints { | |
194 | fn get_lints(&self) -> LintArray { | |
195 | lint_array!( | |
196 | UNUSED_IMPORTS, | |
197 | UNUSED_EXTERN_CRATES, | |
198 | UNUSED_QUALIFICATIONS, | |
199 | UNKNOWN_LINTS, | |
200 | UNUSED_VARIABLES, | |
201 | UNUSED_ASSIGNMENTS, | |
202 | DEAD_CODE, | |
203 | UNREACHABLE_CODE, | |
204 | WARNINGS, | |
85aaf69f SL |
205 | UNUSED_FEATURES, |
206 | STABLE_FEATURES, | |
1a4d82fc JJ |
207 | UNKNOWN_CRATE_TYPES, |
208 | VARIANT_SIZE_DIFFERENCES, | |
c34b1796 AL |
209 | FAT_PTR_TRANSMUTES, |
210 | TRIVIAL_CASTS, | |
b039eaaf | 211 | TRIVIAL_NUMERIC_CASTS, |
9cc50fc6 | 212 | PRIVATE_IN_PUBLIC, |
7453a54e | 213 | INACCESSIBLE_EXTERN_CRATE, |
9cc50fc6 | 214 | INVALID_TYPE_PARAM_DEFAULT, |
54a0048b SL |
215 | ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN, |
216 | ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN, | |
92a42be0 SL |
217 | MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT, |
218 | CONST_ERR, | |
54a0048b SL |
219 | RAW_POINTER_DERIVE, |
220 | TRANSMUTE_FROM_FN_ITEM_TYPES, | |
221 | OVERLAPPING_INHERENT_IMPLS, | |
222 | RENAMED_AND_REMOVED_LINTS, | |
223 | SUPER_OR_SELF_IN_GLOBAL_PATH | |
1a4d82fc JJ |
224 | ) |
225 | } | |
226 | } | |
b039eaaf SL |
227 | |
228 | impl LateLintPass for HardwiredLints {} |