Skip to content
Myr

Merge pull request #365 from dtolnay/ensuretype

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add tests for `ensure!` with non-bool argument

authored by David Tolnay · committed by GitHub · parents 96f0392, eb8becf · Browse files · 3 files+46 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+46 added−1 removed

  • tests:+46 added−1 removed

3 files+46 added−1 removed

added:tests/ui/ensure-nonbool.rs+13 added
1use anyhow::{ensure, Result};23fn main() -> Result<()> {4 ensure!("...");56 struct Struct(bool);7 let mut s = Struct(true);8 match &mut s {9 Struct(cond) => ensure!(cond),10 }1112 Ok(())13}
added:tests/ui/ensure-nonbool.stderr+15 added
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)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)
modified:tests/test_macros.rs+18 added-1 removed
1 unmodified line
2 clippy::assertions_on_result_states,3 clippy::eq_op,4 clippy::incompatible_msrv, // https://github.com/rust-lang/rust-clippy/issues/122575 clippy::items_after_statements,6 clippy::match_single_binding,7 clippy::needless_pass_by_value,8 clippy::shadow_unrelated,9 clippy::wildcard_imports10)]1112mod common;1314use self::common::*;14use anyhow::{anyhow, ensure};15use anyhow::{anyhow, ensure, Result};16use std::cell::Cell;17use std::future;1819#[test]
34 unmodified lines
54 );55}5657#[test]58fn test_ensure_nonbool() {59 struct Struct {60 condition: bool,61 }6263 fn f(s: &Struct) -> Result<()> {64 match s {65 Struct { condition } => ensure!(condition), // &bool66 }67 Ok(())68 }6970 f(&Struct { condition: true }).unwrap();71}7273#[test]74fn test_temporaries() {75 fn require_send_sync(_: impl Send + Sync) {}7677 require_send_sync(async {
21 unmodified lines