]> git.lizzy.rs Git - rust.git/blob - src/librustc_lint/lib.rs
Auto merge of #28263 - christopherdumas:add_help_E0118, r=nikomatsakis
[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 #![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(ref_slice)]
39 #![feature(rustc_diagnostic_macros)]
40 #![feature(rustc_private)]
41 #![feature(slice_patterns)]
42 #![feature(staged_api)]
43 #![feature(str_char)]
44
45 extern crate syntax;
46 #[macro_use]
47 extern crate rustc;
48 #[macro_use]
49 extern crate log;
50 extern crate rustc_front;
51
52 pub use rustc::lint as lint;
53 pub use rustc::metadata as metadata;
54 pub use rustc::middle as middle;
55 pub use rustc::session as session;
56 pub use rustc::util as util;
57
58 use session::Session;
59 use lint::LintId;
60
61 mod builtin;
62
63 /// Tell the `LintStore` about all the built-in lints (the ones
64 /// defined in this crate and the ones defined in
65 /// `rustc::lint::builtin`).
66 pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
67     macro_rules! add_builtin {
68         ($sess:ident, $($name:ident),*,) => (
69             {$(
70                 store.register_pass($sess, false, box builtin::$name);
71                 )*}
72             )
73     }
74
75     macro_rules! add_builtin_with_new {
76         ($sess:ident, $($name:ident),*,) => (
77             {$(
78                 store.register_pass($sess, false, box builtin::$name::new());
79                 )*}
80             )
81     }
82
83     macro_rules! add_lint_group {
84         ($sess:ident, $name:expr, $($lint:ident),*) => (
85             store.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]);
86             )
87     }
88
89     add_builtin!(sess,
90                  HardwiredLints,
91                  WhileTrue,
92                  ImproperCTypes,
93                  BoxPointers,
94                  UnusedAttributes,
95                  PathStatements,
96                  UnusedResults,
97                  NonCamelCaseTypes,
98                  NonSnakeCase,
99                  NonUpperCaseGlobals,
100                  UnusedParens,
101                  UnusedImportBraces,
102                  NonShorthandFieldPatterns,
103                  UnusedUnsafe,
104                  UnsafeCode,
105                  UnusedMut,
106                  UnusedAllocation,
107                  MissingCopyImplementations,
108                  UnstableFeatures,
109                  Stability,
110                  UnconditionalRecursion,
111                  InvalidNoMangleItems,
112                  PluginAsLibrary,
113                  DropWithReprExtern,
114                  MutableTransmutes,
115                  );
116
117     add_builtin_with_new!(sess,
118                           TypeLimits,
119                           RawPointerDerive,
120                           MissingDoc,
121                           MissingDebugImplementations,
122                           );
123
124     add_lint_group!(sess, "bad_style",
125                     NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPER_CASE_GLOBALS);
126
127     add_lint_group!(sess, "unused",
128                     UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
129                     UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
130                     UNUSED_UNSAFE, PATH_STATEMENTS);
131
132     // We have one lint pass defined specially
133     store.register_pass(sess, false, box lint::GatherNodeLevels);
134
135     // Insert temporary renamings for a one-time deprecation
136     store.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
137
138     store.register_renamed("unknown_features", "unused_features");
139
140     store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
141 }