diff options
| author | bors <bors@rust-lang.org> | 2022-12-01 22:37:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-01 22:37:15 +0000 |
| commit | e16a8b93ba08b93a8d4b835f4842b77d70451bf2 (patch) | |
| tree | a01ebcf7e478b66c62e050eb3203949018dc52f3 | |
| parent | be0eb20fff7f222200d0160da1e2537592a0314e (diff) | |
| parent | a1b15f13f7187b9c61e1d691a339b32550dfed43 (diff) | |
| download | rust-e16a8b93ba08b93a8d4b835f4842b77d70451bf2.tar.gz rust-e16a8b93ba08b93a8d4b835f4842b77d70451bf2.zip | |
Auto merge of #10008 - Jarcho:issue_9882, r=Manishearth
Treat custom enum discriminant values as constants fixes #9882 changelog: All lints: Don't lint in enum discriminant values when the suggestion won't work in a const context
| -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, +} |
