Skip to content

Commit

Permalink
Add regression test for issue 398
Browse files Browse the repository at this point in the history
    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
  • Loading branch information
dtolnay committed Dec 18, 2024
1 parent 9c0f2d2 commit 6a07345
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ fn test_pointer() {
}

#[test]
fn test_macro_rules() {
fn test_macro_rules_variant_from_call_site() {
// Regression test for https://github.com/dtolnay/thiserror/issues/86

macro_rules! decl_error {
Expand All @@ -291,6 +291,30 @@ fn test_macro_rules() {
assert("0", Error1::Repro(0));
}

#[test]
fn test_macro_rules_message_from_call_site() {
// Regression test for https://github.com/dtolnay/thiserror/issues/398

macro_rules! decl_error {
($($errors:tt)*) => {
#[derive(Error, Debug)]
pub enum Error {
$($errors)*
}
};
}

decl_error! {
#[error("{0}")]
Unnamed(u8),
#[error("{x}")]
Named { x: u8 },
}

assert("0", Error::Unnamed(0));
assert("0", Error::Named { x: 0 });
}

#[test]
fn test_raw() {
#[derive(Error, Debug)]
Expand Down

0 comments on commit 6a07345

Please sign in to comment.