about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2022-11-30 22:34:42 -0500
committerJason Newcomb <jsnewcomb@pm.me>2022-11-30 22:34:42 -0500
commita1b15f13f7187b9c61e1d691a339b32550dfed43 (patch)
treec20b453a02218d9b6523f262fa54cca124e03ebe
parent1cdb06d406181e15a943dab926273013fdefd516 (diff)
downloadrust-a1b15f13f7187b9c61e1d691a339b32550dfed43.tar.gz
rust-a1b15f13f7187b9c61e1d691a339b32550dfed43.zip
Treat custom enum discriminant values as constants
-rw-r--r--clippy_utils/src/lib.rs2
-rw-r--r--tests/ui/cast_lossless_integer.fixed6
-rw-r--r--tests/ui/cast_lossless_integer.rs6
3 files changed, 13 insertions, 1 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 90192f46cbf..09ed7255a2b 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -196,7 +196,7 @@ pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool {
     let parent_id = cx.tcx.hir().get_parent_item(id).def_id;
     match cx.tcx.hir().get_by_def_id(parent_id) {
         Node::Item(&Item {
-            kind: ItemKind::Const(..) | ItemKind::Static(..),
+            kind: ItemKind::Const(..) | ItemKind::Static(..) | ItemKind::Enum(..),
             ..
         })
         | Node::TraitItem(&TraitItem {
diff --git a/tests/ui/cast_lossless_integer.fixed b/tests/ui/cast_lossless_integer.fixed
index 72a708b4073..925cbf25368 100644
--- a/tests/ui/cast_lossless_integer.fixed
+++ b/tests/ui/cast_lossless_integer.fixed
@@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
         }
     }
 }
+
+#[derive(PartialEq, Debug)]
+#[repr(i64)]
+enum Test {
+    A = u32::MAX as i64 + 1,
+}
diff --git a/tests/ui/cast_lossless_integer.rs b/tests/ui/cast_lossless_integer.rs
index 34bb47181e6..c82bd9108d2 100644
--- a/tests/ui/cast_lossless_integer.rs
+++ b/tests/ui/cast_lossless_integer.rs
@@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
         }
     }
 }
+
+#[derive(PartialEq, Debug)]
+#[repr(i64)]
+enum Test {
+    A = u32::MAX as i64 + 1,
+}