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/")]
29 #![cfg_attr(not(stage0), deny(warnings))]
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)]
46 extern crate rustc_back;
47 extern crate rustc_const_eval;
49 pub use rustc::lint as lint;
50 pub use rustc::middle as middle;
51 pub use rustc::session as session;
52 pub use rustc::util as util;
56 use lint::FutureIncompatibleInfo;
68 /// Tell the `LintStore` about all the built-in lints (the ones
69 /// defined in this crate and the ones defined in
70 /// `rustc::lint::builtin`).
71 pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
72 macro_rules! add_builtin {
73 ($sess:ident, $($name:ident),*,) => (
75 store.register_late_pass($sess, false, box $name);
80 macro_rules! add_early_builtin {
81 ($sess:ident, $($name:ident),*,) => (
83 store.register_early_pass($sess, false, box $name);
88 macro_rules! add_builtin_with_new {
89 ($sess:ident, $($name:ident),*,) => (
91 store.register_late_pass($sess, false, box $name::new());
96 macro_rules! add_lint_group {
97 ($sess:ident, $name:expr, $($lint:ident),*) => (
98 store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
102 add_early_builtin!(sess,
118 NonShorthandFieldPatterns,
123 MissingCopyImplementations,
126 UnconditionalRecursion,
127 InvalidNoMangleItems,
133 add_builtin_with_new!(sess,
136 MissingDebugImplementations,
139 add_lint_group!(sess, "bad_style",
140 NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPER_CASE_GLOBALS);
142 add_lint_group!(sess, "unused",
143 UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
144 UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
145 UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);
147 // Guidelines for creating a future incompatibility lint:
149 // - Create a lint defaulting to warn as normal, with ideally the same error
150 // message you would normally give
151 // - Add a suitable reference, typically an RFC or tracking issue. Go ahead
152 // and include the full URL.
153 // - Later, change lint to error
154 // - Eventually, remove lint
155 store.register_future_incompatible(sess, vec![
156 FutureIncompatibleInfo {
157 id: LintId::of(PRIVATE_IN_PUBLIC),
158 reference: "the explanation for E0446 (`--explain E0446`)",
160 FutureIncompatibleInfo {
161 id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
162 reference: "PR 31362 <https://github.com/rust-lang/rust/pull/31362>",
164 FutureIncompatibleInfo {
165 id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
166 reference: "PR 30724 <https://github.com/rust-lang/rust/pull/30724>",
168 FutureIncompatibleInfo {
169 id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
170 reference: "PR #32403 <https://github.com/rust-lang/rust/pull/32403>",
172 FutureIncompatibleInfo {
173 id: LintId::of(MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT),
174 reference: "RFC 218 <https://github.com/rust-lang/rfcs/blob/\
175 master/text/0218-empty-struct-with-braces.md>",
177 FutureIncompatibleInfo {
178 id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
179 reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
181 FutureIncompatibleInfo {
182 id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
183 reference: "issue #22889 <https://github.com/rust-lang/rust/issues/22889>",
185 FutureIncompatibleInfo {
186 id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
187 reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
189 FutureIncompatibleInfo {
190 id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
191 reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
193 FutureIncompatibleInfo {
194 id: LintId::of(UNSIZED_IN_TUPLE),
195 reference: "issue #33242 <https://github.com/rust-lang/rust/issues/33242>",
197 FutureIncompatibleInfo {
198 id: LintId::of(OBJECT_UNSAFE_FRAGMENT),
199 reference: "issue #33243 <https://github.com/rust-lang/rust/issues/33243>",
201 FutureIncompatibleInfo {
202 id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE),
203 reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>",
205 FutureIncompatibleInfo {
206 id: LintId::of(LIFETIME_UNDERSCORE),
207 reference: "RFC 1177 <https://github.com/rust-lang/rfcs/pull/1177>",
211 // We have one lint pass defined specially
212 store.register_late_pass(sess, false, box lint::GatherNodeLevels);
214 // Register renamed and removed lints
215 store.register_renamed("unknown_features", "unused_features");
216 store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
217 store.register_removed("negate_unsigned", "cast a signed value instead");
218 store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok");
219 // This was renamed to raw_pointer_derive, which was then removed,
220 // so it is also considered removed
221 store.register_removed("raw_pointer_deriving", "using derive with raw pointers is ok");