Skip to content

Macro derive fails when a non-std write macro is in scope #239

@konstin

Description

@konstin

When we have our own custom write! macro with a different declaration than the std one in scope, the Error derive fails (playground):

use thiserror::Error;
use std::io;

/// Our custom write macro
#[macro_export]
macro_rules! write {
    ($dst:expr, [$($arg:expr),+ $(,)?]) => {{
        let result = $dst.write_fmt($crate::format_args!($($arg),+));
        result
    }}
}

#[derive(Error, Debug)]
pub enum FormatModuleError {
    #[error("io error: {0}")]
    IoError(io::Error),
}
error: no rules expected the token `"io error: {field__0}"`
  --> src/lib.rs:16:13
   |
6  | macro_rules! write {
   | ------------------ when calling this macro
...
16 |     #[error("io error: {0}")]
   |             ^^^^^^^^^^^^^^^ no rules expected this token in macro call
   |
note: while trying to match `[`
  --> src/lib.rs:7:17
   |
7  |     ($dst:expr, [$($arg:expr),+ $(,)?]) => {{
   |                 ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions