-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Stabilize offset_of_slice
#139673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jdonszelmann
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
jdonszelmann:offset-of-slice
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11
−61
Open
Stabilize offset_of_slice
#139673
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1263,10 +1263,10 @@ impl<T> SizedTypeProperties for T {} | |
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate this item, mark one as |
||
/// # Offsets of, and in, dynamically sized types | ||
/// | ||
/// The field’s type must be [`Sized`], but it may be located in a [dynamically sized] container. | ||
/// If the field type is dynamically sized, then you cannot use `offset_of!` (since the field's | ||
/// alignment, and therefore its offset, may also be dynamic) and must take the offset from an | ||
/// actual pointer to the container instead. | ||
/// The field’s type must have a statically known alignment. In other words, it is [`Sized`], a slice, | ||
/// or some wrapper around a slice. Notably, this is not the case if the field is a trait object. | ||
/// The alignment of trait objects can be different based on what the underlying type is, which can | ||
/// affect the offset of the field. Therefore you cannot use `offset_of!`. | ||
/// | ||
/// ``` | ||
/// # use core::mem; | ||
|
@@ -1281,8 +1281,9 @@ impl<T> SizedTypeProperties for T {} | |
/// #[repr(C, align(4))] | ||
/// struct Align4(u32); | ||
/// | ||
/// assert_eq!(mem::offset_of!(Struct<dyn Debug>, a), 0); // OK — Sized field | ||
/// assert_eq!(mem::offset_of!(Struct<Align4>, b), 4); // OK — not DST | ||
/// assert_eq!(mem::offset_of!(Struct<Align4>, b), 4); // OK — the last field is Sized | ||
/// assert_eq!(mem::offset_of!(Struct<[u8]>, b), 1); // OK — the last field is a slice | ||
/// assert_eq!(mem::offset_of!(Struct<dyn Debug>, a), 0); // OK — the struct is unsized, but the field `a` is Sized | ||
/// | ||
/// // assert_eq!(mem::offset_of!(Struct<dyn Debug>, b), 1); | ||
/// // ^^^ error[E0277]: ... cannot be known at compilation time | ||
|
@@ -1344,7 +1345,6 @@ impl<T> SizedTypeProperties for T {} | |
/// The following unstable features expand the functionality of `offset_of!`: | ||
/// | ||
/// * [`offset_of_enum`] — allows `enum` variants to be traversed as if they were fields. | ||
/// * [`offset_of_slice`] — allows getting the offset of a field of type `[T]`. | ||
/// | ||
/// # Examples | ||
/// | ||
|
@@ -1374,7 +1374,6 @@ impl<T> SizedTypeProperties for T {} | |
/// | ||
/// [dynamically sized]: https://doc.rust-lang.org/reference/dynamically-sized-types.html | ||
/// [`offset_of_enum`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-enum.html | ||
/// [`offset_of_slice`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/offset-of-slice.html | ||
#[stable(feature = "offset_of", since = "1.77.0")] | ||
#[allow_internal_unstable(builtin_syntax)] | ||
pub macro offset_of($Container:ty, $($fields:expr)+ $(,)?) { | ||
|
30 changes: 0 additions & 30 deletions
30
src/doc/unstable-book/src/language-features/offset-of-slice.md
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
//@run-pass | ||
#![feature(offset_of_slice)] | ||
|
||
use std::mem::offset_of; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a comment onto
require_type_has_static_alignment
that notes that changing the behavior will extend the functionality ofoffset_of
and is insta-stable?