Skip to content
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

Closed
1 of 3 tasks
lcnr opened this issue Mar 1, 2022 · 3 comments
Closed
1 of 3 tasks

allow arbitrary inherent impls in the standard library #487

lcnr opened this issue Mar 1, 2022 · 3 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 1, 2022

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 crates core, alloc and std to only search these.

Having inherent impls for foreign types is sound and to my knowledge only forbidden because:

  • foreign crates adding inherent items for your type causes the addition of something with the same name to be a breaking change
  • if ever crate could add inherent impls for foreign types, we would have to always check all dependencies when searching for them, probably impacting perf
  • probably also just easier to reason about for users, so general lang design reasons ✨

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:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

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.

@lcnr lcnr added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Mar 1, 2022
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2022

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 rustbot added the to-announce Announce this issue on triage meeting label Mar 1, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Mar 1, 2022

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Mar 1, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Mar 3, 2022
@apiraino
Copy link
Contributor

@rustbot label -final-comment-period +major-change-accepted

@rustbot rustbot added major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement labels Mar 15, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Mar 17, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 30, 2022
…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.
bors added a commit to rust-lang-ci/rust that referenced this issue May 5, 2022
…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`
workingjubilee pushed a commit to tcdi/postgrestd that referenced this issue Sep 15, 2022
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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

4 participants