Skip to content

Commit 57a8745

Browse files
committed
clarify 'no fields'
1 parent a8e5377 commit 57a8745

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

compiler/rustc_lint/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ fn get_nullable_type<'tcx>(
814814

815815
/// A type is niche-optimization candidate iff:
816816
/// - Is a zero-sized type with alignment 1 (a “1-ZST”).
817-
/// - Has no fields.
817+
/// - Is either a struct/tuple with no fields, or an enum with no variants.
818818
/// - Does not have the `#[non_exhaustive]` attribute.
819819
fn is_niche_optimization_candidate<'tcx>(
820820
tcx: TyCtxt<'tcx>,
@@ -828,7 +828,7 @@ fn is_niche_optimization_candidate<'tcx>(
828828
match ty.kind() {
829829
ty::Adt(ty_def, _) => {
830830
let non_exhaustive = ty_def.is_variant_list_non_exhaustive();
831-
let empty = (ty_def.is_struct() && ty_def.all_fields().next().is_none())
831+
let empty = (ty_def.is_struct() && ty_def.non_enum_variant().fields.is_empty())
832832
|| (ty_def.is_enum() && ty_def.variants().is_empty());
833833

834834
!non_exhaustive && empty

library/core/src/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@
235235
//! [representation guarantees][opt-rep] (let's call that type `I`), and the *other* type must meet
236236
//! all of the following conditions:
237237
//! * Is a zero-sized type with alignment 1 (a "1-ZST").
238-
//! * Has no fields.
238+
//! * Is either a struct/tuple with no fields, or an enum with no variants.
239239
//! * Does not have the `#[non_exhaustive]` attribute.
240240
//!
241241
//! If that is the case, then `Result<T, E>` has the same size, alignment, and [function call ABI]

0 commit comments

Comments
 (0)