Implement provenance preserving methods on NonNull#95556
Merged
bors merged 1 commit intorust-lang:masterfrom Apr 2, 2022
declanvk:nonnull-provenance
Merged
Implement provenance preserving methods on NonNull#95556bors merged 1 commit intorust-lang:masterfrom declanvk:nonnull-provenance
bors merged 1 commit intorust-lang:masterfrom
declanvk:nonnull-provenance
Conversation
**Description** Add the `addr`, `with_addr, `map_addr` methods to the `NonNull` type, and map the address type to `NonZeroUsize`. **Motiviation** The `NonNull` type is useful for implementing pointer types which have the 0-niche. It is currently possible to implement these provenance preserving functions by calling `NonNull::as_ptr` and `new_unchecked`. The addition of these methods simply make it more ergonomic to use. **Testing** Added a unit test of a nonnull tagged pointer type. This is based on some real code I have elsewhere, that currently routes the pointer through a `NonZeroUsize` and back out to produce a usable pointer.
Contributor
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon. Please see the contribution instructions for more information. |
Member
|
@bors r+ |
Member
|
@bors ping |
Collaborator
|
😪 I'm awake I'm awake |
Member
|
@bors r+ |
Collaborator
|
📌 Commit 2a82763 has been approved by |
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Apr 1, 2022
Implement provenance preserving methods on NonNull ### Description Add the `addr`, `with_addr`, `map_addr` methods to the `NonNull` type, and map the address type to `NonZeroUsize`. ### Motivation The `NonNull` type is useful for implementing pointer types which have the 0-niche. It is currently possible to implement these provenance preserving functions by calling `NonNull::as_ptr` and `new_unchecked`. The adding these methods makes it more ergonomic. ### Testing Added a unit test of a non-null tagged pointer type. This is based on some real code I have elsewhere, that currently routes the pointer through a `NonZeroUsize` and back out to produce a usable pointer. I wanted to produce an ideal version of the same tagged pointer struct that preserved pointer provenance. ### Related Extension of APIs proposed in rust-lang#95228 . I can also split this out into a separate tracking issue if that is better (though I may need some pointers on how to do that).
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Apr 1, 2022
Implement provenance preserving methods on NonNull ### Description Add the `addr`, `with_addr`, `map_addr` methods to the `NonNull` type, and map the address type to `NonZeroUsize`. ### Motivation The `NonNull` type is useful for implementing pointer types which have the 0-niche. It is currently possible to implement these provenance preserving functions by calling `NonNull::as_ptr` and `new_unchecked`. The adding these methods makes it more ergonomic. ### Testing Added a unit test of a non-null tagged pointer type. This is based on some real code I have elsewhere, that currently routes the pointer through a `NonZeroUsize` and back out to produce a usable pointer. I wanted to produce an ideal version of the same tagged pointer struct that preserved pointer provenance. ### Related Extension of APIs proposed in rust-lang#95228 . I can also split this out into a separate tracking issue if that is better (though I may need some pointers on how to do that).
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 2, 2022
Rollup of 8 pull requests Successful merges: - rust-lang#95354 (Handle rustc_const_stable attribute in library feature collector) - rust-lang#95373 (invalid_value lint: detect invalid initialization of arrays) - rust-lang#95430 (Disable #[thread_local] support on i686-pc-windows-msvc) - rust-lang#95544 (Add error message suggestion for missing noreturn in naked function) - rust-lang#95556 (Implement provenance preserving methods on NonNull) - rust-lang#95557 (Fix `thread_local!` macro to be compatible with `no_implicit_prelude`) - rust-lang#95559 (small type system refactoring) - rust-lang#95560 (convert more `DefId`s to `LocalDefId`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
RalfJung
reviewed
Apr 3, 2022
|
|
||
| /// Creates a new pointer by mapping `self`'s address to a new one. | ||
| /// | ||
| /// This is a convenience for [`with_addr`][Self::with_addr], see that method for details. |
Member
There was a problem hiding this comment.
Might be good to have a similar reference in the addr and with_addr docs?
Contributor
Author
There was a problem hiding this comment.
Do you mean references to the ptr::addr and ptr::with_addr from the NonNull versions? I can make a followup CR
Member
There was a problem hiding this comment.
Yes, that's what I mean. That would be great. :)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Add the
addr,with_addr,map_addrmethods to theNonNulltype, and map the address type toNonZeroUsize.Motivation
The
NonNulltype is useful for implementing pointer types which have the 0-niche. It is currently possible to implement these provenance preserving functions by callingNonNull::as_ptrandnew_unchecked. The adding these methods makes it more ergonomic.Testing
Added a unit test of a non-null tagged pointer type. This is based on some real code I have elsewhere, that currently routes the pointer through a
NonZeroUsizeand back out to produce a usable pointer. I wanted to produce an ideal version of the same tagged pointer struct that preserved pointer provenance.Related
Extension of APIs proposed in #95228 . I can also split this out into a separate tracking issue if that is better (though I may need some pointers on how to do that).