diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2022-11-30 22:34:42 -0500 |
|---|---|---|
| committer | Jason Newcomb <jsnewcomb@pm.me> | 2022-11-30 22:34:42 -0500 |
| commit | a1b15f13f7187b9c61e1d691a339b32550dfed43 (patch) | |
| tree | c20b453a02218d9b6523f262fa54cca124e03ebe | |
| parent | 1cdb06d406181e15a943dab926273013fdefd516 (diff) | |
| download | rust-a1b15f13f7187b9c61e1d691a339b32550dfed43.tar.gz rust-a1b15f13f7187b9c61e1d691a339b32550dfed43.zip | |
Treat custom enum discriminant values as constants
| -rw-r--r-- | clippy_utils/src/lib.rs | 2 | ||||
| -rw-r--r-- | tests/ui/cast_lossless_integer.fixed | 6 | ||||
| -rw-r--r-- | tests/ui/cast_lossless_integer.rs | 6 |
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, +} |
