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 for builtin types in core #94963

Merged
merged 13 commits into from
Mar 30, 2022

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Mar 15, 2022

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.

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 15, 2022
@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 15, 2022
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor Author

lcnr commented Mar 15, 2022

alright, updating rustdoc should be an improvement over its current state, but it's a bit annoying. Will try to do that tomorrow

@oli-obk
Copy link
Contributor

oli-obk commented Mar 15, 2022

the changes lgtm (including query & metadata changes). Try running perfbot once rustdoc builds, too

@bors
Copy link
Contributor

bors commented Mar 15, 2022

☔ The latest upstream changes (presumably #94966) made this pull request unmergeable. Please resolve the merge conflicts.

@lcnr lcnr changed the title allow arbitrary inherent impls for lang items in std allow arbitrary inherent impls for builtin types in std Mar 16, 2022
@lcnr lcnr added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 18, 2022
@lcnr lcnr changed the title allow arbitrary inherent impls for builtin types in std allow arbitrary inherent impls for builtin types in core Mar 18, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Mar 18, 2022

r? @m-ou-se on the library part.

@rust-highfive rust-highfive assigned m-ou-se and unassigned oli-obk Mar 18, 2022
@lcnr
Copy link
Contributor Author

lcnr commented Mar 18, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 18, 2022
@bors
Copy link
Contributor

bors commented Mar 18, 2022

⌛ Trying commit a76419df6de185959c57105a84845e1f5cd15f52 with merge c633c9f813192ee63f4cd438fdc471caf6b78c47...

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 18, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2022
@lcnr
Copy link
Contributor Author

lcnr commented Mar 18, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3e75146): comparison url.

Summary: This benchmark run did not return any relevant results. 29 results were found to be statistically significant but too small to be relevant.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@eddyb
Copy link
Member

eddyb commented Apr 12, 2022

crate attribute #![rustc_coherence_is_core]

Why not "simply" make core (the whole crate) a lang item? I feel like most of this PR could've been avoided. Lang items already are robustly checked, why add more machinery?

bors added a commit to rust-lang-ci/rust that referenced this pull request 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`
bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2022
don't encode only locally used attrs

Part of rust-lang/compiler-team#505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc rust-lang#94963 (comment)
xFrednet pushed a commit to xFrednet/rust-clippy that referenced this pull request May 15, 2022
don't encode only locally used attrs

Part of rust-lang/compiler-team#505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc rust-lang/rust#94963 (comment)
|| found_assoc(tcx.types.u64)
|| found_assoc(tcx.types.u128)
|| found_assoc(tcx.types.f32)
|| found_assoc(tcx.types.f32);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line looks like a typo to me, should it be f64?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked by #114683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.