Skip to content

allow arbitrary inherent impls in the standard library #487

Closed
@lcnr

Description

@lcnr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was accepted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions