From 9bd74a15407da67b4c584434afe5f66da03a06c6 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 4 Oct 2022 21:52:37 -0700 Subject: [PATCH] Restore pre-nightly-2022-10-05 behavior of test_path PhantomData tests --- tests/test_ensure.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/test_ensure.rs b/tests/test_ensure.rs index 296ccd4..6984c7d 100644 --- a/tests/test_ensure.rs +++ b/tests/test_ensure.rs @@ -18,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; @@ -44,6 +46,24 @@ trait Trait: Sized { impl Trait for T {} +enum Enum { + #[allow(dead_code)] + Thing(PhantomData), + Generic, +} + +impl PartialEq for Enum { + fn eq(&self, rhs: &Self) -> bool { + mem::discriminant(self) == mem::discriminant(rhs) + } +} + +impl Debug for Enum { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("Generic") + } +} + #[track_caller] fn assert_err(result: impl FnOnce() -> Result, expected: &'static str) { let actual = result().unwrap_err().to_string(); @@ -356,27 +376,27 @@ fn test_path() { let test = || Ok(ensure!(E::U::>E::U)); assert_err(test, "Condition failed: `E::U:: > E::U` (U vs U)"); - let test = || Ok(ensure!(PhantomData:: != PhantomData)); + let test = || Ok(ensure!(Generic:: != Generic)); assert_err( test, - "Condition failed: `PhantomData:: != PhantomData`", + "Condition failed: `Generic:: != Generic` (Generic vs Generic)", ); - let test = || Ok(ensure!(PhantomData:: != PhantomData)); + let test = || Ok(ensure!(Generic:: != Generic)); assert_err( test, - "Condition failed: `PhantomData:: != PhantomData`", + "Condition failed: `Generic:: != Generic` (Generic vs Generic)", ); #[rustfmt::skip] let test = || { Ok(ensure!( - PhantomData:: != PhantomData + Generic:: != Generic )) }; assert_err( test, - "Condition failed: `PhantomData:: != PhantomData`", + "Condition failed: `Generic:: != Generic` (Generic vs Generic)", ); }