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;
48 extern crate syntax_pos;
50 pub use rustc::lint as lint;
51 pub use rustc::middle as middle;
52 pub use rustc::session as session;
53 pub use rustc::util as util;
57 use lint::FutureIncompatibleInfo;
69 /// Tell the `LintStore` about all the built-in lints (the ones
70 /// defined in this crate and the ones defined in
71 /// `rustc::lint::builtin`).
72 pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
73 macro_rules! add_builtin {
74 ($sess:ident, $($name:ident),*,) => (
76 store.register_late_pass($sess, false, box $name);
81 macro_rules! add_early_builtin {
82 ($sess:ident, $($name:ident),*,) => (
84 store.register_early_pass($sess, false, box $name);
89 macro_rules! add_builtin_with_new {
90 ($sess:ident, $($name:ident),*,) => (
92 store.register_late_pass($sess, false, box $name::new());
97 macro_rules! add_lint_group {
98 ($sess:ident, $name:expr, $($lint:ident),*) => (
99 store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
103 add_early_builtin!(sess,
119 NonShorthandFieldPatterns,
124 MissingCopyImplementations,
127 UnconditionalRecursion,
128 InvalidNoMangleItems,
134 add_builtin_with_new!(sess,
137 MissingDebugImplementations,
140 add_lint_group!(sess, "bad_style",
141 NON_CAMEL_CASE_TYPES, NON_SNAKE_CASE, NON_UPPER_CASE_GLOBALS);
143 add_lint_group!(sess, "unused",
144 UNUSED_IMPORTS, UNUSED_VARIABLES, UNUSED_ASSIGNMENTS, DEAD_CODE,
145 UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
146 UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);
148 // Guidelines for creating a future incompatibility lint:
150 // - Create a lint defaulting to warn as normal, with ideally the same error
151 // message you would normally give
152 // - Add a suitable reference, typically an RFC or tracking issue. Go ahead
153 // and include the full URL.
154 // - Later, change lint to error
155 // - Eventually, remove lint
156 store.register_future_incompatible(sess, vec![
157 FutureIncompatibleInfo {
158 id: LintId::of(PRIVATE_IN_PUBLIC),
159 reference: "the explanation for E0446 (`--explain E0446`)",
161 FutureIncompatibleInfo {
162 id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
163 reference: "PR 31362 <https://github.com/rust-lang/rust/pull/31362>",
165 FutureIncompatibleInfo {
166 id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
167 reference: "PR 30724 <https://github.com/rust-lang/rust/pull/30724>",
169 FutureIncompatibleInfo {
170 id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
171 reference: "PR #32403 <https://github.com/rust-lang/rust/pull/32403>",
173 FutureIncompatibleInfo {
174 id: LintId::of(MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT),
175 reference: "RFC 218 <https://github.com/rust-lang/rfcs/blob/\
176 master/text/0218-empty-struct-with-braces.md>",
178 FutureIncompatibleInfo {
179 id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
180 reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
182 FutureIncompatibleInfo {
183 id: LintId::of(OVERLAPPING_INHERENT_IMPLS),
184 reference: "issue #22889 <https://github.com/rust-lang/rust/issues/22889>",
186 FutureIncompatibleInfo {
187 id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
188 reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
190 FutureIncompatibleInfo {
191 id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
192 reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
194 FutureIncompatibleInfo {
195 id: LintId::of(UNSIZED_IN_TUPLE),
196 reference: "issue #33242 <https://github.com/rust-lang/rust/issues/33242>",
198 FutureIncompatibleInfo {
199 id: LintId::of(OBJECT_UNSAFE_FRAGMENT),
200 reference: "issue #33243 <https://github.com/rust-lang/rust/issues/33243>",
202 FutureIncompatibleInfo {
203 id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE),
204 reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>",
206 FutureIncompatibleInfo {
207 id: LintId::of(LIFETIME_UNDERSCORE),
208 reference: "RFC 1177 <https://github.com/rust-lang/rfcs/pull/1177>",
212 // We have one lint pass defined specially
213 store.register_late_pass(sess, false, box lint::GatherNodeLevels);
215 // Register renamed and removed lints
216 store.register_renamed("unknown_features", "unused_features");
217 store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
218 store.register_removed("negate_unsigned", "cast a signed value instead");
219 store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok");
220 // This was renamed to raw_pointer_derive, which was then removed,
221 // so it is also considered removed
222 store.register_removed("raw_pointer_deriving", "using derive with raw pointers is ok");