-
Notifications
You must be signed in to change notification settings - Fork 13k
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
improper_ctypes lint allows all "Option-like" enums, but we only guarantee this specifically for Option #130652
Comments
@RalfJung Frankly, the |
It also cannot be modified because even the smallest change, to not eagerly warn on things that are not a problem, is deferred to a T-lang decision, e.g. #116863 |
I already actively recommend to people to simply silence the lint, in direct communication, when it proves to be the slightest problem. I will feel forced to more proactively recommend silencing the lint if this is done, in venues like "the documentation for FFI libraries used by many corporations". Yyyes, it's kind of silly that we don't guarantee this quality for non-Option, non-Result enums that nonetheless "look like" Option and Result. But I already have enough trouble encouraging people to use the compiler correctly when things "don't cause problems in practice" (read: their code is actively UB but it hasn't visibly miscompiled yet). In this case, we actually do know it doesn't cause problems in practice. If we fix literally every other problem with ...well, that'll be a while, but then I'd endorse such an action: https://github.com/rust-lang/rust/issues?q=state%3Aopen%20label%3A%22L-improper_ctypes%22 Though, I'd probably file an RFC to extend the |
I don't think we need t-lang to make the lint fire on more cases. And it's not a false positive - those layouts are literally not guaranteed. Enum layout is very underspecified and adjusting the lint should come *after* specifying it more, if that is something someone is interested in pursuing.
|
I was under the impression that the null pointer optimization was guaranteed for all "Option-like" enums, but i can't find a normative reference for that closest i can find is this: |
Cc @chorman0773 |
It is, in fact, only guaranteed for |
The FCP here seems to have established a guarantee for all Option-like types? |
Interesting. It's not been documented outside of the UCG from what I can tell. |
In relation to the lint itself, I would agree with Jubilee also - even if this is a false negative, I'd very much prefer we fix the inordinate false positives before addressing false negatives. The lint is IMO useless as is, because of its false positives, so making it lint on more things (even things it should be linting on) isn't going to make it any more useful (can't catch a bug if the lint has been blanket allowed due to FP). |
Noting in passing this T-lang decision that specifically permits |
Interesting -- this was never put into any docs it seems, only the lint "knows" about this. |
That didn't update the layout chapter in the rust reference though. In fact the reference still doesn't mention niches at all, even the ones guaranteed in If a guarantee is made in an FCP and it's nowhere to be read, does that constitute a spec? 🌲🔉 |
@rust-lang/lang since this is a t-lang FCP (from five years ago), we'd be interested in your take on this. :) Does the behavior of the improper_ctypes lint, where all option-like enums are accepted for the null pointer layout guarantee, constitute a stable guarantee that we should properly document somewhere, or not? |
@rustbot labels -I-lang-nominated We discussed this in the triage meeting today and agreed that we meant what was in the FCP in #60300, that we're still OK with it, that it is (and has been) a language guarantee, and that we're OK with documenting it. Note that this guarantee will be subsumed by the one that we're making now via FCP in: |
Okay, I think that means we can close this issue -- thanks for clarifying! |
Ever since its introduction, the FFI safety lint has accepted
MyOption<Box<T>>
as FFI safe even ifMyOption
is not the "official"Option
type from libcore. This was originally done because "being sound but slightly incomplete is acceptable". However, it doesn't quite reflect today's approaches any more, and IMO the lint should be adjusted to match the documented guarantees -- which AFAIK only cover specificallyOption
, and not all "Option-like" types.Cc @rust-lang/opsem @workingjubilee @Noratrieb
The text was updated successfully, but these errors were encountered: