-
Notifications
You must be signed in to change notification settings - Fork 59
Document (for the purpose of education) cases where Rust gives unsafe code fewer guarantees than C/C++ code has come to rely on #294
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
Comments
I think it's fine enough to document "this is what the compiler does today but we might change it later" |
Good idea! Items 2 and 3 are fundamentally the same thing: Stacked Borrows (or whatever the final aliasing model for Rust will be). Rust references also have an initialization invariant that does not match anything in C -- but then, C doesn't have anything even resembling that type. However, C++ has references, so it might make sense to compare those. To my knowledge, C++ references have to be dereferencable under some conditions even when not used (in particular, when they are passed to a function). But do they also have to be aligned? Also Rust likely requires dereferencability in more situations than C++ does. |
Another thing to possibly add to the list: equality on function pointers (because we use "unstable address" for all functions). And maybe the same for vtables? Not sure what C++ does there; it also seems less relevant there since vtable ptrs do not affect |
Sure, but I think it might be better for the purposes of education to separate and explicitly mention some of the different consequences of stacked borrows. As it is, pointing someone at the stacked borrows doc is usually met with a glazey stare, and while many things are discussed either here or in zulip, it can be difficult to find a concrete place to point (especially as "zulip conversation" is behind a login, and seems likely to be especially unconvincing, as message-board threads tend to be) I'm not sure about the precise invariants around references. I agree it does make sense to compare that sort of thing — it proabbly is worth calling out that Rust references do require alignment regardless of whether C++'s do as well, as whatever the answer is, it seems likely that a subset of people believe the wrong thing about it. |
Oh, I fully agree, I just want to be sure we also have the actual underlying reasons for these things documented. :)
I'd probably generalize this to the entire concept of initialization invariants.
|
There is a zulip archive that doesn't need a login: https://zulip-archive.rust-lang.org/ |
#292 gave me this idea, but is in some sense the opposite.
ISTM that a valuable addition for the purpose of education would be a set of cases where Rust differs from what C or C++ systems programmers expect, in the direction of patterns they expect to work to be either unreliable, or flat out UB.
Some examples of this are:
This is tricky, since many of these are still in flux, and are things we might not want to actually commit to — however, documenting them is effectively committing to them...
P.S. sorry if this issue exists somewhere, I didn't see it.
The text was updated successfully, but these errors were encountered: