Skip to content

impl Not for ! - #91122

Merged
bors merged 4 commits into
rust-lang:masterfrom
dtolnay:not
Jan 23, 2022
Merged

impl Not for !#91122
bors merged 4 commits into
rust-lang:masterfrom
dtolnay:not

Conversation

@dtolnay

Copy link
Copy Markdown
Member

The lack of this impl caused trouble for me in some degenerate cases of macro-generated code of the form if !$cond {...}, even without feature(never_type) on a stable compiler. Namely if $cond contains a return or break or similar diverging expression, which would otherwise be perfectly legal in boolean position, the code previously failed to compile with:

error[E0600]: cannot apply unary operator `!` to type `!` --> library/core/tests/ops.rs:239:8 |239 | if !return () {} | ^^^^^^^^^^ cannot apply unary operator `!`

Currently fails to build:
error[E0600]: cannot apply unary operator `!` to type `!`
--> library/core/tests/ops.rs:239:8
|
239 | if !return () {}
| ^^^^^^^^^^ cannot apply unary operator `!`
@dtolnaydtolnay added T-libs-api [DEPRECATED; DO NOT USE] needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. labels Nov 22, 2021
@dtolnay

Copy link
Copy Markdown
MemberAuthor

It looks like highfive hasn't assigned this.
r? rust-lang/libs-api

@rust-log-analyzer

This comment has been minimized.

@dtolnaydtolnay added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 1, 2021
@dtolnaydtolnay added the I-libs-api-nominated [DEPRECATED; DO NOT USE] label Jan 5, 2022
@joshtriplettjoshtriplett added I-lang-nominated Nominated for discussion during a lang team meeting. and removed I-libs-api-nominated [DEPRECATED; DO NOT USE] labels Jan 5, 2022
@m-ou-se

Copy link
Copy Markdown
Member

@rfcbot merge

@rfcbot

rfcbot commented Jan 5, 2022

Copy link
Copy Markdown

Team member @m-ou-se has proposed to merge 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.

@rfcbotrfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 5, 2022
@joshtriplett

joshtriplett commented Jan 5, 2022

Copy link
Copy Markdown
Member

Nominating for the lang team because the libs-api team would like to check whether lang considers it a lang matter if we add impls of traits for !.

Note in particular that this will be visible in stable.

@scottmcm

Copy link
Copy Markdown
Member

Is this the first trait impl on ! for which there's an associated type?

Output = ! does seem reasonable for Not, but I wonder if this would be a good time to think about how to pick it more generally. Like Iterator for ! is particularly non-obvious to me.

So I don't really have any particular concern here, but this seems like it's setting a precedent for other things -- does Add for ! come next? -- where I'm not sure exactly what form it should have.

If there was going to be a lang thing here, it could be that the type checker just was smart about ! specifically. Since we might want something like impl<T> Add<!> for T and impl<T> Add<T> for !, but we can't have both of those. Maybe the answer there is that we want features for that overlap anyway?

@rfcbotrfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Jan 11, 2022
@rfcbot

Copy link
Copy Markdown

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbotrfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Jan 11, 2022
@joshtriplettjoshtriplett removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Jan 11, 2022
@Amanieu

Copy link
Copy Markdown
Member

Regarding Add, can we just have a single impl Add<!> for ! and let type coercion/inference do the rest?

Comment threadlibrary/core/src/ops/bit.rs Outdated
@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 20, 2022
@rfcbotrfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jan 21, 2022
@rfcbot

Copy link
Copy Markdown

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbotrfcbot added the to-announce Announce this issue on triage meeting label Jan 21, 2022
@m-ou-se

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Jan 22, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 3136c5f has been approved by m-ou-se

@borsbors 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 Jan 22, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 22, 2022
impl Not for !
The lack of this impl caused trouble for me in some degenerate cases of macro-generated code of the form `if !$cond {...}`, even without `feature(never_type)` on a stable compiler. Namely if `$cond` contains a `return` or `break` or similar diverging expression, which would otherwise be perfectly legal in boolean position, the code previously failed to compile with:
```console
error[E0600]: cannot apply unary operator `!` to type `!`
--> library/core/tests/ops.rs:239:8
|
239 | if !return () {}
| ^^^^^^^^^^ cannot apply unary operator `!`
```
This was referenced Jan 22, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 23, 2022
…askrgr
Rollup of 8 pull requests
Successful merges:
- rust-lang#90666 (Stabilize arc_new_cyclic)
- rust-lang#91122 (impl Not for !)
- rust-lang#93068 (Fix spacing for `·` between stability and source)
- rust-lang#93103 (Tweak `expr.await` desugaring `Span`)
- rust-lang#93113 (Unify search input and buttons size)
- rust-lang#93168 (update uclibc instructions for new toolchain, add link from platforms doc)
- rust-lang#93185 (rustdoc: Make some `pub` items crate-private)
- rust-lang#93196 (Remove dead code from build_helper)
Failed merges:
- rust-lang#93188 (rustdoc: fix bump down typing search on Safari)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 55a1f8b into rust-lang:masterJan 23, 2022
@rustbotrustbot added this to the 1.60.0 milestone Jan 23, 2022
@dtolnay
dtolnay deleted the not branch January 29, 2022 06:34
@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Feb 1, 2022
@dtolnaydtolnay removed 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. labels Jan 14, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

11 participants

@dtolnay@rust-log-analyzer@m-ou-se@rfcbot@joshtriplett@scottmcm@Amanieu@bors@teor2345@apiraino@rustbot