]> git.lizzy.rs Git - rust.git/blob - src/librustc_lint/lib.rs
Fix typo in future incompatible lint
[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 #![unstable(feature = "rustc_private", issue = "27812")]
24 #![crate_type = "dylib"]
25 #![crate_type = "rlib"]
26 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
27       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
28       html_root_url = "https://doc.rust-lang.org/nightly/")]
29 #![cfg_attr(not(stage0), deny(warnings))]
30
31 #![cfg_attr(test, feature(test))]
32 #![feature(box_patterns)]
33 #![feature(box_syntax)]
34 #![feature(quote)]
35 #![feature(rustc_diagnostic_macros)]
36 #![feature(rustc_private)]
37 #![feature(slice_patterns)]
38 #![feature(staged_api)]
39
40 #[macro_use]
41 extern crate syntax;
42 #[macro_use]
43 extern crate rustc;
44 #[macro_use]
45 extern crate log;
46 extern crate rustc_back;
47 extern crate rustc_const_eval;
48
49 pub use rustc::lint as lint;
50 pub use rustc::middle as middle;
51 pub use rustc::session as session;
52 pub use rustc::util as util;
53
54 use session::Session;
55 use lint::LintId;
56 use lint::FutureIncompatibleInfo;
57
58 mod bad_style;
59 mod builtin;
60 mod types;
61 mod unused;
62
63 use bad_style::*;
64 use builtin::*;
65 use types::*;
66 use unused::*;
67
68 /// Tell the `LintStore` about all the built-in lints (the ones
69 /// defined in this crate and the ones defined in
70 /// `rustc::lint::builtin`).
71 pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
72     macro_rules! add_builtin {
73         ($sess:ident, $($name:ident),*,) => (
74             {$(
75                 store.register_late_pass($sess, false, box $name);
76                 )*}
77             )
78     }
79
80     macro_rules! add_early_builtin {
81         ($sess:ident, $($name:ident),*,) => (
82             {$(
83                 store.register_early_pass($sess, false, box $name);
84                 )*}
85             )
86     }
87
88     macro_rules! add_builtin_with_new {
89         ($sess:ident, $($name:ident),*,) => (
90             {$(
91                 store.register_late_pass($sess, false, box $name::new());
92                 )*}
93             )
94     }
95
96     macro_rules! add_lint_group {
97         ($sess:ident, $name:expr, $($lint:ident),*) => (
98             store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
99             )
100     }
101
102     add_early_builtin!(sess,
103                        UnusedParens,
104                        );
105
106     add_builtin!(sess,
107                  HardwiredLints,
108                  WhileTrue,
109                  ImproperCTypes,
110                  BoxPointers,
111                  UnusedAttributes,
112                  PathStatements,
113                  UnusedResults,
114                  NonCamelCaseTypes,
115                  NonSnakeCase,
116                  NonUpperCaseGlobals,
117                  UnusedImportBraces,
118                  NonShorthandFieldPatterns,
119                  UnusedUnsafe,
120                  UnsafeCode,
121                  UnusedMut,
122                  UnusedAllocation,
123                  MissingCopyImplementations,
124                  UnstableFeatures,
125                  Deprecated,
126                  UnconditionalRecursion,
127                  InvalidNoMangleItems,
128                  PluginAsLibrary,
129                  DropWithReprExtern,
130                  MutableTransmutes,
131                  );
132
133     add_builtin_with_new!(sess,
134                           TypeLimits,
135                           MissingDoc,
136                           MissingDebugImplementations,
137                           );
138
139     add_lint_group!(sess, "bad_style",
140                     NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPER_CASE_GLOBALS);
141
142     add_lint_group!(sess, "unused",
143                     UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
144                     UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
145                     UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);
146
147     // Guidelines for creating a future incompatibility lint:
148     //
149     // - Create a lint defaulting to warn as normal, with ideally the same error
150     //   message you would normally give
151     // - Add a suitable reference, typically an RFC or tracking issue. Go ahead
152     //   and include the full URL.
153     // - Later, change lint to error
154     // - Eventually, remove lint
155     store.register_future_incompatible(sess, vec![
156         FutureIncompatibleInfo {
157             id: LintId::of(PRIVATE_IN_PUBLIC),
158             reference: "the explanation for E0446 (`--explain E0446`)",
159         },
160         FutureIncompatibleInfo {
161             id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
162             reference: "PR 31362 <https://github.com/rust-lang/rust/pull/31362>",
163         },
164         FutureIncompatibleInfo {
165             id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
166             reference: "PR 30724 <https://github.com/rust-lang/rust/pull/30724>",
167         },
168         FutureIncompatibleInfo {
169             id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
170             reference: "PR #32403 <https://github.com/rust-lang/rust/pull/32403>",
171         },
172         FutureIncompatibleInfo {
173             id: LintId::of(MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT),
174             reference: "RFC 218 <https://github.com/rust-lang/rfcs/blob/\
175                         master/text/0218-empty-struct-with-braces.md>",
176         },
177         FutureIncompatibleInfo {
178             id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
179             reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
180         },
181         FutureIncompatibleInfo {
182             id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
183             reference: "issue #22889 <https://github.com/rust-lang/rust/issues/22889>",
184         },
185         FutureIncompatibleInfo {
186             id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
187             reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
188         },
189         FutureIncompatibleInfo {
190             id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
191             reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
192         },
193         FutureIncompatibleInfo {
194             id: LintId::of(UNSIZED_IN_TUPLE),
195             reference: "issue #33242 <https://github.com/rust-lang/rust/issues/33242>",
196         },
197         FutureIncompatibleInfo {
198             id: LintId::of(OBJECT_UNSAFE_FRAGMENT),
199             reference: "issue #33243 <https://github.com/rust-lang/rust/issues/33243>",
200         },
201         FutureIncompatibleInfo {
202             id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE),
203             reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>",
204         },
205         FutureIncompatibleInfo {
206             id: LintId::of(LIFETIME_UNDERSCORE),
207             reference: "RFC 1177 <https://github.com/rust-lang/rfcs/pull/1177>",
208         },
209         ]);
210
211     // We have one lint pass defined specially
212     store.register_late_pass(sess, false, box lint::GatherNodeLevels);
213
214     // Register renamed and removed lints
215     store.register_renamed("unknown_features", "unused_features");
216     store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
217     store.register_removed("negate_unsigned", "cast a signed value instead");
218     store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok");
219     // This was renamed to raw_pointer_derive, which was then removed,
220     // so it is also considered removed
221     store.register_removed("raw_pointer_deriving", "using derive with raw pointers is ok");
222 }