]> git.lizzy.rs Git - rust.git/blob - src/librustc_lint/lib.rs
Auto merge of #30413 - pnkfelix:fsk-span_note, r=Manishearth
[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 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
23 #![cfg_attr(stage0, feature(custom_attribute))]
24 #![crate_name = "rustc_lint"]
25 #![unstable(feature = "rustc_private", issue = "27812")]
26 #![cfg_attr(stage0, staged_api)]
27 #![crate_type = "dylib"]
28 #![crate_type = "rlib"]
29 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
30       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
31       html_root_url = "https://doc.rust-lang.org/nightly/")]
32
33 #![cfg_attr(test, feature(test))]
34 #![feature(box_patterns)]
35 #![feature(box_syntax)]
36 #![feature(num_bits_bytes)]
37 #![feature(quote)]
38 #![feature(rustc_diagnostic_macros)]
39 #![feature(rustc_private)]
40 #![feature(slice_patterns)]
41 #![feature(staged_api)]
42 #![feature(str_char)]
43
44 extern crate syntax;
45 #[macro_use]
46 extern crate rustc;
47 #[macro_use]
48 extern crate log;
49 extern crate rustc_front;
50 extern crate rustc_back;
51
52 pub use rustc::lint as lint;
53 pub use rustc::middle as middle;
54 pub use rustc::session as session;
55 pub use rustc::util as util;
56
57 use session::Session;
58 use lint::LintId;
59
60 mod bad_style;
61 mod builtin;
62 mod types;
63 mod unused;
64
65 use bad_style::*;
66 use builtin::*;
67 use types::*;
68 use unused::*;
69
70 /// Tell the `LintStore` about all the built-in lints (the ones
71 /// defined in this crate and the ones defined in
72 /// `rustc::lint::builtin`).
73 pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
74     macro_rules! add_builtin {
75         ($sess:ident, $($name:ident),*,) => (
76             {$(
77                 store.register_late_pass($sess, false, box $name);
78                 )*}
79             )
80     }
81
82     macro_rules! add_early_builtin {
83         ($sess:ident, $($name:ident),*,) => (
84             {$(
85                 store.register_early_pass($sess, false, box $name);
86                 )*}
87             )
88     }
89
90     macro_rules! add_builtin_with_new {
91         ($sess:ident, $($name:ident),*,) => (
92             {$(
93                 store.register_late_pass($sess, false, box $name::new());
94                 )*}
95             )
96     }
97
98     macro_rules! add_lint_group {
99         ($sess:ident, $name:expr, $($lint:ident),*) => (
100             store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
101             )
102     }
103
104     add_early_builtin!(sess,
105                        UnusedParens,
106                        );
107
108     add_builtin!(sess,
109                  HardwiredLints,
110                  WhileTrue,
111                  ImproperCTypes,
112                  BoxPointers,
113                  UnusedAttributes,
114                  PathStatements,
115                  UnusedResults,
116                  NonCamelCaseTypes,
117                  NonSnakeCase,
118                  NonUpperCaseGlobals,
119                  UnusedImportBraces,
120                  NonShorthandFieldPatterns,
121                  UnusedUnsafe,
122                  UnsafeCode,
123                  UnusedMut,
124                  UnusedAllocation,
125                  MissingCopyImplementations,
126                  UnstableFeatures,
127                  Deprecated,
128                  UnconditionalRecursion,
129                  InvalidNoMangleItems,
130                  PluginAsLibrary,
131                  DropWithReprExtern,
132                  MutableTransmutes,
133                  );
134
135     add_builtin_with_new!(sess,
136                           TypeLimits,
137                           MissingDoc,
138                           MissingDebugImplementations,
139                           );
140
141     add_lint_group!(sess, "bad_style",
142                     NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPER_CASE_GLOBALS);
143
144     add_lint_group!(sess, "unused",
145                     UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
146                     UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
147                     UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);
148
149     add_lint_group!(sess, "future_incompatible",
150                     PRIVATE_IN_PUBLIC);
151
152     // We have one lint pass defined specially
153     store.register_late_pass(sess, false, box lint::GatherNodeLevels);
154
155     // Insert temporary renamings for a one-time deprecation
156     store.register_renamed("unknown_features", "unused_features");
157
158     store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
159 }