Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[RFC] externally implementable functions #3632
base: master
Are you sure you want to change the base?
[RFC] externally implementable functions #3632
Changes from all commits
b0acfc6
13e0a58
c84a3c8
364552d
c9a3417
d77a2b9
95af3f8
651fe52
9be0f4d
12d72ee
4d5516d
e7644f2
cd37570
deb7ba1
01fbc99
d15cc37
1b56e58
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Could you clarify whether this is intended to also tie into visibility? For instance, a
pub(crate) extern impl fn
can only have an implementation provided by the crate, right?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.
The idea is that if you do:
The, other crates can provide an implementation (because
a
ispub
, allowing them to namea::x
), but they cannot call it (because the function is not public itself).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.
@m-ou-se That seems potentially confusing. Is there some way to set the visibility of being able to implement it? Is there value in being able to do so?
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.
No, because the point of this feature is allowing other crates to implement it. So unless you want to propose a kind of visibility that includes some crates but not others, that just implies full public.
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.
So if the
extern impl fn
is in a private module, it is impossible to implement?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.
@m-ou-se
Yeah this is very confusing. Could you make it respect the normal privacy rule and reuse e.g. #3323 to explicitly deny call/ref permission from dependencies?
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.
It could be re-exported, but that reexport then presumably allows both calling and implementing the item. The magic behavior where these two permissions are different can only be obtain via the original definition of the item, IIUC.
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 allow grouping multiple functions together like global_allocator in this RFC? Or should that be left as future potential improvement?
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 could work around that with a TAIT:
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.
I think that'd be part of a potential future (more compplicated) RFC, such as #2492
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.
Possibly global_alloc could at least use the same internal mechanism, even if it's not visible to the user?
could expand to something like
Then codegen and Miri would only have to support one such mechanism. :)
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 the following alternative be mentioned / discussed:
also just had the thought: does
use crateA::different_name as panic_handler
work similar to how (I believe) it works formain
?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.
Not a problem for this RFC since it's just a future possibility, but I wanted to write this up somewhere before I forget it again since it's non-obvious and I haven't seen it spelled out before: the "only one impl allowed, except that the declaration can include a default body" semantics work fine for the panic handler but not for the global allocator. The panic handler is declared and used in
core
,std
supplies a definition that can't be overridden once it's pulled in. In contrast, the global allocator is declared and used inalloc
, butstd
effectively adds a "default" implementation that can be overridden.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.
One approach to compatibility would be to start with this syntax already, and just artificially restrict the trait used to only have
Self
-less associated functions, I believe that is isomorphic to this proposal of defining global functions, and could then just be extended to support more trait features in the future (eventually I assume any object-safe trait could be used).