-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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_must_implement_one_of]
attribute
#92164
Implement #[rustc_must_implement_one_of]
attribute
#92164
Conversation
This comment has been minimized.
This comment has been minimized.
e86dc5a
to
db76b9e
Compare
#[rustc_must_implement_one_of]
attribute#[rustc_must_implement_one_of]
attribute
r? @Aaron1011 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite glad to see the eq
/ ne
etc. situation fixed that nicely 👌
Just a nit about favoring "(associated) function" terminology to "methods".
src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs
Outdated
Show resolved
Hide resolved
src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs
Outdated
Show resolved
Hide resolved
src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs
Outdated
Show resolved
Hide resolved
src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs
Outdated
Show resolved
Hide resolved
src/test/ui/traits/default-method/rustc_must_implement_one_of_misuse.rs
Outdated
Show resolved
Hide resolved
e4a0af2
to
105ae9c
Compare
This comment has been minimized.
This comment has been minimized.
105ae9c
to
f524d58
Compare
☔ The latest upstream changes (presumably #90639) made this pull request unmergeable. Please resolve the merge conflicts. |
hir::ItemKind::Trait(is_auto, unsafety, .., items) => { | ||
(is_auto == hir::IsAuto::Yes, unsafety, items) | ||
} | ||
hir::ItemKind::TraitAlias(..) => (false, hir::Unsafety::Normal, &[][..]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can just be &[]
instead of &[][..]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very disappointing; minimal repro: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=875b8d707eb70e293fc06d51eb6f26e0 — a type annotation at line 1201 does fix it, but without that a "wide pointer" field on one branch is not sufficient for a coercion to happen on other branches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, even a one element tuple is enough to demonstrate this: (play)
Can you rebase this against |
f524d58
to
96b2f8a
Compare
Use "(associated) function" terminology instead of "method". Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
This comment has been minimized.
This comment has been minimized.
It looks like you need to mark the test with |
This PR is currently broken because #90639 changed what values does |
This adds the old, pre 90639 `is_implemented` that previously only was true if the implementation of the item was from the given impl block and not from the trait default.
@Aaron1011 I rebased & fixed the problem, now it should work as expected again :') |
The test failed because order of items in a
|
@Aaron1011 I removed the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo that last tiny nit, the new improvements look good to me! (EDIT: I still can't r
stuff 😅)
@danielhenrymantilla: 🔑 Insufficient privileges: Not in reviewers |
@bors r+ |
📌 Commit 28edd7a has been approved by |
…askrgr Rollup of 10 pull requests Successful merges: - rust-lang#90498 (Clarifications in the target tier policy) - rust-lang#92164 (Implement `#[rustc_must_implement_one_of]` attribute) - rust-lang#92729 (rustc_codegen_llvm: Remove (almost) unused span parameter from many functions in metadata.rs) - rust-lang#92752 (Correct minor typos in some long error code explanations) - rust-lang#92801 (Enable wrapping words by default) - rust-lang#92825 (Rename environment variable for overriding rustc version) - rust-lang#92877 (Remove LLVMRustMarkAllFunctionsNounwind) - rust-lang#92936 (rustdoc: Remove `collect` in `html::markdown::parse`) - rust-lang#92956 (Add `log2` and `log10` to `NonZeroU*`) - rust-lang#92960 (Use `carrying_{mul|add}` in `num::bignum`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This reminds me the |
@oxalica personally I'd say that
trait Eq {
#[requires(neq)]
fn eq(&self, other: &Self) -> bool { !self.neq(other) }
#[requires(eq)]
fn neq(&self, other: &Self) -> bool { !self.eq(other) }
} |
I'm not really care about the detail of
I don't like the word |
…ort_for_must_implement, r=GuillaumeGomez rustdoc: Add support for `#[rustc_must_implement_one_of]` This PR adds support for `#[rustc_must_implement_one_of]` attribute added in rust-lang#92164. There is a desire to eventually use this attribute of `Read`, so making it show up in docs is a good thing. I "stole" the styling from cfg notes, not sure what would be a proper styling. Currently it looks like this: ![2022-07-14_15-00](https://user-images.githubusercontent.com/38225716/178968170-913c1dd5-8875-4a95-9848-b075a0bb8998.png) <details><summary>Code to reproduce</summary> <p> ```rust #![feature(rustc_attrs)] #[rustc_must_implement_one_of(a, b)] pub trait Trait { fn req(); fn a(){ Self::b() } fn b(){ Self::a() } } ``` </p> </details>
…table, r=Aaron1011 Implement `#[rustc_default_body_unstable]` 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: ```rust 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]`](rust-lang#92164), 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 😅
This PR adds a new attribute —
#[rustc_must_implement_one_of]
that allows changing the "minimal complete definition" of a trait. It's similar to GHC's minimal{-# MINIMAL #-}
pragma, though#[rustc_must_implement_one_of]
is weaker atm.Such attribute was long wanted. It can be, for example, used in
Read
trait to make transitions to recently addedread_buf
easier:For now, this is implemented as an internal attribute to start experimenting on the design of this feature. In the future we may want to extend it:
a | (b & c)
Eventually, we should make an RFC and make this (or rather similar) attribute public.
I'm fairly new to compiler development and not at all sure if the implementation makes sense, but at least it passes tests :)