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.
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.
11 //! Lints in the Rust compiler.
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.
20 //! This API is completely unstable and subject to change.
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/")]
31 #![cfg_attr(test, feature(test))]
32 #![feature(box_patterns)]
33 #![feature(box_syntax)]
35 #![feature(rustc_diagnostic_macros)]
36 #![feature(rustc_private)]
37 #![feature(slice_patterns)]
38 #![feature(staged_api)]
45 extern crate rustc_back;
46 extern crate rustc_const_eval;
47 extern crate syntax_pos;
49 extern crate rustc_i128;
52 pub use rustc::middle;
53 pub use rustc::session;
58 use lint::FutureIncompatibleInfo;
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),*,) => (
77 store.register_late_pass($sess, false, box $name);
82 macro_rules! add_early_builtin {
83 ($sess:ident, $($name:ident),*,) => (
85 store.register_early_pass($sess, false, box $name);
90 macro_rules! add_builtin_with_new {
91 ($sess:ident, $($name:ident),*,) => (
93 store.register_late_pass($sess, false, box $name::new());
98 macro_rules! add_early_builtin_with_new {
99 ($sess:ident, $($name:ident),*,) => (
101 store.register_early_pass($sess, false, box $name::new());
106 macro_rules! add_lint_group {
107 ($sess:ident, $name:expr, $($lint:ident),*) => (
108 store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
112 add_early_builtin!(sess,
117 add_early_builtin_with_new!(sess,
125 VariantSizeDifferences,
133 NonShorthandFieldPatterns,
138 MissingCopyImplementations,
140 UnconditionalRecursion,
141 InvalidNoMangleItems,
144 UnionsWithDropFields,
147 add_builtin_with_new!(sess,
150 MissingDebugImplementations,
153 add_lint_group!(sess,
155 NON_CAMEL_CASE_TYPES,
157 NON_UPPER_CASE_GLOBALS);
159 add_lint_group!(sess,
167 UNREACHABLE_PATTERNS,
173 // Guidelines for creating a future incompatibility lint:
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
181 store.register_future_incompatible(sess,
183 FutureIncompatibleInfo {
184 id: LintId::of(PRIVATE_IN_PUBLIC),
185 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
187 FutureIncompatibleInfo {
188 id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
189 reference: "issue #36886 <https://github.com/rust-lang/rust/issues/36886>",
191 FutureIncompatibleInfo {
192 id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
193 reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
195 FutureIncompatibleInfo {
196 id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
197 reference: "issue #36888 <https://github.com/rust-lang/rust/issues/36888>",
199 FutureIncompatibleInfo {
200 id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
201 reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
203 FutureIncompatibleInfo {
204 id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
205 reference: "issue #36889 <https://github.com/rust-lang/rust/issues/36889>",
207 FutureIncompatibleInfo {
208 id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
209 reference: "issue #36890 <https://github.com/rust-lang/rust/issues/36890>",
211 FutureIncompatibleInfo {
212 id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
213 reference: "issue #36891 <https://github.com/rust-lang/rust/issues/36891>",
215 FutureIncompatibleInfo {
216 id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE),
217 reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>",
219 FutureIncompatibleInfo {
220 id: LintId::of(LIFETIME_UNDERSCORE),
221 reference: "issue #36892 <https://github.com/rust-lang/rust/issues/36892>",
223 FutureIncompatibleInfo {
224 id: LintId::of(SAFE_EXTERN_STATICS),
225 reference: "issue #36247 <https://github.com/rust-lang/rust/issues/35112>",
227 FutureIncompatibleInfo {
228 id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY),
229 reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
231 FutureIncompatibleInfo {
232 id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL),
233 reference: "issue #37166 <https://github.com/rust-lang/rust/issues/37166>",
235 FutureIncompatibleInfo {
236 id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP),
237 reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
239 FutureIncompatibleInfo {
240 id: LintId::of(LEGACY_IMPORTS),
241 reference: "issue #38260 <https://github.com/rust-lang/rust/issues/38260>",
243 FutureIncompatibleInfo {
244 id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
245 reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
249 // Register renamed and removed lints
250 store.register_renamed("unknown_features", "unused_features");
251 store.register_removed("unsigned_negation",
252 "replaced by negate_unsigned feature gate");
253 store.register_removed("negate_unsigned", "cast a signed value instead");
254 store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok");
255 // This was renamed to raw_pointer_derive, which was then removed,
256 // so it is also considered removed
257 store.register_removed("raw_pointer_deriving",
258 "using derive with raw pointers is ok");
259 store.register_removed("drop_with_repr_extern", "drop flags have been removed");