Skip to content

Malformed suggestion for E0308 when macros are involved #140659

@nagisa

Description

@nagisa

I don't have the time to minimize this right now so I've committed the intermediate state that produces a pretty weird suggestion that's invalid:

error[E0308]: mismatched types
    --> crates/wasm-encoder/src/reencode.rs:1727:9
     |
1727 |         wasmparser::for_each_operator!(translate)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `Result<u32, <T as Reencode>::Error>`
     |
     = note: expected type `u32`
                found enum `core::result::Result<u32, <T as Reencode>::Error>`
     = note: this error originates in the macro `wasmparser::for_each_operator` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use the `?` operator to extract the `core::result::Result<u32, <T as Reencode>::Error>` value, propagating a `Result::Err` value to the caller
     |
1727 |         wasmparser::for_each_operator!(translate): tag_index?
     |                                                  ++++++++++++

You can find the reproducing code at https://github.com/nagisa/wasm-tools/tree/weird-diagnostic and running cargo check --all-features.

Reproduces both on stable and nightly:

cargo 1.88.0-nightly (7918c7eb5 2025-04-27)
release: 1.88.0-nightly
commit-hash: 7918c7eb59614c39f1c4e27e99d557720976bdd7
commit-date: 2025-04-27
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:OpenSSL/3.4.1)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: NixOS 25.5.0 [64-bit]
cargo 1.86.0 (adf9b6ad1 2025-02-28)
release: 1.86.0
commit-hash: adf9b6ad14cfa10ff680d5806741a144f7163698
commit-date: 2025-02-28
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.0-DEV (sys:0.4.79+curl-8.12.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: NixOS 25.5.0 [64-bit]

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions