Repository navigation
Relax safety documentation of FnPtr::from_ptr().
#163821
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -332,7 +332,8 @@ pub trait FnPtr: Copy { | |||||
| self.as_ptr().addr().get() | ||||||
| } | ||||||
|
|
||||||
| /// Returns the function pointer as a [`NonNull<Code>`]. | ||||||
| /// Returns the function pointer as a [`NonNull<Code>`], thus forgetting the signature and | ||||||
| /// everything else about the type except except the fact that it was a function pointer. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| #[unstable(feature = "fn_static", issue = "148768")] | ||||||
| #[lang = "fn_ptr_as_ptr"] | ||||||
| fn as_ptr(self) -> NonNull<Code>; | ||||||
|
|
@@ -341,9 +342,9 @@ pub trait FnPtr: Copy { | |||||
| /// | ||||||
| /// # Safety | ||||||
| /// | ||||||
| /// The function pointer must have been obtained | ||||||
| /// from an [`FnPtr::as_ptr`] call from a function | ||||||
| /// pointer type that is ABI compatible. | ||||||
| /// `ptr` must have been obtained from calling [`FnPtr::as_ptr`] on a function pointer type | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| /// that is ABI-compatible, or from an equivalent foreign operation (e.g. requesting a function | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ABI-compatible with what?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if this is correct.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not entirely sure this is correct either. It feels like we're back into the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this has anything to do with fn_addr_eq. It's just that the safety invariant for |
||||||
| /// pointer, of the appropriate ABI, from a dynamic loader by name). | ||||||
| #[unstable(feature = "fn_static", issue = "148768")] | ||||||
| #[lang = "fn_ptr_from_ptr"] | ||||||
| unsafe fn from_ptr(ptr: NonNull<Code>) -> Self; | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
Should we perhaps also link to the docs talking about the hazards of function pointers? In particular,
NonNull<Code>implementsPartialEq, but it has the same problems as "normal" function pointersfn()with regards to comparisons and identity.(also the wrong lint fires when you try to equate
NonNull<Code>, the wide pointer lint fires instead of the fn pointer comparison lint, but that should be fixed in a different PR)View changes since the review
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.
That seems fair. Potentially something like, in general, you should not expect to glean any useful information from this pointer besides converting it back into a function, and to link
fn_addr_eqto explain pitfalls.(whose docs I don't think have been updated yet, but will be)