-
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
Adding unsafe modules and unsafe blocks outside functions. #2148
Conversation
I like the general idea behind this RFC; but I think it needs to be a lot more detailed than it currently is. This should fit nicely in the ergonomics initiative to remove paper cuts. |
If this is something usually resorted to as temporary/prototype mechanism, would This would also avoid massive indent/unindent of mod body if the attribute is added or removed. |
You'd want this if your using the entire file as a module. It seems weird and non-local to have the unsafe declaration be in the lib.rs:
foo.rs
vs foo.rs
In fact, if you only get to use lib.rs
bin/foo.rs
|
But unsafe modules have an additional property. | ||
Using such a module is also unsafe: | ||
``` | ||
unsafe use test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this surprising, because use
doesn't need unsafe
to import other unsafe
things:
mod foo { pub unsafe fn bar() {} }
use foo::bar; // no unsafe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still perhaps understandable...? With normal modules the entire module isn't necessarily for unsafe stuff. And unsafe use can be good for greppability. Then again, you still have to be in "unsafe mode" to use the functions inside the module, and you can grow for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means that "this could just be implemented by some syntactic transformations" isn't true, though. It's a new concept that use
rs need to know, but I'm not convinced there's value in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wasn't sure if unsafe use is useful. But you don't even need to use
unsafe functions from safe modules, and just use them at other positions. Maybe just importing things from inside the module as unsafe would make sence? But I think I should remove unsafe
use
from the RFC entirely. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say just remove it, especially since it opens a bunch of questions about what paths involving the module would require. For example:
unsafe mod foo {
pub struct Bar;
}
use foo::Bar; // do I need `unsafe use` here?
(Thanks to Havvy for inspiration that led to this example.)
@Centril @egilburg @bbatha |
add alternative option `#[unsafe]`
Hmm, one can already define functions inside fn foo() {
let x: fn();
unsafe {
fn bar() {}
x = bar;
}
x()
} More generally, this RFC would mean that unsafe blocks would sometimes mean "I'm providing a safe interface over unsafe things" and sometimes "I'm defining a bunch of unsafe things" which are very different things, which makes me nervous. |
We want unsafety to be explicit and rare, so we should require that every An I think by analogy an |
A consistent treatment of this would mean that In general, I'm against this idea because |
I understand the problem with fn in unsafe blocks. |
I feel like the biggest issue here is motivation. I don't even see any problem to begin with - when is |
@rfcbot fcp postpone I'd rather not change anything about the syntax of |
Team member @nikomatsakis has proposed to postpone this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, 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! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
1 similar comment
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Appears even sorting out |
The final comment period is now complete. |
Closing as postponed. Thanks for the RFC, @porky11! |
This allows unsafe for blocks outside of functions and for modules.
It will enable faster prototyping and more compact writing of unsafe libs.
Edit: Rendered