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