about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/utils/mod.rs4
-rw-r--r--tests/ui/cast_lossless_float.fixed11
-rw-r--r--tests/ui/cast_lossless_float.rs11
-rw-r--r--tests/ui/cast_lossless_integer.fixed11
-rw-r--r--tests/ui/cast_lossless_integer.rs11
5 files changed, 48 insertions, 0 deletions
diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs
index 8fb45899653..1aff61e3186 100644
--- a/clippy_lints/src/utils/mod.rs
+++ b/clippy_lints/src/utils/mod.rs
@@ -88,6 +88,10 @@ pub fn in_constant(cx: &LateContext<'_, '_>, id: HirId) -> bool {
             node: ItemKind::Fn(_, header, ..),
             ..
         }) => header.constness == Constness::Const,
+        Node::ImplItem(&ImplItem {
+            node: ImplItemKind::Method(ref sig, _),
+            ..
+        }) => sig.header.constness == Constness::Const,
         _ => false,
     }
 }
diff --git a/tests/ui/cast_lossless_float.fixed b/tests/ui/cast_lossless_float.fixed
index 8021dc229e5..709d58b596c 100644
--- a/tests/ui/cast_lossless_float.fixed
+++ b/tests/ui/cast_lossless_float.fixed
@@ -32,3 +32,14 @@ fn main() {
 const fn abc(input: f32) -> f64 {
     input as f64
 }
+
+// Same as the above issue. We can't suggest `::from` in const fns in impls
+mod cast_lossless_in_impl {
+    struct A;
+
+    impl A {
+        pub const fn convert(x: f32) -> f64 {
+            x as f64
+        }
+    }
+}
diff --git a/tests/ui/cast_lossless_float.rs b/tests/ui/cast_lossless_float.rs
index 3cd5ad62203..eb0aab88642 100644
--- a/tests/ui/cast_lossless_float.rs
+++ b/tests/ui/cast_lossless_float.rs
@@ -32,3 +32,14 @@ fn main() {
 const fn abc(input: f32) -> f64 {
     input as f64
 }
+
+// Same as the above issue. We can't suggest `::from` in const fns in impls
+mod cast_lossless_in_impl {
+    struct A;
+
+    impl A {
+        pub const fn convert(x: f32) -> f64 {
+            x as f64
+        }
+    }
+}
diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed
index 22936e41c90..03e49adb117 100644
--- a/tests/ui/cast_lossless_integer.fixed
+++ b/tests/ui/cast_lossless_integer.fixed
@@ -34,3 +34,14 @@ fn main() {
 const fn abc(input: u16) -> u32 {
     input as u32
 }
+
+// Same as the above issue. We can't suggest `::from` in const fns in impls
+mod cast_lossless_in_impl {
+    struct A;
+
+    impl A {
+        pub const fn convert(x: u32) -> u64 {
+            x as u64
+        }
+    }
+}
diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs
index 958a336cf2c..6a984d24596 100644
--- a/tests/ui/cast_lossless_integer.rs
+++ b/tests/ui/cast_lossless_integer.rs
@@ -34,3 +34,14 @@ fn main() {
 const fn abc(input: u16) -> u32 {
     input as u32
 }
+
+// Same as the above issue. We can't suggest `::from` in const fns in impls
+mod cast_lossless_in_impl {
+    struct A;
+
+    impl A {
+        pub const fn convert(x: u32) -> u64 {
+            x as u64
+        }
+    }
+}