-
Notifications
You must be signed in to change notification settings - Fork 28
[Coding Guideline]: Do Not Depend on Function Pointer Identity #256
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for scrc-coding-guidelines ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
|
||
| - Comparing function pointers for equality (``fn1 == fn2``) | ||
| - Assuming a unique function address | ||
| - Using function pointers as identity keys (e.g., in maps, registries, matchers) |
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.
you can still use function pointers as keys, they just don't have a one-to-one relationship to function items, so you can't rely on a function item giving the same function pointer or different items giving different pointers. (ignoring #[no_mangle]). so e.g. you can have a HashSet<fn()> and it works just fine as long as you don't assume inserting any particular function item does anything other than guaranteeing calling one or more of the entries is equivalent to calling that function item.
|
@rcseacord you'll want to consider this discussion before the guideline is ready for merge rust-lang/unsafe-code-guidelines#589, since it addresses the same topic |
|
FYI @rcseacord @manhatsu -- I got this building again, aside from the code examples, see: #287 Feel free to just yoink the commit from there and replace the commits on this feature branch (i.e. cherry-pick that commit I linked above onto your local updated That way we keep all the comment history from on here. (The coding examples also need to be updated to compile) |
25b657d to
4398ef0
Compare
Coding guidelines based on #255