diff options
| author | Philipp Krones <hello@philkrones.com> | 2024-07-25 18:09:52 +0200 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2024-07-25 18:23:27 +0200 |
| commit | 9f53fc32cfb62724d95de44779259ce4e24bc085 (patch) | |
| tree | df5069c84c1a281c78b72e8935a9664b3110f66a /clippy_lints/src/empty_enum.rs | |
| parent | 6d674685ae4e9156dbb6ecd3aa38d87864ecab3e (diff) | |
| parent | df0cb6c51ee798264586ee9144466cf003d68181 (diff) | |
Merge remote-tracking branch 'upstream/master' into rustup
Diffstat (limited to 'clippy_lints/src/empty_enum.rs')
| -rw-r--r-- | clippy_lints/src/empty_enum.rs | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index d16714695cb..1869faab1d3 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -64,25 +64,21 @@ declare_lint_pass!(EmptyEnum => [EMPTY_ENUM]); impl<'tcx> LateLintPass<'tcx> for EmptyEnum { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { - // Only suggest the `never_type` if the feature is enabled - if !cx.tcx.features().never_type { - return; - } - - if let ItemKind::Enum(..) = item.kind { - let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); - let adt = ty.ty_adt_def().expect("already checked whether this is an enum"); - if adt.variants().is_empty() { - span_lint_and_help( - cx, - EMPTY_ENUM, - item.span, - "enum with no variants", - None, - "consider using the uninhabited type `!` (never type) or a wrapper \ - around it to introduce a type which can't be instantiated", - ); - } + if let ItemKind::Enum(..) = item.kind + // Only suggest the `never_type` if the feature is enabled + && cx.tcx.features().never_type + && let Some(adt) = cx.tcx.type_of(item.owner_id).instantiate_identity().ty_adt_def() + && adt.variants().is_empty() + { + span_lint_and_help( + cx, + EMPTY_ENUM, + item.span, + "enum with no variants", + None, + "consider using the uninhabited type `!` (never type) or a wrapper \ + around it to introduce a type which can't be instantiated", + ); } } } |
