Skip to content

Conversation

@RalfJung
Copy link
Member

Cc @jethrogb -- no idea why this created a slice only to directly convert it back to a raw pointer, but we can avoid this and in fact make the entire function safe. I didn't change the function signature (it's still an unsafe fn) as I know nothing about the surrounding code.

@rustbot rustbot added O-SGX Target: SGX S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 19, 2025

r? @ChrisDenton

rustbot has assigned @ChrisDenton.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@jethrogb
Copy link
Contributor

jethrogb commented Nov 19, 2025

no idea why

ptr::slice_from_raw_parts_mut was added in 8b21b07. This code was added in 1e44e2d, which predates that.

@jethrogb
Copy link
Contributor

make the entire function safe

So the Safety documentation section of the trait method seems to imply that the following invariant must be upheld

  • T: UserSafe implies that the memory location of T is in user (not enclave) memory.

However, I think that may be incorrect. I think a similar invariant is upheld by the UserRef and User types. Also UserSafe is implemented for regular primitive Rust types (like u8), so it sounds weird that implementing that trait somehow adds this kind of restriction.

@RalfJung
Copy link
Member Author

It is also generally odd to have a safety comment on a trait impl that's not the same as the one in the trait itself -- callers that use a generic T: UserSafe will not know about the specific requirement of this impl.

Anyway I won't be conducting a refactor of that trait here, I just noticed this little improvement inside the slice impl. I will leave follow-up cleanup to people that understand the surrounding context better :)

@ChrisDenton
Copy link
Member

Potential followups aside, this is strictly an improvement so...

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 20, 2025

📌 Commit 7ad3c5c has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 20, 2025
…enton

sgx: avoid unnecessarily creating a slice

Cc `@jethrogb` -- no idea why this created a slice only to directly convert it back to a raw pointer, but we can avoid this and in fact make the entire function safe. I didn't change the function signature (it's still an `unsafe fn`) as I know nothing about the surrounding code.
bors added a commit that referenced this pull request Nov 20, 2025
Rollup of 9 pull requests

Successful merges:

 - #149033 (autodiff rlib handling)
 - #149088 (Add missing trailing period to RustDoc for fn create_dir().)
 - #149111 (fs: Run file lock tests on all platforms that support it)
 - #149113 (sgx: avoid unnecessarily creating a slice)
 - #149123 (std: sys: fs: uefi: Fix FileAttr size)
 - #149125 (In `BTreeMap::eq`, do not compare the elements if the sizes are different.)
 - #149133 (Remove an unused variable)
 - #149134 (std: sys: net: uefi: Implement read_vectored)
 - #149139 (Enable host tools for aarch64-unknown-linux-ohos)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Nov 20, 2025
Rollup of 9 pull requests

Successful merges:

 - #149033 (autodiff rlib handling)
 - #149088 (Add missing trailing period to RustDoc for fn create_dir().)
 - #149111 (fs: Run file lock tests on all platforms that support it)
 - #149113 (sgx: avoid unnecessarily creating a slice)
 - #149123 (std: sys: fs: uefi: Fix FileAttr size)
 - #149133 (Remove an unused variable)
 - #149139 (Enable host tools for aarch64-unknown-linux-ohos)
 - #149144 (Reject `async fn` in `const impl` during AST validation)
 - #149154 (Fix platform supports docs tiny typo)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3e99b85 into rust-lang:main Nov 21, 2025
11 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 21, 2025
rust-timer added a commit that referenced this pull request Nov 21, 2025
Rollup merge of #149113 - RalfJung:sgx-less-unsafe, r=ChrisDenton

sgx: avoid unnecessarily creating a slice

Cc ``@jethrogb`` -- no idea why this created a slice only to directly convert it back to a raw pointer, but we can avoid this and in fact make the entire function safe. I didn't change the function signature (it's still an `unsafe fn`) as I know nothing about the surrounding code.
@RalfJung RalfJung deleted the sgx-less-unsafe branch November 21, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-SGX Target: SGX S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants