Skip to content

Commit

Permalink
Merge pull request #375 from dtolnay/unsized
Browse files Browse the repository at this point in the history
Support dynamically sized field in error
  • Loading branch information
dtolnay authored Nov 8, 2024
2 parents 6097d61 + 24c04da commit 2f6bff3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait AsDisplay<'a>: Sealed {

impl<'a, T> AsDisplay<'a> for &T
where
T: Display + 'a,
T: Display + ?Sized + 'a,
{
type Target = &'a T;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl<'a> AsDisplay<'a> for PathBuf {

#[doc(hidden)]
pub trait Sealed {}
impl<T: Display> Sealed for &T {}
impl<T: Display + ?Sized> Sealed for &T {}
#[cfg(feature = "std")]
impl Sealed for Path {}
#[cfg(feature = "std")]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ enum EnumPathBuf {
Read(PathBuf),
}

#[derive(Error, Debug)]
#[error("{tail}")]
pub struct UnsizedError {
pub head: i32,
pub tail: str,
}

fn assert<T: Display>(expected: &str, value: T) {
assert_eq!(expected, value.to_string());
}
Expand Down

0 comments on commit 2f6bff3

Please sign in to comment.