Skip to content

Commit d27f7a2

Browse files
committed
stabilize offset_of_enum
1 parent 9c3064e commit d27f7a2

File tree

15 files changed

+28
-123
lines changed

15 files changed

+28
-123
lines changed

compiler/rustc_error_codes/src/error_codes/E0795.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Invalid argument for the `offset_of!` macro.
33
Erroneous code example:
44

55
```compile_fail,E0795
6-
#![feature(offset_of_enum)]
7-
86
let x = std::mem::offset_of!(Option<u8>, Some);
97
```
108

@@ -16,8 +14,6 @@ The offset of the contained `u8` in the `Option<u8>` can be found by specifying
1614
the field name `0`:
1715

1816
```
19-
#![feature(offset_of_enum)]
20-
2117
let x: usize = std::mem::offset_of!(Option<u8>, Some.0);
2218
```
2319

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ declare_features! (
328328
(accepted, non_exhaustive, "1.40.0", Some(44109)),
329329
/// Allows `foo.rs` as an alternative to `foo/mod.rs`.
330330
(accepted, non_modrs_mods, "1.30.0", Some(44660)),
331+
/// Allows using enums in offset_of!
332+
(accepted, offset_of_enum, "CURRENT_RUSTC_VERSION", Some(120141)),
331333
/// Allows using multiple nested field accesses in offset_of!
332334
(accepted, offset_of_nested, "1.82.0", Some(120140)),
333335
/// Allows the use of or-patterns (e.g., `0 | 1`).

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,6 @@ declare_features! (
597597
(unstable, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554)),
598598
/// Allows `for<T>` binders in where-clauses
599599
(incomplete, non_lifetime_binders, "1.69.0", Some(108185)),
600-
/// Allows using enums in offset_of!
601-
(unstable, offset_of_enum, "1.75.0", Some(120141)),
602600
/// Allows using fields with slice type in offset_of!
603601
(unstable, offset_of_slice, "1.81.0", Some(126151)),
604602
/// Allows using `#[optimize(X)]`.

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,16 +3847,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
38473847
let (ident, _def_scope) =
38483848
self.tcx.adjust_ident_and_get_scope(field, container_def.did(), block);
38493849

3850-
if !self.tcx.features().offset_of_enum() {
3851-
rustc_session::parse::feature_err(
3852-
&self.tcx.sess,
3853-
sym::offset_of_enum,
3854-
ident.span,
3855-
"using enums in offset_of is experimental",
3856-
)
3857-
.emit();
3858-
}
3859-
38603850
let Some((index, variant)) = container_def
38613851
.variants()
38623852
.iter_enumerated()

library/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@
113113
#![feature(is_ascii_octdigit)]
114114
#![feature(lazy_get)]
115115
#![feature(link_cfg)]
116-
#![feature(offset_of_enum)]
117116
#![feature(panic_internals)]
118117
#![feature(ptr_alignment_type)]
119118
#![feature(ptr_metadata)]

library/core/src/mem/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,6 @@ impl<T> SizedTypeProperties for T {}
13651365
///
13661366
/// The following unstable features expand the functionality of `offset_of!`:
13671367
///
1368-
/// * [`offset_of_enum`] — allows `enum` variants to be traversed as if they were fields.
13691368
/// * [`offset_of_slice`] — allows getting the offset of a field of type `[T]`.
13701369
///
13711370
/// # Examples
@@ -1392,10 +1391,20 @@ impl<T> SizedTypeProperties for T {}
13921391
/// struct NestedB(u8);
13931392
///
13941393
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
1394+
///
1395+
/// #[repr(u8)]
1396+
/// enum Enum {
1397+
/// A(u8, u16),
1398+
/// B { one: u8, two: u16 },
1399+
/// }
1400+
///
1401+
/// assert_eq!(mem::offset_of!(Enum, A.0), 1);
1402+
/// assert_eq!(mem::offset_of!(Enum, B.two), 2);
1403+
///
1404+
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
13951405
/// ```
13961406
///
13971407
/// [dynamically sized]: https://doc.rust-lang.org/reference/dynamically-sized-types.html
1398-
/// [`offset_of_enum`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-enum.html
13991408
/// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html
14001409
#[stable(feature = "offset_of", since = "1.77.0")]
14011410
#[allow_internal_unstable(builtin_syntax)]

src/doc/unstable-book/src/language-features/offset-of-enum.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/mir-opt/const_prop/offset_of.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//@ test-mir-pass: GVN
33
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
44

5-
#![feature(offset_of_enum)]
6-
75
use std::marker::PhantomData;
86
use std::mem::offset_of;
97

tests/ui/feature-gates/feature-gate-offset-of-enum.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/feature-gates/feature-gate-offset-of-enum.stderr

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)