]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
1 | // Copyright 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 | //! Lints in the Rust compiler. | |
12 | //! | |
13 | //! This currently only contains the definitions and implementations | |
14 | //! of most of the lints that `rustc` supports directly, it does not | |
15 | //! contain the infrastructure for defining/registering lints. That is | |
92a42be0 | 16 | //! available in `rustc::lint` and `rustc_plugin` respectively. |
c34b1796 AL |
17 | //! |
18 | //! # Note | |
19 | //! | |
20 | //! This API is completely unstable and subject to change. | |
21 | ||
c34b1796 | 22 | #![crate_name = "rustc_lint"] |
e9174d1e | 23 | #![unstable(feature = "rustc_private", issue = "27812")] |
c34b1796 AL |
24 | #![crate_type = "dylib"] |
25 | #![crate_type = "rlib"] | |
e9174d1e | 26 | #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", |
62682a34 | 27 | html_favicon_url = "https://doc.rust-lang.org/favicon.ico", |
e9174d1e | 28 | html_root_url = "https://doc.rust-lang.org/nightly/")] |
32a655c1 | 29 | #![deny(warnings)] |
c34b1796 | 30 | |
62682a34 | 31 | #![cfg_attr(test, feature(test))] |
c34b1796 AL |
32 | #![feature(box_patterns)] |
33 | #![feature(box_syntax)] | |
8bb4bdeb | 34 | #![feature(i128_type)] |
c34b1796 AL |
35 | #![feature(quote)] |
36 | #![feature(rustc_diagnostic_macros)] | |
37 | #![feature(rustc_private)] | |
c1a9b12d | 38 | #![feature(slice_patterns)] |
c34b1796 | 39 | #![feature(staged_api)] |
c34b1796 AL |
40 | |
41 | extern crate syntax; | |
42 | #[macro_use] | |
43 | extern crate rustc; | |
44 | #[macro_use] | |
45 | extern crate log; | |
b039eaaf | 46 | extern crate rustc_back; |
54a0048b | 47 | extern crate rustc_const_eval; |
3157f602 | 48 | extern crate syntax_pos; |
c34b1796 | 49 | |
c30ab7b3 SL |
50 | pub use rustc::lint; |
51 | pub use rustc::middle; | |
52 | pub use rustc::session; | |
53 | pub use rustc::util; | |
c34b1796 AL |
54 | |
55 | use session::Session; | |
56 | use lint::LintId; | |
9cc50fc6 | 57 | use lint::FutureIncompatibleInfo; |
c34b1796 | 58 | |
b039eaaf | 59 | mod bad_style; |
c34b1796 | 60 | mod builtin; |
b039eaaf SL |
61 | mod types; |
62 | mod unused; | |
63 | ||
64 | use bad_style::*; | |
65 | use builtin::*; | |
66 | use types::*; | |
67 | use unused::*; | |
c34b1796 AL |
68 | |
69 | /// Tell the `LintStore` about all the built-in lints (the ones | |
70 | /// defined in this crate and the ones defined in | |
71 | /// `rustc::lint::builtin`). | |
72 | pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { | |
73 | macro_rules! add_builtin { | |
74 | ($sess:ident, $($name:ident),*,) => ( | |
75 | {$( | |
b039eaaf SL |
76 | store.register_late_pass($sess, false, box $name); |
77 | )*} | |
78 | ) | |
79 | } | |
80 | ||
81 | macro_rules! add_early_builtin { | |
82 | ($sess:ident, $($name:ident),*,) => ( | |
83 | {$( | |
84 | store.register_early_pass($sess, false, box $name); | |
c34b1796 AL |
85 | )*} |
86 | ) | |
87 | } | |
88 | ||
89 | macro_rules! add_builtin_with_new { | |
90 | ($sess:ident, $($name:ident),*,) => ( | |
91 | {$( | |
b039eaaf | 92 | store.register_late_pass($sess, false, box $name::new()); |
c34b1796 AL |
93 | )*} |
94 | ) | |
95 | } | |
96 | ||
c30ab7b3 SL |
97 | macro_rules! add_early_builtin_with_new { |
98 | ($sess:ident, $($name:ident),*,) => ( | |
99 | {$( | |
100 | store.register_early_pass($sess, false, box $name::new()); | |
101 | )*} | |
102 | ) | |
103 | } | |
104 | ||
c34b1796 AL |
105 | macro_rules! add_lint_group { |
106 | ($sess:ident, $name:expr, $($lint:ident),*) => ( | |
b039eaaf | 107 | store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]); |
c34b1796 AL |
108 | ) |
109 | } | |
110 | ||
b039eaaf SL |
111 | add_early_builtin!(sess, |
112 | UnusedParens, | |
476ff2be | 113 | UnusedImportBraces, |
b039eaaf SL |
114 | ); |
115 | ||
c30ab7b3 SL |
116 | add_early_builtin_with_new!(sess, |
117 | DeprecatedAttr, | |
118 | ); | |
119 | ||
c34b1796 AL |
120 | add_builtin!(sess, |
121 | HardwiredLints, | |
122 | WhileTrue, | |
123 | ImproperCTypes, | |
5bcae85e | 124 | VariantSizeDifferences, |
c34b1796 AL |
125 | BoxPointers, |
126 | UnusedAttributes, | |
127 | PathStatements, | |
128 | UnusedResults, | |
129 | NonCamelCaseTypes, | |
130 | NonSnakeCase, | |
131 | NonUpperCaseGlobals, | |
c34b1796 AL |
132 | NonShorthandFieldPatterns, |
133 | UnusedUnsafe, | |
134 | UnsafeCode, | |
135 | UnusedMut, | |
136 | UnusedAllocation, | |
137 | MissingCopyImplementations, | |
138 | UnstableFeatures, | |
c34b1796 AL |
139 | UnconditionalRecursion, |
140 | InvalidNoMangleItems, | |
141 | PluginAsLibrary, | |
bd371182 | 142 | MutableTransmutes, |
9e0c209e | 143 | UnionsWithDropFields, |
c34b1796 AL |
144 | ); |
145 | ||
146 | add_builtin_with_new!(sess, | |
147 | TypeLimits, | |
c34b1796 AL |
148 | MissingDoc, |
149 | MissingDebugImplementations, | |
150 | ); | |
151 | ||
c30ab7b3 SL |
152 | add_lint_group!(sess, |
153 | "bad_style", | |
154 | NON_CAMEL_CASE_TYPES, | |
155 | NON_SNAKE_CASE, | |
156 | NON_UPPER_CASE_GLOBALS); | |
157 | ||
158 | add_lint_group!(sess, | |
159 | "unused", | |
160 | UNUSED_IMPORTS, | |
161 | UNUSED_VARIABLES, | |
162 | UNUSED_ASSIGNMENTS, | |
163 | DEAD_CODE, | |
164 | UNUSED_MUT, | |
165 | UNREACHABLE_CODE, | |
32a655c1 | 166 | UNREACHABLE_PATTERNS, |
c30ab7b3 SL |
167 | UNUSED_MUST_USE, |
168 | UNUSED_UNSAFE, | |
169 | PATH_STATEMENTS, | |
170 | UNUSED_ATTRIBUTES); | |
c34b1796 | 171 | |
9cc50fc6 SL |
172 | // Guidelines for creating a future incompatibility lint: |
173 | // | |
174 | // - Create a lint defaulting to warn as normal, with ideally the same error | |
175 | // message you would normally give | |
176 | // - Add a suitable reference, typically an RFC or tracking issue. Go ahead | |
177 | // and include the full URL. | |
178 | // - Later, change lint to error | |
179 | // - Eventually, remove lint | |
c30ab7b3 SL |
180 | store.register_future_incompatible(sess, |
181 | vec![ | |
9cc50fc6 SL |
182 | FutureIncompatibleInfo { |
183 | id: LintId::of(PRIVATE_IN_PUBLIC), | |
5bcae85e | 184 | reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>", |
9cc50fc6 | 185 | }, |
7453a54e SL |
186 | FutureIncompatibleInfo { |
187 | id: LintId::of(INACCESSIBLE_EXTERN_CRATE), | |
c30ab7b3 | 188 | reference: "issue #36886 <https://github.com/rust-lang/rust/issues/36886>", |
7453a54e | 189 | }, |
9cc50fc6 SL |
190 | FutureIncompatibleInfo { |
191 | id: LintId::of(INVALID_TYPE_PARAM_DEFAULT), | |
c30ab7b3 | 192 | reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>", |
9cc50fc6 | 193 | }, |
54a0048b SL |
194 | FutureIncompatibleInfo { |
195 | id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH), | |
c30ab7b3 | 196 | reference: "issue #36888 <https://github.com/rust-lang/rust/issues/36888>", |
9cc50fc6 | 197 | }, |
54a0048b SL |
198 | FutureIncompatibleInfo { |
199 | id: LintId::of(OVERLAPPING_INHERENT_IMPLS), | |
c30ab7b3 | 200 | reference: "issue #36889 <https://github.com/rust-lang/rust/issues/36889>", |
54a0048b SL |
201 | }, |
202 | FutureIncompatibleInfo { | |
203 | id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN), | |
c30ab7b3 | 204 | reference: "issue #36890 <https://github.com/rust-lang/rust/issues/36890>", |
54a0048b SL |
205 | }, |
206 | FutureIncompatibleInfo { | |
207 | id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN), | |
c30ab7b3 | 208 | reference: "issue #36891 <https://github.com/rust-lang/rust/issues/36891>", |
54a0048b | 209 | }, |
a7813a04 XL |
210 | FutureIncompatibleInfo { |
211 | id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE), | |
212 | reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>", | |
213 | }, | |
3157f602 XL |
214 | FutureIncompatibleInfo { |
215 | id: LintId::of(LIFETIME_UNDERSCORE), | |
c30ab7b3 | 216 | reference: "issue #36892 <https://github.com/rust-lang/rust/issues/36892>", |
3157f602 | 217 | }, |
8bb4bdeb XL |
218 | FutureIncompatibleInfo { |
219 | id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT), | |
220 | reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>", | |
221 | }, | |
9e0c209e SL |
222 | FutureIncompatibleInfo { |
223 | id: LintId::of(SAFE_EXTERN_STATICS), | |
c30ab7b3 SL |
224 | reference: "issue #36247 <https://github.com/rust-lang/rust/issues/35112>", |
225 | }, | |
226 | FutureIncompatibleInfo { | |
227 | id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY), | |
228 | reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>", | |
229 | }, | |
230 | FutureIncompatibleInfo { | |
231 | id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL), | |
232 | reference: "issue #37166 <https://github.com/rust-lang/rust/issues/37166>", | |
9e0c209e | 233 | }, |
476ff2be SL |
234 | FutureIncompatibleInfo { |
235 | id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP), | |
236 | reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>", | |
237 | }, | |
238 | FutureIncompatibleInfo { | |
239 | id: LintId::of(LEGACY_IMPORTS), | |
240 | reference: "issue #38260 <https://github.com/rust-lang/rust/issues/38260>", | |
241 | }, | |
8bb4bdeb XL |
242 | FutureIncompatibleInfo { |
243 | id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY), | |
244 | reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>", | |
245 | }, | |
246 | FutureIncompatibleInfo { | |
247 | id: LintId::of(MISSING_FRAGMENT_SPECIFIER), | |
248 | reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>", | |
249 | }, | |
9cc50fc6 | 250 | ]); |
92a42be0 | 251 | |
92a42be0 | 252 | // Register renamed and removed lints |
c34b1796 | 253 | store.register_renamed("unknown_features", "unused_features"); |
c30ab7b3 SL |
254 | store.register_removed("unsigned_negation", |
255 | "replaced by negate_unsigned feature gate"); | |
9cc50fc6 | 256 | store.register_removed("negate_unsigned", "cast a signed value instead"); |
92a42be0 SL |
257 | store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok"); |
258 | // This was renamed to raw_pointer_derive, which was then removed, | |
259 | // so it is also considered removed | |
c30ab7b3 SL |
260 | store.register_removed("raw_pointer_deriving", |
261 | "using derive with raw pointers is ok"); | |
9e0c209e | 262 | store.register_removed("drop_with_repr_extern", "drop flags have been removed"); |
8bb4bdeb XL |
263 | store.register_removed("transmute_from_fn_item_types", |
264 | "always cast functions before transmuting them"); | |
c34b1796 | 265 | } |