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

impl Not for ! #91122

Merged
merged 4 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions library/core/src/ops/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ macro_rules! not_impl {

not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }

#[stable(feature = "not_never", since = "1.60.0")]
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
impl const Not for ! {
type Output = !;

#[inline]
fn not(self) -> ! {
match self {}
}
}

/// The bitwise AND operator `&`.
///
/// Note that `Rhs` is `Self` by default, but this is not mandatory.
Expand Down
6 changes: 6 additions & 0 deletions library/core/tests/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,9 @@ fn deref_on_ref() {
let y = deref(&mut x);
assert_eq!(y, 4);
}

#[test]
#[allow(unreachable_code)]
fn test_not_never() {
if !return () {}
}
4 changes: 2 additions & 2 deletions src/test/ui/reachable/expr_unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#![deny(unreachable_code)]

fn foo() {
let x: ! = ! { return; }; //~ ERROR unreachable
//~| ERROR cannot apply unary operator `!` to type `!`
let x: ! = * { return; }; //~ ERROR unreachable
//~| ERROR type `!` cannot be dereferenced
}

fn main() { }
10 changes: 5 additions & 5 deletions src/test/ui/reachable/expr_unary.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error[E0600]: cannot apply unary operator `!` to type `!`
error[E0614]: type `!` cannot be dereferenced
--> $DIR/expr_unary.rs:8:16
|
LL | let x: ! = ! { return; };
| ^^^^^^^^^^^^^ cannot apply unary operator `!`
LL | let x: ! = * { return; };
| ^^^^^^^^^^^^^

error: unreachable expression
--> $DIR/expr_unary.rs:8:16
|
LL | let x: ! = ! { return; };
LL | let x: ! = * { return; };
| ^^^^------^^^
| | |
| | any code following this expression is unreachable
Expand All @@ -21,4 +21,4 @@ LL | #![deny(unreachable_code)]

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0600`.
For more information about this error, try `rustc --explain E0614`.