diff --git a/tests/test_display.rs b/tests/test_display.rs index 89bdc4a..7fad386 100644 --- a/tests/test_display.rs +++ b/tests/test_display.rs @@ -318,6 +318,15 @@ fn test_keyword() { assert("error: 1", Error); } +#[test] +fn test_self() { + #[derive(Error, Debug)] + #[error("error: {self:?}")] + struct Error; + + assert("error: Error", Error); +} + #[test] fn test_str_special_chars() { #[derive(Error, Debug)] diff --git a/tests/ui/display-underscore.rs b/tests/ui/display-underscore.rs new file mode 100644 index 0000000..335614b --- /dev/null +++ b/tests/ui/display-underscore.rs @@ -0,0 +1,7 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +#[error("{_}")] +pub struct Error; + +fn main() {} diff --git a/tests/ui/display-underscore.stderr b/tests/ui/display-underscore.stderr new file mode 100644 index 0000000..36882b9 --- /dev/null +++ b/tests/ui/display-underscore.stderr @@ -0,0 +1,7 @@ +error: invalid format string: invalid argument name `_` + --> tests/ui/display-underscore.rs:4:11 + | +4 | #[error("{_}")] + | ^ invalid argument name in format string + | + = note: argument name cannot be a single underscore