diff options
| author | bors <bors@rust-lang.org> | 2023-03-26 12:05:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-26 12:05:38 +0000 |
| commit | 89c2e3d3d75486e52473de3ae38f0ca6efeffef2 (patch) | |
| tree | 07df5b9bb2675e15c5ecc5e4d55cc379f1cdecd7 /compiler/rustc_abi/src/lib.rs | |
| parent | 2420bd34ba68a625840022de2a56aec228500359 (diff) | |
| parent | 4aa4ce6ee26045f74f28d6a5067d01bf54221616 (diff) | |
| download | rust-89c2e3d3d75486e52473de3ae38f0ca6efeffef2.tar.gz rust-89c2e3d3d75486e52473de3ae38f0ca6efeffef2.zip | |
Auto merge of #109626 - matthiaskrgr:rollup-k0y7bdd, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #109007 (rustdoc: skip `// some variants omitted` if enum is `#[non_exhaustive]`) - #109593 (Rustdoc Book refer to rustdoc::missing_doc_code_examples. Fixes #109592.) - #109595 (Improve "Auto-hide trait implementation documentation" GUI test) - #109619 (Still-further-specializable projections are ambiguous in new solver) - #109620 (Correct typo (`back_box` -> `black_box`)) - #109621 (Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_abi/src/lib.rs')
| -rw-r--r-- | compiler/rustc_abi/src/lib.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 39574ca558f..6740001c38b 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -1380,8 +1380,21 @@ impl Niche { } rustc_index::newtype_index! { + /// The *source-order* index of a variant in a type. + /// + /// For enums, these are always `0..variant_count`, regardless of any + /// custom discriminants that may have been defined, and including any + /// variants that may end up uninhabited due to field types. (Some of the + /// variants may not be present in a monomorphized ABI [`Variants`], but + /// those skipped variants are always counted when determining the *index*.) + /// + /// `struct`s, `tuples`, and `unions`s are considered to have a single variant + /// with variant index zero, aka [`FIRST_VARIANT`]. #[derive(HashStable_Generic)] - pub struct VariantIdx {} + pub struct VariantIdx { + /// Equivalent to `VariantIdx(0)`. + const FIRST_VARIANT = 0; + } } #[derive(PartialEq, Eq, Hash, Clone)] @@ -1422,7 +1435,7 @@ impl LayoutS { let size = scalar.size(cx); let align = scalar.align(cx); LayoutS { - variants: Variants::Single { index: VariantIdx::new(0) }, + variants: Variants::Single { index: FIRST_VARIANT }, fields: FieldsShape::Primitive, abi: Abi::Scalar(scalar), largest_niche, |
