Skip to content

Commit 6a07345

Browse files
committed
Add regression test for issue 398
error[E0425]: cannot find value `_0` in this scope --> tests/test_display.rs:308:17 | 308 | #[error("{0}")] | ^^^^^ not found in this scope error[E0425]: cannot find value `__display_x` in this scope --> tests/test_display.rs:310:17 | 310 | #[error("{x}")] | ^^^^^ not found in this scope
1 parent 9c0f2d2 commit 6a07345

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

tests/test_display.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn test_pointer() {
266266
}
267267

268268
#[test]
269-
fn test_macro_rules() {
269+
fn test_macro_rules_variant_from_call_site() {
270270
// Regression test for https://github.com/dtolnay/thiserror/issues/86
271271

272272
macro_rules! decl_error {
@@ -291,6 +291,30 @@ fn test_macro_rules() {
291291
assert("0", Error1::Repro(0));
292292
}
293293

294+
#[test]
295+
fn test_macro_rules_message_from_call_site() {
296+
// Regression test for https://github.com/dtolnay/thiserror/issues/398
297+
298+
macro_rules! decl_error {
299+
($($errors:tt)*) => {
300+
#[derive(Error, Debug)]
301+
pub enum Error {
302+
$($errors)*
303+
}
304+
};
305+
}
306+
307+
decl_error! {
308+
#[error("{0}")]
309+
Unnamed(u8),
310+
#[error("{x}")]
311+
Named { x: u8 },
312+
}
313+
314+
assert("0", Error::Unnamed(0));
315+
assert("0", Error::Named { x: 0 });
316+
}
317+
294318
#[test]
295319
fn test_raw() {
296320
#[derive(Error, Debug)]

0 commit comments

Comments
 (0)