You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rust-analyzer appears to be passing Spans' line numbers (from the proc_macro_span unstable API) as 0-indexed values to my proc-macro. According to the documentation, this line is supposed to always be 1-indexed. The rustc compiler is using 1-indexed lines. The result of this is an LSP error of proc-macro panicked: attempt to subtract with overflow. When compiled and run using rustc, however, the code runs perfectly fine.
You should note that we don't really support the line/column API (and can't, for incrementality reasons). Currently it just returns 0. Returning 1 is trivial, but it won't really mean we support this API.
That's fair. I don't think returning 1 would help my use case, but would probably still be more consistent with the Span.line() documentation. Since the syntax of SimpleML is whitespace-sensitive, using the line/column APIs was the best way I could find to achieve whitespace-sensitive syntax in a rust macro.
Probably the most helpful thing that could be done here would be to monitor the line/column APIs and, if they're called, suppress all diagnostics from the macro. That doesn't seem worth the development effort though, so I'd also be okay with closing the issue. I can let my users know in documentation that rust-analyzer doesn't support this macro particularly well and they will see phantom errors.
We can return line/column numbers relative to the macro call's beginning (instead of the file's beginning); will that help you? (Anyway that's not what we're doing currently).
Relying on whitespace information is brittle anyway and macros weren't meant for that. If you'll make the whole argument a string it'll be easier.
Rust-analyzer appears to be passing Spans' line numbers (from the proc_macro_span unstable API) as 0-indexed values to my proc-macro. According to the documentation, this line is supposed to always be 1-indexed. The rustc compiler is using 1-indexed lines. The result of this is an LSP error of
proc-macro panicked: attempt to subtract with overflow
. When compiled and run using rustc, however, the code runs perfectly fine.rust-analyzer version: 0.3.2273-standalone (248bd51 2025-01-18)
rustc version: 1.84.0-nightly (9b18a122f 2024-10-26)
editor or extension: VSCode. For VSCode users, specify your extension version: 0.3.2273
relevant settings: N/A
repository link (if public, optional): rust-analyzer-bug-report
code snippet to reproduce:
The text was updated successfully, but these errors were encountered: