-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Unsafe Extern Blocks #3484
Unsafe Extern Blocks #3484
Conversation
Co-authored-by: Jacob Lifshay <[email protected]>
Perhaps non- This would minimize churn in the language definition if any such targets appear in the future. (But maybe that's an insignificant concern since support for previous editions is still required.) |
a future RFC can always relax required keywords in certain situations, it wouldn't even be an edition-break issue at that point. but let's save that for a future RFC when we actually have a clear and specific fully working case. |
One concern about making the functions inside the For example, I could imagine people updating their projects, solving issues one by one, and resolving this issue by just changing an (Keep in mind that not every project uses |
maybe have a weak keyword unsafe extern "C" {
safe fn sqrtf(v: f32) -> f32;
unsafe fn printf(s: *const c_char, ...);
} |
I'm frustrated by this RFC because the overall direction is obviously right to me, but the overloading of |
One specific concern I have:
i.e., we have to weigh the risk of people accidentally writing |
Hey I'm all for a |
The T-lang team met to discuss this RFC today. We bikeshed'ed a bit and probably covered the same ground that was already covered in this comment thread above (e.g. the suggestion above of a weak In the end, we have the following proposal for how you might adjust this RFC to meet some broader goals that we identified. Proposal:(In this text, let the term "unadorned
Here are the various motivations/assumptions that led us to the proposal above:
|
@rustbot labels +I-lang-nominated +A-edition-2024 We met back on 2023-10-11 to discuss this RFC, and in that meeting, we hammered out a consensus for how to move forward on this as articulated by pnkfelix above. We've just been waiting for the RFC to be updated according to that consensus, and it now has been ( Let's nominate to discuss potentially moving forward on this for Rust 2024. |
Updates here look good! I this this is a good path forward and this version addresses the previous worries about changing something to be the opposite over an edition boundary. @rfcbot merge |
Team member @scottmcm has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
So in the 2024 edition from what I can tell, you wouldn't be able to use
There is a pretty big difference between a language keyword, and a substring of a function name. |
@tmccombs I'm pretty sure |
I think #[doc = include_str!("../README.md")]
extern {} // there's no reason this should be unsafe and I expect extern type declarations to also not need unsafe. |
I'm saying
#![warn(unsafe_code)]
std::arch::global_asm! { "" }
// ^ using this macro is unsafe even though it does not need an `unsafe` block
Strawman. For Additionally, existing (≤2021) |
I understand. And I'm saying that's bad as one now has to know a list of things in Rust that implicitly introduce unsafety, as opposed to the simple rule that I don't think my
That should be rectified, like we did with unsafe attributes. No reason to repeat past mistakes. |
@rustbot labels -I-lang-nominated We discussed this in the lang triage meeting today, and we confirmed that:
|
I was not in the meeting but I concur with this.
…On Wed, May 8, 2024, at 6:10 PM, Travis Cross wrote:
@rustbot <https://github.com/rustbot> labels -I-lang-nominated
We discussed this in the lang triage meeting today, and we confirmed that:
1. Our key motivation for this change is to make clear that the obligation for proving the correctness of the signatures within an `extern` block falls on the author of the `extern` block, not on the *caller* (or, in general, the *user*) of an item within an `extern` block.
2. We're happy with this motivation even if Rust could be fixed such that writing an `extern` block with incorrect signatures would not potentially cause the resulting program to exhibit undefined behavior even if those items were never used by Rust code.
—
Reply to this email directly, view it on GitHub <#3484 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABF4ZQDRVIMKE7GFO5HBHDZBJE73AVCNFSM6AAAAAA4OEIOO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBQHEZDKMZYHE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
The FCP for RFC 3484 has completed with a disposition to merge. Let's prepare to merge it.
We had earlier made clarifying edits to many sections, but not to all of them. Let's clarify some text in these remaining sections.
The lang team has accepted this RFC, and we've now merged it. Thanks to @Lokathor for pushing this forward, and thanks to all those who contributed helpful feedback. For further updates on this work, please follow the tracking issue: |
…li-obk Unsafe extern blocks This implements RFC 3484. Tracking issue rust-lang#123743 and RFC rust-lang/rfcs#3484 This is better reviewed commit by commit.
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC rust-lang/rfcs#3484 This is better reviewed commit by commit.
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC rust-lang/rfcs#3484 This is better reviewed commit by commit.
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC rust-lang/rfcs#3484 This is better reviewed commit by commit.
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC rust-lang/rfcs#3484 This is better reviewed commit by commit.
…-blocks, r=compiler-errors Stabilize unsafe extern blocks (RFC 3484) # Stabilization report ## Summary This is a tracking issue for the RFC 3484: Unsafe Extern Blocks We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](rust-lang/rfcs#3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use. RFC: rust-lang/rfcs#3484 Tracking issue: rust-lang#123743 ## What is stabilized ### Summary of stabilization We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results. ```rust unsafe extern { // sqrt (from libm) may be called with any `f64` pub safe fn sqrt(x: f64) -> f64; // strlen (from libc) requires a valid pointer, // so we mark it as being an unsafe fn pub unsafe fn strlen(p: *const c_char) -> usize; // this function doesn't say safe or unsafe, so it defaults to unsafe pub fn free(p: *mut core::ffi::c_void); pub safe static IMPORTANT_BYTES: [u8; 256]; pub safe static LINES: SyncUnsafeCell<i32>; } ``` ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`. ## History - rust-lang#124482 - rust-lang#124455 - rust-lang#125077 - rust-lang#125522 - rust-lang#126738 - rust-lang#126749 - rust-lang#126755 - rust-lang#126757 - rust-lang#126758 - rust-lang#126756 - rust-lang#126973 - rust-lang#127535 - rust-lang/rustfmt#6204 ## Unresolved questions I am not aware of any unresolved questions.
…-blocks, r=compiler-errors Stabilize unsafe extern blocks (RFC 3484) # Stabilization report ## Summary This is a tracking issue for the RFC 3484: Unsafe Extern Blocks We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](rust-lang/rfcs#3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use. RFC: rust-lang/rfcs#3484 Tracking issue: rust-lang#123743 ## What is stabilized ### Summary of stabilization We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results. ```rust unsafe extern { // sqrt (from libm) may be called with any `f64` pub safe fn sqrt(x: f64) -> f64; // strlen (from libc) requires a valid pointer, // so we mark it as being an unsafe fn pub unsafe fn strlen(p: *const c_char) -> usize; // this function doesn't say safe or unsafe, so it defaults to unsafe pub fn free(p: *mut core::ffi::c_void); pub safe static IMPORTANT_BYTES: [u8; 256]; pub safe static LINES: SyncUnsafeCell<i32>; } ``` ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`. ## History - rust-lang#124482 - rust-lang#124455 - rust-lang#125077 - rust-lang#125522 - rust-lang#126738 - rust-lang#126749 - rust-lang#126755 - rust-lang#126757 - rust-lang#126758 - rust-lang#126756 - rust-lang#126973 - rust-lang#127535 - rust-lang/rustfmt#6204 ## Unresolved questions I am not aware of any unresolved questions.
Rollup merge of rust-lang#127921 - spastorino:stabilize-unsafe-extern-blocks, r=compiler-errors Stabilize unsafe extern blocks (RFC 3484) # Stabilization report ## Summary This is a tracking issue for the RFC 3484: Unsafe Extern Blocks We are stabilizing `#![feature(unsafe_extern_blocks)]`, as described in [Unsafe Extern Blocks RFC 3484](rust-lang/rfcs#3484). This feature makes explicit that declaring an extern block is unsafe. Starting in Rust 2024, all extern blocks must be marked as unsafe. In all editions, items within unsafe extern blocks may be marked as safe to use. RFC: rust-lang/rfcs#3484 Tracking issue: rust-lang#123743 ## What is stabilized ### Summary of stabilization We now need extern blocks to be marked as unsafe and items inside can also have safety modifiers (unsafe or safe), by default items with no modifiers are unsafe to offer easy migration without surprising results. ```rust unsafe extern { // sqrt (from libm) may be called with any `f64` pub safe fn sqrt(x: f64) -> f64; // strlen (from libc) requires a valid pointer, // so we mark it as being an unsafe fn pub unsafe fn strlen(p: *const c_char) -> usize; // this function doesn't say safe or unsafe, so it defaults to unsafe pub fn free(p: *mut core::ffi::c_void); pub safe static IMPORTANT_BYTES: [u8; 256]; pub safe static LINES: SyncUnsafeCell<i32>; } ``` ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-extern-blocks`. ## History - rust-lang#124482 - rust-lang#124455 - rust-lang#125077 - rust-lang#125522 - rust-lang#126738 - rust-lang#126749 - rust-lang#126755 - rust-lang#126757 - rust-lang#126758 - rust-lang#126756 - rust-lang#126973 - rust-lang#127535 - rust-lang/rustfmt#6204 ## Unresolved questions I am not aware of any unresolved questions.
Rendered
Tracking:
Continuation of #3439, very sorry for the mix up, but when I went to make #3477 I deleted my
rfcs
repo fork and re-forked. I had forgotten that there was an open PR at the time.