-
Notifications
You must be signed in to change notification settings - Fork 69
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
allow arbitrary inherent impls in the standard library #487
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed. cc @rust-lang/compiler @rust-lang/compiler-contributors |
@rustbot second |
@rustbot label -final-comment-period +major-change-accepted |
…ou-se allow arbitrary inherent impls for builtin types in core Part of rust-lang/compiler-team#487. Slightly adjusted after some talks with `@m-ou-se` about the requirements of `t-libs-api`. This adds a crate attribute `#![rustc_coherence_is_core]` which allows arbitrary impls for builtin types in core. For other library crates impls for builtin types should be avoided if possible. We do have to allow the existing stable impls however. To prevent us from accidentally adding more of these in the future, there is a second attribute `#[rustc_allow_incoherent_impl]` which has to be added to **all impl items**. This only supports impls for builtin types but can easily be extended to additional types in a future PR. This implementation does not check for overlaps in these impls. Perfectly checking that requires us to check the coherence of these incoherent impls in every crate, as two distinct dependencies may add overlapping methods. It should be easy enough to detect if it goes wrong and the attribute is only intended for use inside of std. The first two commits are mostly unrelated cleanups.
…ochenkov generalize "incoherent impls" impl for user defined types To allow the move of `trait Error` into core. continues the work from rust-lang#94963, finishes rust-lang/compiler-team#487 r? `@petrochenkov` cc `@yaahc`
generalize "incoherent impls" impl for user defined types To allow the move of `trait Error` into core. continues the work from #94963, finishes rust-lang/compiler-team#487 r? `@petrochenkov` cc `@yaahc`
Proposal
We currently use a lot of different lang items to support inherent impls in the standard library, e.g.
https://github.com/rust-lang/rust/blob/6e5a6ffb14fc47051b0a23410c681ad6e4af045f/library/alloc/src/slice.rs#L659-L661
I intend to change both probe and coherence to deal with arbitrary inherent impls from all crates in the dependency crate with some special crate attribute, e.g.
#[rustc_arbitrary_inherent_impls]
. This change removes a lot of lang items and greatly improves the experience of library developers looking to move types into core. Alternatively, add 3 lang items for the cratescore
,alloc
andstd
to only search these.Having inherent impls for foreign types is sound and to my knowledge only forbidden because:
All of these things do not get worse if we stop requiring lang items in the standard library for this.
Mentors or Reviewers
If you have a reviewer or mentor in mind for this work, mention then
here. You can put your own name here if you are planning to mentor the
work.
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: