diff --git a/CHANGELOG.md b/CHANGELOG.md index e4a1a602c43..db838a3e2e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -982,7 +982,6 @@ Released 2018-09-13 [`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division [`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array [`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref -[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref [`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex [`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons [`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements diff --git a/README.md b/README.md index 389fe316ade..8bcfd8a8430 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 310 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 309 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 62cef778917..0140cf861ac 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -113,3 +113,12 @@ declare_deprecated_lint! { pub UNSAFE_VECTOR_INITIALIZATION, "the replacement suggested by this lint had substantially different behavior" } + +/// **What it does:** Nothing. This lint has been deprecated. +/// +/// **Deprecation reason:** This lint has been superseded by the warn-by-default +/// `invalid_value` rustc lint. +declare_clippy_lint! { + pub INVALID_REF, + "superseded by rustc lint `invalid_value`" +} diff --git a/clippy_lints/src/invalid_ref.rs b/clippy_lints/src/invalid_ref.rs deleted file mode 100644 index 8f9ccaea26d..00000000000 --- a/clippy_lints/src/invalid_ref.rs +++ /dev/null @@ -1,55 +0,0 @@ -use crate::utils::{match_def_path, paths, span_help_and_lint}; -use if_chain::if_chain; -use rustc::hir::*; -use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::ty; -use rustc::{declare_lint_pass, declare_tool_lint}; - -declare_clippy_lint! { - /// **What it does:** Checks for creation of references to zeroed or uninitialized memory. - /// - /// **Why is this bad?** Creation of null references is undefined behavior. - /// - /// **Known problems:** None. - /// - /// **Example:** - /// ```no_run - /// let bad_ref: &usize = unsafe { std::mem::zeroed() }; - /// ``` - pub INVALID_REF, - correctness, - "creation of invalid reference" -} - -const ZERO_REF_SUMMARY: &str = "reference to zeroed memory"; -const UNINIT_REF_SUMMARY: &str = "reference to uninitialized memory"; -const HELP: &str = "Creation of a null reference is undefined behavior; \ - see https://doc.rust-lang.org/reference/behavior-considered-undefined.html"; - -declare_lint_pass!(InvalidRef => [INVALID_REF]); - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef { - fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { - if_chain! { - if let ExprKind::Call(ref path, ref args) = expr.node; - if let ExprKind::Path(ref qpath) = path.node; - if args.len() == 0; - if let ty::Ref(..) = cx.tables.expr_ty(expr).sty; - if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id(); - then { - let msg = if match_def_path(cx, def_id, &paths::MEM_ZEROED) | - match_def_path(cx, def_id, &paths::INIT) - { - ZERO_REF_SUMMARY - } else if match_def_path(cx, def_id, &paths::MEM_UNINIT) | - match_def_path(cx, def_id, &paths::UNINIT) - { - UNINIT_REF_SUMMARY - } else { - return; - }; - span_help_and_lint(cx, INVALID_REF, expr.span, msg, HELP); - } - } - } -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 258be38e48b..1ab943c5923 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -200,7 +200,6 @@ pub mod inherent_to_string; pub mod inline_fn_without_body; pub mod int_plus_one; pub mod integer_division; -pub mod invalid_ref; pub mod items_after_statements; pub mod large_enum_variant; pub mod len_zero; @@ -558,7 +557,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box bytecount::ByteCount); reg.register_late_lint_pass(box infinite_iter::InfiniteIter); reg.register_late_lint_pass(box inline_fn_without_body::InlineFnWithoutBody); - reg.register_late_lint_pass(box invalid_ref::InvalidRef); reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default()); reg.register_late_lint_pass(box types::ImplicitHasher); reg.register_early_lint_pass(box redundant_static_lifetimes::RedundantStaticLifetimes); @@ -736,7 +734,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY, inline_fn_without_body::INLINE_FN_WITHOUT_BODY, int_plus_one::INT_PLUS_ONE, - invalid_ref::INVALID_REF, large_enum_variant::LARGE_ENUM_VARIANT, len_zero::LEN_WITHOUT_IS_EMPTY, len_zero::LEN_ZERO, @@ -1094,7 +1091,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { infinite_iter::INFINITE_ITER, inherent_to_string::INHERENT_TO_STRING_SHADOW_DISPLAY, inline_fn_without_body::INLINE_FN_WITHOUT_BODY, - invalid_ref::INVALID_REF, literal_representation::MISTYPED_LITERAL_SUFFIXES, loops::FOR_LOOP_OVER_OPTION, loops::FOR_LOOP_OVER_RESULT, diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index e08ff3e9705..62b22afff95 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -37,7 +37,6 @@ pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entr pub const HASHSET: [&str; 5] = ["std", "collections", "hash", "set", "HashSet"]; pub const INDEX: [&str; 3] = ["core", "ops", "Index"]; pub const INDEX_MUT: [&str; 3] = ["core", "ops", "IndexMut"]; -pub const INIT: [&str; 4] = ["core", "intrinsics", "", "init"]; pub const INTO: [&str; 3] = ["core", "convert", "Into"]; pub const INTO_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "IntoIterator"]; pub const IO_READ: [&str; 3] = ["std", "io", "Read"]; @@ -50,8 +49,6 @@ pub const LINT_PASS: [&str; 3] = ["rustc", "lint", "LintPass"]; pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"]; pub const MEM_FORGET: [&str; 3] = ["core", "mem", "forget"]; pub const MEM_REPLACE: [&str; 3] = ["core", "mem", "replace"]; -pub const MEM_UNINIT: [&str; 3] = ["core", "mem", "uninitialized"]; -pub const MEM_ZEROED: [&str; 3] = ["core", "mem", "zeroed"]; pub const MUTEX: [&str; 4] = ["std", "sync", "mutex", "Mutex"]; pub const OPEN_OPTIONS: [&str; 3] = ["std", "fs", "OpenOptions"]; pub const OPS_MODULE: [&str; 2] = ["core", "ops"]; @@ -109,7 +106,6 @@ pub const TO_STRING_METHOD: [&str; 4] = ["alloc", "string", "ToString", "to_stri pub const TRANSMUTE: [&str; 4] = ["core", "intrinsics", "", "transmute"]; pub const TRY_FROM_ERROR: [&str; 4] = ["std", "ops", "Try", "from_error"]; pub const TRY_INTO_RESULT: [&str; 4] = ["std", "ops", "Try", "into_result"]; -pub const UNINIT: [&str; 4] = ["core", "intrinsics", "", "uninit"]; pub const VEC: [&str; 3] = ["alloc", "vec", "Vec"]; pub const VEC_DEQUE: [&str; 4] = ["alloc", "collections", "vec_deque", "VecDeque"]; pub const VEC_FROM_ELEM: [&str; 3] = ["alloc", "vec", "from_elem"]; diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 93712e8eb68..b41ed4a5910 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 310] = [ +pub const ALL_LINTS: [Lint; 309] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -791,13 +791,6 @@ pub const ALL_LINTS: [Lint; 310] = [ deprecation: None, module: "methods", }, - Lint { - name: "invalid_ref", - group: "correctness", - desc: "creation of invalid reference", - deprecation: None, - module: "invalid_ref", - }, Lint { name: "invalid_regex", group: "correctness", diff --git a/tests/ui/invalid_ref.rs b/tests/ui/invalid_ref.rs deleted file mode 100644 index d59bd51bb4f..00000000000 --- a/tests/ui/invalid_ref.rs +++ /dev/null @@ -1,56 +0,0 @@ -#![allow(deprecated, unused)] -#![feature(core_intrinsics)] - -extern crate core; -use std::intrinsics::init; - -fn main() { - let x = 1; - unsafe { - ref_to_zeroed_std(&x); - ref_to_zeroed_core(&x); - ref_to_zeroed_intr(&x); - ref_to_uninit_std(&x); - ref_to_uninit_core(&x); - some_ref(); - std_zeroed_no_ref(); - core_zeroed_no_ref(); - intr_init_no_ref(); - } -} - -unsafe fn ref_to_zeroed_std(t: &T) { - let ref_zero: &T = std::mem::zeroed(); // warning -} - -unsafe fn ref_to_zeroed_core(t: &T) { - let ref_zero: &T = core::mem::zeroed(); // warning -} - -unsafe fn ref_to_zeroed_intr(t: &T) { - let ref_zero: &T = std::intrinsics::init(); // warning -} - -unsafe fn ref_to_uninit_std(t: &T) { - let ref_uninit: &T = std::mem::uninitialized(); // warning -} - -unsafe fn ref_to_uninit_core(t: &T) { - let ref_uninit: &T = core::mem::uninitialized(); // warning -} - -fn some_ref() { - let some_ref = &1; -} - -unsafe fn std_zeroed_no_ref() { - let mem_zero: usize = std::mem::zeroed(); // no warning -} - -unsafe fn core_zeroed_no_ref() { - let mem_zero: usize = core::mem::zeroed(); // no warning -} - -unsafe fn intr_init_no_ref() { - let mem_zero: usize = std::intrinsics::init(); // no warning -} diff --git a/tests/ui/invalid_ref.stderr b/tests/ui/invalid_ref.stderr deleted file mode 100644 index aeef3892dbe..00000000000 --- a/tests/ui/invalid_ref.stderr +++ /dev/null @@ -1,43 +0,0 @@ -error: reference to zeroed memory - --> $DIR/invalid_ref.rs:23:24 - | -LL | let ref_zero: &T = std::mem::zeroed(); // warning - | ^^^^^^^^^^^^^^^^^^ - | - = note: `#[deny(clippy::invalid_ref)]` on by default - = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html - -error: reference to zeroed memory - --> $DIR/invalid_ref.rs:27:24 - | -LL | let ref_zero: &T = core::mem::zeroed(); // warning - | ^^^^^^^^^^^^^^^^^^^ - | - = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html - -error: reference to zeroed memory - --> $DIR/invalid_ref.rs:31:24 - | -LL | let ref_zero: &T = std::intrinsics::init(); // warning - | ^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html - -error: reference to uninitialized memory - --> $DIR/invalid_ref.rs:35:26 - | -LL | let ref_uninit: &T = std::mem::uninitialized(); // warning - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html - -error: reference to uninitialized memory - --> $DIR/invalid_ref.rs:39:26 - | -LL | let ref_uninit: &T = core::mem::uninitialized(); // warning - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html - -error: aborting due to 5 previous errors -