Clarify preconditions of raw size/align methods - #158893
Conversation
The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future. Co-authored-by: Crystal Durham <cad97@cad97.com>
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
The one wrinkle with documenting this guarantee is that in order to rely on it you need to accept not only that it is sound to reborrow the pointer as a reference at this point, but also that it is safe to do so with respect to the rest of the program. I.e. computing the size/align could potentially require doing a read of the value (e.g. for a thin c string). Such is clearly sufficient to allow calling these functions. I'm just not fully confident that the actual requirement is made clear. I also am struggling to come up with a use case that would want this guarantee that couldn't just call the reference taking functions instead. |
Either it's safe to get a reference (and pass it to arbitrary safe code, including |
There was a problem hiding this comment.
I also am struggling to come up with a use case that would want this guarantee that couldn't just call the reference taking functions instead.
I guess the purpose here is rather making the safety contract complete for future unsized types. For that, I think the proposed one sounds clearer.
@CAD97 I'm happy to discuss further if needed, otherwise r= you & me
|
Ok, let's go ahead, this can be tweaked later if something else is raised. |
…r=JohnTitor Clarify preconditions of raw size/align methods The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future. Take 2 of rust-lang#103372, wording from @CAD97 in rust-lang#103372 (comment). Tracking issue: rust-lang#69835
Rollup of 9 pull requests Successful merges: - #153563 (Lint against iterator functions that panic when `N` is zero ) - #159960 (Allow `UnsafeCell` content access without `get` in `invalid_reference_casting` lint) - #158893 (Clarify preconditions of raw size/align methods) - #159220 (Don't optimize across storage markers in SimplifyComparisonIntegral) - #159309 (Move tests batch 18) - #159450 (Add codegen test for enum clone) - #160017 (Make BorrowSet methods public again) - #160022 (Refactor rustc_hir re-exports) - #160041 (Correct tracking issue for `casefold` feature)
Rollup merge of #158893 - Jules-Bertholet:for-pointer-docs, r=JohnTitor Clarify preconditions of raw size/align methods The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future. Take 2 of #103372, wording from @CAD97 in #103372 (comment). Tracking issue: #69835
The current documentation doesn't guarantee that these methods are safe to call for pointers derived from references to new unsized types that Rust may add in the future.
Take 2 of #103372, wording from @CAD97 in #103372 (comment).
Tracking issue: #69835