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