Add ensure test with a Deref to bool
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Tolnay · committed by David Tolnay · parent 52a46eb · Browse files · 2 files·+56 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+56 added−15 removed
- tests:+56 added−15 removed
Provenance
- Commit
85f0a69- Tree
529fc61- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
52a46eb
2 files changed+56 added−15 removed
modified:tests/ui/ensure-nonbool.rs+18 added-3 removed
1 use anyhow::{ensure, Result};2+use std::ops::Deref;3 4+struct Bool(bool);5+6+struct DerefBool(bool);7+8+impl Deref for DerefBool {9+ type Target = bool;10+ fn deref(&self) -> &Self::Target {11+ &self.012+ }13+}14+15 fn main() -> Result<()> {16 ensure!("...");17 6- struct Struct(bool);7- let mut s = Struct(true);18+ let mut s = Bool(true);19 match &mut s {9- Struct(cond) => ensure!(cond),20+ Bool(cond) => ensure!(cond),21 }22 23+ let db = DerefBool(true);24+ ensure!(db);25+ ensure!(&db);26+27 Ok(())28 }modified:tests/ui/ensure-nonbool.stderr+38 added-12 removed
1 error[E0600]: cannot apply unary operator `!` to type `&'static str`2- --> tests/ui/ensure-nonbool.rs:4:53- |4-4 | ensure!("...");5- | ^^^^^^^^^^^^^^ cannot apply unary operator `!`6- |7- = note: this error originates in the macro `$crate::__fallback_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)2+ --> tests/ui/ensure-nonbool.rs:16:53+ |4+16 | ensure!("...");5+ | ^^^^^^^^^^^^^^ cannot apply unary operator `!`6+ |7+ = note: this error originates in the macro `$crate::__fallback_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)8 9 error[E0600]: cannot apply unary operator `!` to type `&mut bool`10- --> tests/ui/ensure-nonbool.rs:9:2511- |12-9 | Struct(cond) => ensure!(cond),13- | ^^^^^^^^^^^^^ cannot apply unary operator `!`14- |15- = note: this error originates in the macro `$crate::__fallback_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)10+ --> tests/ui/ensure-nonbool.rs:20:2311+ |12+20 | Bool(cond) => ensure!(cond),13+ | ^^^^^^^^^^^^^ cannot apply unary operator `!`14+ |15+ = note: this error originates in the macro `$crate::__fallback_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)16+17+error[E0600]: cannot apply unary operator `!` to type `DerefBool`18+ --> tests/ui/ensure-nonbool.rs:24:519+ |20+24 | ensure!(db);21+ | ^^^^^^^^^^^ cannot apply unary operator `!`22+ |23+note: an implementation of `Not` might be missing for `DerefBool`24+ --> tests/ui/ensure-nonbool.rs:6:125+ |26+6 | struct DerefBool(bool);27+ | ^^^^^^^^^^^^^^^^ must implement `Not`28+note: the trait `Not` must be implemented29+ --> $RUST/core/src/ops/bit.rs30+ |31+ | pub trait Not {32+ | ^^^^^^^^^^^^^33+ = note: this error originates in the macro `$crate::__fallback_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)34+35+error[E0600]: cannot apply unary operator `!` to type `&DerefBool`36+ --> tests/ui/ensure-nonbool.rs:25:537+ |38+25 | ensure!(&db);39+ | ^^^^^^^^^^^^ cannot apply unary operator `!`40+ |41+ = note: this error originates in the macro `$crate::__fallback_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info)