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
This commit is contained in:
bors 2022-12-01 22:37:15 +00:00
commit e16a8b93ba
3 changed files with 13 additions and 1 deletions

View file

@ -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; let parent_id = cx.tcx.hir().get_parent_item(id).def_id;
match cx.tcx.hir().get_by_def_id(parent_id) { match cx.tcx.hir().get_by_def_id(parent_id) {
Node::Item(&Item { Node::Item(&Item {
kind: ItemKind::Const(..) | ItemKind::Static(..), kind: ItemKind::Const(..) | ItemKind::Static(..) | ItemKind::Enum(..),
.. ..
}) })
| Node::TraitItem(&TraitItem { | Node::TraitItem(&TraitItem {

View file

@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
} }
} }
} }
#[derive(PartialEq, Debug)]
#[repr(i64)]
enum Test {
A = u32::MAX as i64 + 1,
}

View file

@ -45,3 +45,9 @@ mod cast_lossless_in_impl {
} }
} }
} }
#[derive(PartialEq, Debug)]
#[repr(i64)]
enum Test {
A = u32::MAX as i64 + 1,
}