Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
konstin opened this issue Jul 6, 2023 · 2 comments · Fixed by #240
Closed

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

konstin opened this issue Jul 6, 2023 · 2 comments · Fixed by #240

Comments

@konstin
Copy link

konstin commented Jul 6, 2023

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),+ $(,)?]) => {{
   |                 ^
@dtolnay
Copy link
Owner

dtolnay commented Jul 6, 2023

Good catch. Fixed in 1.0.42.

konstin added a commit to astral-sh/ruff that referenced this issue Jul 7, 2023
konstin added a commit to astral-sh/ruff that referenced this issue Jul 7, 2023
@konstin
Copy link
Author

konstin commented Jul 7, 2023

Thanks!

crapStone added a commit to Calciumdibromid/CaBr2 that referenced this issue Jul 10, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [thiserror](https://github.com/dtolnay/thiserror) | dependencies | patch | `1.0.40` -> `1.0.43` |

---

### Release Notes

<details>
<summary>dtolnay/thiserror (thiserror)</summary>

### [`v1.0.43`](dtolnay/thiserror@1.0.42...1.0.43)

[Compare Source](dtolnay/thiserror@1.0.42...1.0.43)

### [`v1.0.42`](https://github.com/dtolnay/thiserror/releases/tag/1.0.42)

[Compare Source](dtolnay/thiserror@1.0.41...1.0.42)

-   Fix compile error in derived Display impl if there was a nonstandard `write!` macro in scope ([#&#8203;239](dtolnay/thiserror#239))

### [`v1.0.41`](dtolnay/thiserror@1.0.40...1.0.41)

[Compare Source](dtolnay/thiserror@1.0.40...1.0.41)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNi4xLjExIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1955
Reviewed-by: crapStone <crapstone01@gmail.com>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants