From 1ea70116d389699400545c6200c38345b1eceeb7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 29 Aug 2017 05:48:19 -0700 Subject: [PATCH] Enable the cast_lossless warning by default. --- README.md | 2 +- clippy_lints/src/lib.rs | 2 +- clippy_lints/src/types.rs | 2 +- tests/ui/absurd-extreme-comparisons.rs | 4 ++-- tests/ui/float_cmp.rs | 2 +- tests/ui/invalid_upcast_comparisons.rs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 01c4a89e1..9f2a0128c 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ name [box_vec](https://github.com/rust-lang-nursery/rust-clippy/wiki#box_vec) | warn | usage of `Box>`, vector elements are already on the heap [boxed_local](https://github.com/rust-lang-nursery/rust-clippy/wiki#boxed_local) | warn | using `Box` where unnecessary [builtin_type_shadow](https://github.com/rust-lang-nursery/rust-clippy/wiki#builtin_type_shadow) | warn | shadowing a builtin type -[cast_lossless](https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_lossless) | allow | casts using `as` that are known to be lossless, e.g. `x as u64` where `x: u8` +[cast_lossless](https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_lossless) | warn | casts using `as` that are known to be lossless, e.g. `x as u64` where `x: u8` [cast_possible_truncation](https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_possible_truncation) | allow | casts that may cause truncation of the value, e.g. `x as u8` where `x: u32`, or `x as i32` where `x: f32` [cast_possible_wrap](https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_possible_wrap) | allow | casts that may cause wrapping around the value, e.g. `x as i32` where `x: u32` and `x > i32::MAX` [cast_precision_loss](https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_precision_loss) | allow | casts that cause loss of precision, e.g. `x as f32` where `x: u64` diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index ef8bff92c..19b8816cd 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -358,7 +358,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { shadow::SHADOW_UNRELATED, strings::STRING_ADD, strings::STRING_ADD_ASSIGN, - types::CAST_LOSSLESS, types::CAST_POSSIBLE_TRUNCATION, types::CAST_POSSIBLE_WRAP, types::CAST_PRECISION_LOSS, @@ -530,6 +529,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { types::ABSURD_EXTREME_COMPARISONS, types::BORROWED_BOX, types::BOX_VEC, + types::CAST_LOSSLESS, types::CHAR_LIT_AS_U8, types::LET_UNIT_VALUE, types::LINKEDLIST, diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 9612c670f..29a7bb750 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -499,7 +499,7 @@ declare_lint! { /// ``` declare_lint! { pub CAST_LOSSLESS, - Allow, + Warn, "casts using `as` that are known to be lossless, e.g. `x as u64` where `x: u8`" } diff --git a/tests/ui/absurd-extreme-comparisons.rs b/tests/ui/absurd-extreme-comparisons.rs index 87c49f885..ad381c6cd 100644 --- a/tests/ui/absurd-extreme-comparisons.rs +++ b/tests/ui/absurd-extreme-comparisons.rs @@ -38,12 +38,12 @@ pub struct U(u64); impl PartialEq for U { fn eq(&self, other: &u32) -> bool { - self.eq(&U(*other as u64)) + self.eq(&U(u64::from(*other))) } } impl PartialOrd for U { fn partial_cmp(&self, other: &u32) -> Option { - self.partial_cmp(&U(*other as u64)) + self.partial_cmp(&U(u64::from(*other))) } } diff --git a/tests/ui/float_cmp.rs b/tests/ui/float_cmp.rs index 47d29a421..f3f66f3c9 100644 --- a/tests/ui/float_cmp.rs +++ b/tests/ui/float_cmp.rs @@ -2,7 +2,7 @@ #![plugin(clippy)] #![warn(float_cmp)] -#![allow(unused, no_effect, unnecessary_operation)] +#![allow(unused, no_effect, unnecessary_operation, cast_lossless)] use std::ops::Add; diff --git a/tests/ui/invalid_upcast_comparisons.rs b/tests/ui/invalid_upcast_comparisons.rs index de606902e..8d8e7bd8d 100644 --- a/tests/ui/invalid_upcast_comparisons.rs +++ b/tests/ui/invalid_upcast_comparisons.rs @@ -2,7 +2,7 @@ #![plugin(clippy)] #![warn(invalid_upcast_comparisons)] -#![allow(unused, eq_op, no_effect, unnecessary_operation)] +#![allow(unused, eq_op, no_effect, unnecessary_operation, cast_lossless)] fn mk_value() -> T { unimplemented!() }