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

Implement #[rustc_default_body_unstable] #96478

Merged
merged 8 commits into from
Aug 9, 2022

Conversation

WaffleLapkin
Copy link
Member

This PR implements a new stability attribute — #[rustc_default_body_unstable].

#[rustc_default_body_unstable] controls the stability of default bodies in traits.
For example:

pub trait Trait {
    #[rustc_default_body_unstable(feature = "feat", isssue = "none")]
    fn item() {}
}

In order to implement Trait user needs to either

  • implement item (even though it has a default implementation)
  • enable #![feature(feat)]

This is useful in conjunction with #[rustc_must_implement_one_of], we may want to relax requirements for a trait, for example allowing implementing either of PartialEq::{eq, ne}, but do so in a safe way — making implementation of only PartialEq::ne unstable.

r? @Aaron1011
cc @nrc (iirc you were interested in this wrt read_buf), @danielhenrymantilla (you were interested in the related #[rustc_must_implement_one_of])
P.S. This is my first time working with stability attributes, so I'm not sure if I did everything right 😅

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 27, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 27, 2022
@rust-log-analyzer

This comment has been minimized.

@WaffleLapkin WaffleLapkin force-pushed the rustc_default_body_unstable branch 3 times, most recently from 4d1cee1 to 35a5566 Compare April 27, 2022 17:35
@bors
Copy link
Contributor

bors commented May 22, 2022

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

@JohnCSimon
Copy link
Member

Ping from triage:
@WaffleLapkin can you please fix the merge conflicts?

@WaffleLapkin WaffleLapkin force-pushed the rustc_default_body_unstable branch 2 times, most recently from 67118a6 to 6d86e5d Compare June 20, 2022 12:39
@bors
Copy link
Contributor

bors commented Jul 14, 2022

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

This attribute allows to mark default body of a trait function as
unstable. This means that implementing the trait without implementing
the function will require enabling unstable feature.

This is useful in conjunction with `#[rustc_must_implement_one_of]`,
we may want to relax requirements for a trait, for example allowing
implementing either of `PartialEq::{eq, ne}`, but do so in a safe way
-- making implementation of only `PartialEq::ne` unstable.
@Aaron1011
Copy link
Member

Sorry for the extreme delay - I had forgotten that this was assigned to me.

This looks good to me overall - do we need lang-team signoff before adding this?

@WaffleLapkin
Copy link
Member Author

do we need lang-team signoff before adding this?

I don't know, maybe 😄

@Aaron1011
Copy link
Member

r=me after confirmation from the libs teem that this is okay (or after an FCP if needed)

@WaffleLapkin
Copy link
Member Author

@Aaron1011 why libs team approval is needed? This PR doesn't change any library APIs after all.

Quoting @scottmcm on zulip:

Looks like it doesn't change anything in library at all? If this is just a compiler feature that could be used in library later, then I don't think it's blocked on libs review.

@Aaron1011
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 8, 2022

📌 Commit 95bf0fb has been approved by Aaron1011

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 8, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 9, 2022
Rollup of 7 pull requests

Successful merges:

 - rust-lang#96478 (Implement `#[rustc_default_body_unstable]`)
 - rust-lang#99787 (Rustdoc-Json: Document HRTB's on DynTrait)
 - rust-lang#100181 (add method to get the mutability of an AllocId)
 - rust-lang#100221 (Don't document impossible to call default trait items on impls)
 - rust-lang#100228 (Don't ICE while suggesting updating item path.)
 - rust-lang#100301 (Avoid `&str` to `String` conversions)
 - rust-lang#100305 (Suggest adding an appropriate missing pattern excluding comments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1dc4858 into rust-lang:master Aug 9, 2022
@rustbot rustbot added this to the 1.65.0 milestone Aug 9, 2022
@WaffleLapkin WaffleLapkin deleted the rustc_default_body_unstable branch January 13, 2023 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants