summaryrefslogtreecommitdiffstats
path: root/vendor/anyhow/tests/test_ensure.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/anyhow/tests/test_ensure.rs')
-rw-r--r--vendor/anyhow/tests/test_ensure.rs39
1 files changed, 30 insertions, 9 deletions
diff --git a/vendor/anyhow/tests/test_ensure.rs b/vendor/anyhow/tests/test_ensure.rs
index cbcba5798..6984c7d11 100644
--- a/vendor/anyhow/tests/test_ensure.rs
+++ b/vendor/anyhow/tests/test_ensure.rs
@@ -1,4 +1,5 @@
#![allow(
+ clippy::bool_to_int_with_if,
clippy::diverging_sub_expression,
clippy::if_same_then_else,
clippy::ifs_same_cond,
@@ -17,10 +18,12 @@
irrefutable_let_patterns
)]
+use self::Enum::Generic;
use anyhow::{anyhow, ensure, Chain, Error, Result};
-use std::fmt::Debug;
+use std::fmt::{self, Debug};
use std::iter;
use std::marker::{PhantomData, PhantomData as P};
+use std::mem;
use std::ops::Add;
use std::ptr;
@@ -43,6 +46,24 @@ trait Trait: Sized {
impl<T> Trait for T {}
+enum Enum<T: ?Sized> {
+ #[allow(dead_code)]
+ Thing(PhantomData<T>),
+ Generic,
+}
+
+impl<T: ?Sized> PartialEq for Enum<T> {
+ fn eq(&self, rhs: &Self) -> bool {
+ mem::discriminant(self) == mem::discriminant(rhs)
+ }
+}
+
+impl<T: ?Sized> Debug for Enum<T> {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ formatter.write_str("Generic")
+ }
+}
+
#[track_caller]
fn assert_err<T: Debug>(result: impl FnOnce() -> Result<T>, expected: &'static str) {
let actual = result().unwrap_err().to_string();
@@ -355,27 +376,27 @@ fn test_path() {
let test = || Ok(ensure!(E::U::<u8,>>E::U));
assert_err(test, "Condition failed: `E::U::<u8> > E::U` (U vs U)");
- let test = || Ok(ensure!(PhantomData::<dyn Debug + Sync> != PhantomData));
+ let test = || Ok(ensure!(Generic::<dyn Debug + Sync> != Generic));
assert_err(
test,
- "Condition failed: `PhantomData::<dyn Debug + Sync> != PhantomData` (PhantomData vs PhantomData)",
+ "Condition failed: `Generic::<dyn Debug + Sync> != Generic` (Generic vs Generic)",
);
- let test = || Ok(ensure!(PhantomData::<dyn Fn() + Sync> != PhantomData));
+ let test = || Ok(ensure!(Generic::<dyn Fn() + Sync> != Generic));
assert_err(
test,
- "Condition failed: `PhantomData::<dyn Fn() + Sync> != PhantomData` (PhantomData vs PhantomData)",
+ "Condition failed: `Generic::<dyn Fn() + Sync> != Generic` (Generic vs Generic)",
);
#[rustfmt::skip]
let test = || {
Ok(ensure!(
- PhantomData::<dyn Fn::() + ::std::marker::Sync> != PhantomData
+ Generic::<dyn Fn::() + ::std::marker::Sync> != Generic
))
};
assert_err(
test,
- "Condition failed: `PhantomData::<dyn Fn() + ::std::marker::Sync> != PhantomData` (PhantomData vs PhantomData)",
+ "Condition failed: `Generic::<dyn Fn() + ::std::marker::Sync> != Generic` (Generic vs Generic)",
);
}
@@ -408,7 +429,7 @@ fn test_trailer() {
let test = || Ok(ensure!(PhantomData::<u8> {} != PhantomData));
assert_err(
test,
- "Condition failed: `PhantomData::<u8> {} != PhantomData` (PhantomData vs PhantomData)",
+ "Condition failed: `PhantomData::<u8> {} != PhantomData` (PhantomData<u8> vs PhantomData<u8>)",
);
let result = Ok::<_, Error>(1);
@@ -596,7 +617,7 @@ fn test_as() {
};
assert_err(
test,
- "Condition failed: `PhantomData as PhantomData<<i32 as ToOwned>::Owned> != PhantomData` (PhantomData vs PhantomData)",
+ "Condition failed: `PhantomData as PhantomData<<i32 as ToOwned>::Owned> != PhantomData` (PhantomData<i32> vs PhantomData<i32>)",
);
macro_rules! int {