From 09c16ef1b0ab96c1091bfa6cca582fe9350ab9c6 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sat, 15 Dec 2018 20:43:01 -0700 Subject: [PATCH] clarification to const_assert --- book/src/01-quirks/05-static_asserts.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/book/src/01-quirks/05-static_asserts.md b/book/src/01-quirks/05-static_asserts.md index 845ede1..5c74184 100644 --- a/book/src/01-quirks/05-static_asserts.md +++ b/book/src/01-quirks/05-static_asserts.md @@ -52,11 +52,11 @@ name. const _: usize = 0 - 1; ``` -Now we wrap this in a macro where we give an expression for a bool. We negate -the bool then cast it to a `usize`, meaning that `true` negates into `false`, -which becomes `0usize`, and then there's no underflow error. Or if the input was -`false`, it negates into `true`, then becomes `1usize`, and then the underflow -error fires. +Now we wrap this in a macro where we give a `bool` expression as input. We +negate the bool then cast it to a `usize`, meaning that `true` negates into +`false`, which becomes `0usize`, and then there's no underflow error. Or if the +input was `false`, it negates into `true`, then becomes `1usize`, and then the +underflow error fires. ```rust macro_rules! const_assert { @@ -68,8 +68,14 @@ macro_rules! const_assert { } ``` -This allows anything which supports `core::ops::Not` and can then can cast into -`usize`, which technically isn't just `bool` values, but close enough. +Technically, written like this, the expression can be anything with a +`core::ops::Not` implementation that can also be `as` cast into `usize`. That's +`bool`, but also basically all the other number types. + +It doesn't really hurt if you want to `const_assert!` a number I guess. I mean, +any number other than the `MAX` value of an unsigned type or the `-1` value of +an unsigned type will fail such an assertion, but I bet you'll notice that you +did something wrong pretty quick. ## Asserting Something