-
Notifications
You must be signed in to change notification settings - Fork 11
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
Fix undefined behaviour. #3
Conversation
Isn't here any way in which you could depend on Does |
I'd rather not pull in another crate for this - it's supposed to be dependency-free so that there is little cost to using it. In addition, this crate exposes a safe API whose safety is intricately linked with the acceptable inputs to the |
It does have to be public, but it could be |
You could verify on your end that this is really a struct field (basically copying just this line). |
There's also a big cost to having to maintain more spots that exploit internal compiler knowledge. This code here, just like the code in I find it silly to count "cost" purely as "number of dependencies". The cost of this crate in terms of maintenance goes up if you copy-paste stuff. |
I mean cost to users of the crate. There's a reason NPM gets a lot of hate. Anyway, putting that aside, I've thought about this some more. There are two pieces of "tricky unsafe code" to get right here:
When I wrote this crate I specifically wanted users to be able to create field offsets for more complex cases without users having to worry about (1). (For example, maybe a user want to get a field offset to an element of a fixed size array, something not possible with the macro). The intent was that they could just focus on being correct WRT (2) and (1) would be handled for them, and this is why that constructor was public. Unfortunately it has turned out that (2) is actually harder than (1), but I think there is still value in only having to worry about (2) and in the future it will get easier. If there was a crate which implemented this macro: |
The issue here is
Fair.
Hm, that is an interesting idea. Though that's a micro-crate if I've ever seen one. ;) Do you think it would make sense to add that to |
Eh, didn't mean to leave this sitting around so long. Going to merge this as I don't think further discussions will result in me changing the public API, even if I decide to change the implementation. |
@Diggsey do you think it would make sense to yank old versions of this crate that predate this UB fix? That way, |
Fixes #2