diff options
Diffstat (limited to 'third_party/rust/anyhow/tests/ui')
12 files changed, 122 insertions, 0 deletions
diff --git a/third_party/rust/anyhow/tests/ui/chained-comparison.rs b/third_party/rust/anyhow/tests/ui/chained-comparison.rs new file mode 100644 index 0000000000..4521b51c8c --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/chained-comparison.rs @@ -0,0 +1,8 @@ +use anyhow::{ensure, Result}; + +fn main() -> Result<()> { + // `ensure!` must not partition this into `(false) == (false == true)` + // because Rust doesn't ordinarily allow this form of expression. + ensure!(false == false == true); + Ok(()) +} diff --git a/third_party/rust/anyhow/tests/ui/chained-comparison.stderr b/third_party/rust/anyhow/tests/ui/chained-comparison.stderr new file mode 100644 index 0000000000..2a4c66508a --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/chained-comparison.stderr @@ -0,0 +1,10 @@ +error: comparison operators cannot be chained + --> tests/ui/chained-comparison.rs:6:19 + | +6 | ensure!(false == false == true); + | ^^ ^^ + | +help: split the comparison into two + | +6 | ensure!(false == false && false == true); + | ++++++++ diff --git a/third_party/rust/anyhow/tests/ui/empty-ensure.rs b/third_party/rust/anyhow/tests/ui/empty-ensure.rs new file mode 100644 index 0000000000..139b743bbf --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/empty-ensure.rs @@ -0,0 +1,6 @@ +use anyhow::{ensure, Result}; + +fn main() -> Result<()> { + ensure!(); + Ok(()) +} diff --git a/third_party/rust/anyhow/tests/ui/empty-ensure.stderr b/third_party/rust/anyhow/tests/ui/empty-ensure.stderr new file mode 100644 index 0000000000..bf0229a2b2 --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/empty-ensure.stderr @@ -0,0 +1,12 @@ +error: unexpected end of macro invocation + --> tests/ui/empty-ensure.rs:4:5 + | +4 | ensure!(); + | ^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$cond:expr` + --> src/ensure.rs + | + | ($cond:expr $(,)?) => { + | ^^^^^^^^^^ + = note: this error originates in the macro `$crate::__parse_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/anyhow/tests/ui/must-use.rs b/third_party/rust/anyhow/tests/ui/must-use.rs new file mode 100644 index 0000000000..ea4e58f55e --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/must-use.rs @@ -0,0 +1,11 @@ +#![deny(unused_must_use)] + +use anyhow::anyhow; + +fn main() -> anyhow::Result<()> { + if true { + // meant to write bail! + anyhow!("it failed"); + } + Ok(()) +} diff --git a/third_party/rust/anyhow/tests/ui/must-use.stderr b/third_party/rust/anyhow/tests/ui/must-use.stderr new file mode 100644 index 0000000000..e10bde40f7 --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/must-use.stderr @@ -0,0 +1,12 @@ +error: unused return value of `anyhow::__private::must_use` that must be used + --> tests/ui/must-use.rs:8:9 + | +8 | anyhow!("it failed"); + | ^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> tests/ui/must-use.rs:1:9 + | +1 | #![deny(unused_must_use)] + | ^^^^^^^^^^^^^^^ + = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/anyhow/tests/ui/no-impl.rs b/third_party/rust/anyhow/tests/ui/no-impl.rs new file mode 100644 index 0000000000..d2e89afc1b --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/no-impl.rs @@ -0,0 +1,8 @@ +use anyhow::anyhow; + +#[derive(Debug)] +struct Error; + +fn main() { + let _ = anyhow!(Error); +} diff --git a/third_party/rust/anyhow/tests/ui/no-impl.stderr b/third_party/rust/anyhow/tests/ui/no-impl.stderr new file mode 100644 index 0000000000..1ddf768639 --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/no-impl.stderr @@ -0,0 +1,31 @@ +error[E0599]: the method `anyhow_kind` exists for reference `&Error`, but its trait bounds were not satisfied + --> tests/ui/no-impl.rs:7:13 + | +4 | struct Error; + | ------------ + | | + | doesn't satisfy `Error: Into<anyhow::Error>` + | doesn't satisfy `Error: anyhow::kind::TraitKind` + | doesn't satisfy `Error: std::fmt::Display` +... +7 | let _ = anyhow!(Error); + | ^^^^^^^^^^^^^^ method cannot be called on `&Error` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `Error: Into<anyhow::Error>` + which is required by `Error: anyhow::kind::TraitKind` + `Error: std::fmt::Display` + which is required by `&Error: anyhow::kind::AdhocKind` + `&Error: Into<anyhow::Error>` + which is required by `&Error: anyhow::kind::TraitKind` +note: the traits `Into` and `std::fmt::Display` must be implemented + --> $RUST/core/src/fmt/mod.rs + | + | pub trait Display { + | ^^^^^^^^^^^^^^^^^ + | + ::: $RUST/core/src/convert/mod.rs + | + | pub trait Into<T>: Sized { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/third_party/rust/anyhow/tests/ui/temporary-value.rs b/third_party/rust/anyhow/tests/ui/temporary-value.rs new file mode 100644 index 0000000000..803809b238 --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/temporary-value.rs @@ -0,0 +1,5 @@ +use anyhow::anyhow; + +fn main() { + let _ = anyhow!(&String::new()); +} diff --git a/third_party/rust/anyhow/tests/ui/temporary-value.stderr b/third_party/rust/anyhow/tests/ui/temporary-value.stderr new file mode 100644 index 0000000000..dc27c4981f --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/temporary-value.stderr @@ -0,0 +1,9 @@ +error[E0716]: temporary value dropped while borrowed + --> tests/ui/temporary-value.rs:4:22 + | +4 | let _ = anyhow!(&String::new()); + | ---------^^^^^^^^^^^^^- + | | | + | | creates a temporary value which is freed while still in use + | temporary value is freed at the end of this statement + | argument requires that borrow lasts for `'static` diff --git a/third_party/rust/anyhow/tests/ui/wrong-interpolation.rs b/third_party/rust/anyhow/tests/ui/wrong-interpolation.rs new file mode 100644 index 0000000000..b870ca713d --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/wrong-interpolation.rs @@ -0,0 +1,5 @@ +use anyhow::{bail, Result}; + +fn main() -> Result<()> { + bail!("{} not found"); +} diff --git a/third_party/rust/anyhow/tests/ui/wrong-interpolation.stderr b/third_party/rust/anyhow/tests/ui/wrong-interpolation.stderr new file mode 100644 index 0000000000..55a2964113 --- /dev/null +++ b/third_party/rust/anyhow/tests/ui/wrong-interpolation.stderr @@ -0,0 +1,5 @@ +error: 1 positional argument in format string, but no arguments were given + --> tests/ui/wrong-interpolation.rs:4:12 + | +4 | bail!("{} not found"); + | ^^ |