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