Skip to content

Commit

Permalink
Add ui test for incorrect type of ensure argument
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 17, 2024
1 parent 5152c1d commit f1cd62c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/ui/ensure-nonbool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use anyhow::{ensure, Result};

fn main() -> Result<()> {
ensure!("...");

struct Struct(bool);
let mut s = Struct(true);
match &mut s {
Struct(cond) => ensure!(cond),
}

Ok(())
}
15 changes: 15 additions & 0 deletions tests/ui/ensure-nonbool.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0600]: cannot apply unary operator `!` to type `&'static str`
--> tests/ui/ensure-nonbool.rs:4:5
|
4 | ensure!("...");
| ^^^^^^^^^^^^^^ cannot apply unary operator `!`
|
= 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)

error[E0600]: cannot apply unary operator `!` to type `&mut bool`
--> tests/ui/ensure-nonbool.rs:9:25
|
9 | Struct(cond) => ensure!(cond),
| ^^^^^^^^^^^^^ cannot apply unary operator `!`
|
= 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)

0 comments on commit f1cd62c

Please sign in to comment.