Skip to content
Myr

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

2 files+56 added−15 removed

modified:tests/ui/ensure-nonbool.rs+18 added-3 removed
1use anyhow::{ensure, Result};2use std::ops::Deref;34struct Bool(bool);56struct DerefBool(bool);78impl Deref for DerefBool {9 type Target = bool;10 fn deref(&self) -> &Self::Target {11 &self.012 }13}1415fn main() -> Result<()> {16 ensure!("...");176 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 }2223 let db = DerefBool(true);24 ensure!(db);25 ensure!(&db);2627 Ok(())28}
modified:tests/ui/ensure-nonbool.stderr+38 added-12 removed
1error[E0600]: cannot apply unary operator `!` to type `&'static str`2 --> tests/ui/ensure-nonbool.rs:4:53 |44 | 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 |416 | 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)89error[E0600]: cannot apply unary operator `!` to type `&mut bool`10 --> tests/ui/ensure-nonbool.rs:9:2511 |129 | 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 |1220 | 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)1617error[E0600]: cannot apply unary operator `!` to type `DerefBool`18 --> tests/ui/ensure-nonbool.rs:24:519 |2024 | ensure!(db);21 | ^^^^^^^^^^^ cannot apply unary operator `!`22 |23note: an implementation of `Not` might be missing for `DerefBool`24 --> tests/ui/ensure-nonbool.rs:6:125 |266 | struct DerefBool(bool);27 | ^^^^^^^^^^^^^^^^ must implement `Not`28note: 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)3435error[E0600]: cannot apply unary operator `!` to type `&DerefBool`36 --> tests/ui/ensure-nonbool.rs:25:537 |3825 | 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)