Merge pull request #1999 from sunfishcode/master
Enable the cast_lossless warning by default.
diff --git a/README.md b/README.md
index 01c4a89..9f2a012 100644
--- a/README.md
+++ b/README.md
@@ -198,7 +198,7 @@
[box_vec](https://github.com/rust-lang-nursery/rust-clippy/wiki#box_vec) | warn | usage of `Box<Vec<T>>`, vector elements are already on the heap
[boxed_local](https://github.com/rust-lang-nursery/rust-clippy/wiki#boxed_local) | warn | using `Box<T>` 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 ef8bff9..19b8816 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -358,7 +358,6 @@
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 @@
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 9612c67..29a7bb7 100644
--- a/clippy_lints/src/types.rs
+++ b/clippy_lints/src/types.rs
@@ -499,7 +499,7 @@
/// ```
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 87c49f8..ad381c6 100644
--- a/tests/ui/absurd-extreme-comparisons.rs
+++ b/tests/ui/absurd-extreme-comparisons.rs
@@ -38,12 +38,12 @@
impl PartialEq<u32> for U {
fn eq(&self, other: &u32) -> bool {
- self.eq(&U(*other as u64))
+ self.eq(&U(u64::from(*other)))
}
}
impl PartialOrd<u32> for U {
fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
- 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 47d29a4..f3f66f3 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 de60690..8d8e7bd 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>() -> T { unimplemented!() }