-
Notifications
You must be signed in to change notification settings - Fork 48
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
Attribute for trusted external static declarations #118
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. |
I agree with @Lokathor here. I think we got this one wrong. I'd like to see this proposal move forward, but I don't want to serve as the liaison for time reasons. =) |
I'm in favor of the idea as well; the details need working out (Send, Sync), but I'd like to do this. |
I can probably write the RFC, though folks were a little divided on the long term design. I'll leave the discussion of that design stuff to the Zulip thread though. |
Closing as an active initiative. Tracking issue: #149 |
Proposal
Summary and problem statement
Currently, the declaration of an extern static is "safe", and then the usage is "unsafe".
Please observe:
Motivation, use-cases, and solution sketches
Since you declare a thing once and use it many times, this is the exact opposite of an ideal situation.
The ideal is to lean towards unsafe creation and then safe use thereafter, whenever possible.
Say you have some external values that will be provided by the linker:
This is exactly the same sort of thing that one could declare and use safely within Rust.
The only concern is that the declaration of the extern might not match what the linker provides, and how any external code uses the data.
Assuming that the declaration is correct, there's no further reason to make interacting with the extern static be an unsafe operation.
Thus, we will provide a new attribute,
#[trusted_extern]
(bikeshed), which declares an absolute confidence in the correctness of the declaration.This attribute is an "unsafe attribute", similar to
#[no_mangle]
and others.It is disallowed when
#![forbid(unsafe_code)]
is in effect.When an extern static is marked with
#[trusted_extern]
, the code declaring the extern has asserted the full safety of the declaration, and so an unsafe block is not needed to use the static, exactly as if the extern static had been declared directly within rust itself.Links and related work
None at this time.
Initial people involved
The text was updated successfully, but these errors were encountered: