-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
add the bool::not method. #82786
add the bool::not method. #82786
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Well, now i need some outside advice on if i should change the test or just abandon the PR because T-libs doesn't even want this. |
Would be good to have the link to T-libs discussion in the PR description. |
I didn't create the PR in response to any particular T-libs discussion, other than musings that some people had in the edition prelude RFC. |
This comment has been minimized.
This comment has been minimized.
library/core/src/bool.rs
Outdated
/// assert_eq!(true.not(), false); | ||
/// ``` | ||
#[unstable(feature = "bool_not_method", issue = "none")] | ||
pub fn not(self) -> Self { |
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.
This method could be a const fn
, did you decide not to make it one to keep it identical to the Not::not
method?
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.
good point actually. i only thought of it initially as a replacement for the Not trait being in the prelude, but we could probably go const here.
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.
Tangentially, it being const
able already can also be an added argument for making it an inherent method
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.
Note that the intention is to make it possible to make trait impls const also, but we're pretty far from seeing that stabilized.
This comment has been minimized.
This comment has been minimized.
Hmm 🤔 while this method is unstable, what happens if somebody does: use ::core::ops::Not /* as _ */;
some_bool.not() ? Is there a way to make |
Triage: What's next steps here? |
I think this is waiting on review from @m-ou-se. |
Particularly, they (and the rest of libs) need to make a call on how to handle the failing tests. The code is not incorrect, rather the failing tests were written specifically against this situation. So either I'm told to change the tests or we abandon the PR entirely. |
Hey @rust-lang/libs, do any of you have an opinion on this addition? |
Personally, I'm ambivalent. One part of me doesn't want But, there is something to be said for reasonable people to disagree over which is more readable or not. And I doubt there will be much confusion between uses of |
Aside: a personal example of a preference for suffix negationSo I personally like the
That being said, I do think that since the language chose prefix One way to do things?I have personally often been skeptical of following the "there should be only one way to do things" idea too blindly, since in practice applying that policy too harshly makes that utopia quickly become a chimera: the natural evolution of a language is likely to end up offering alternative ways to express the same idea, and while feature creeping is a thing, stagnation is also another.
Natural languages do feature synonyms, and the context often suggests which ones are more accurate / adapted to the situation than others, and I think something similar applies to programming languages, no matter how much we may want a unified programming style 🙂 |
@danielhenrymantilla Just to make a small clarification: I specifically did not use the general language of "there should only be one way to do things." I am of course aware of the fact that Rust has never followed that philosophy generally and that Python has largely failed to do so despite it being a design goal. :-) But rather, I am expressing a more narrow opinion on this specific case. |
Mild support. I also hope we have an "inherent traits" mechanism in the future, in which case I'd be generally supportive of marking various traits inherent. |
I am personally not a fan of adding ad-hoc copes of random methods just to avoid an import. |
@sfackler This PR exists in the context of the Prelude changes arguments. By simply adding the one |
The job Click to see the possible cause of the failure (guessed by this bot)
|
@m-ou-se any updates? |
We discussed this in today's @rust-lang/libs meeting. We realized that if we add this, it'll start generating an "unused import" warning for everyone currently importing |
@rfcbot close |
Team member @joshtriplett has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I'll just close it then, the rfc check boxes seem like a needless formality if it's not going to be merged. |
This adds a
not
method to thebool
type so that you can callb.not()
without having to havecore::ops::Not
in scope. Also, a feature gate for the method.This is a much smaller overall change compared to placing
core::opt::Not
into the 2021 prelude (as some have proposed).(@jyn514 gave mild mentor advice on how to get started here and wanted a ping when it was posted)