Skip to content

Commit e16a8b9

Browse files
committed
Auto merge of rust-lang#10008 - Jarcho:issue_9882, r=Manishearth
Treat custom enum discriminant values as constants fixes rust-lang#9882 changelog: All lints: Don't lint in enum discriminant values when the suggestion won't work in a const context
2 parents be0eb20 + a1b15f1 commit e16a8b9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clippy_utils/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn in_constant(cx: &LateContext<'_>, id: HirId) -> bool {
196196
let parent_id = cx.tcx.hir().get_parent_item(id).def_id;
197197
match cx.tcx.hir().get_by_def_id(parent_id) {
198198
Node::Item(&Item {
199-
kind: ItemKind::Const(..) | ItemKind::Static(..),
199+
kind: ItemKind::Const(..) | ItemKind::Static(..) | ItemKind::Enum(..),
200200
..
201201
})
202202
| Node::TraitItem(&TraitItem {

tests/ui/cast_lossless_integer.fixed

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
4545
}
4646
}
4747
}
48+
49+
#[derive(PartialEq, Debug)]
50+
#[repr(i64)]
51+
enum Test {
52+
A = u32::MAX as i64 + 1,
53+
}

tests/ui/cast_lossless_integer.rs

+6
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
4545
}
4646
}
4747
}
48+
49+
#[derive(PartialEq, Debug)]
50+
#[repr(i64)]
51+
enum Test {
52+
A = u32::MAX as i64 + 1,
53+
}

0 commit comments

Comments
 (0)