impl Not for ! by dtolnay · Pull Request #91122 · rust-lang/rust · GitHub

 1 year ago
source link: https://github.com/rust-lang/rust/pull/91122
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link


dtolnay commented on Nov 22, 2021

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 `!`

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK