Stream: t-compiler/rust-analyzer

Topic: Diagnostics from inside proc macros are broken


Jonas Schievink [he/him] (Dec 02 2020 at 19:24, on Zulip):

screenshot-2020-12-02-202249.png

It looks like diagnostics are attached to the outer file instead of the macro file? This is odd, it does not seem to happen with macro_rules! macros.

Jonas Schievink [he/him] (Dec 03 2020 at 13:39, on Zulip):

This looks correct to me? :thinking:

self.source_map.diagnostics.push(BodyDiagnostic::InactiveCode(InactiveCode {
    file: self.expander.current_file_id,
    node: SyntaxNodePtr::new(owner.syntax()),
    cfg,
    opts: self.expander.cfg_options().clone(),
}));

(from https://github.com/rust-analyzer/rust-analyzer/blob/5a1306a43652d914035b2cf0b703f4bfd3451a33/crates/hir_def/src/body/lower.rs#L923-L928)

Jonas Schievink [he/him] (Dec 03 2020 at 13:43, on Zulip):

Ah, it's a general issue with all diagnostics

screenshot-2020-12-03-144337.png

Jonas Schievink [he/him] (Dec 03 2020 at 17:44, on Zulip):

Found the problem, and opened a fix here: https://github.com/rust-analyzer/rust-analyzer/pull/6712

Jonas Schievink [he/him] (Dec 03 2020 at 17:45, on Zulip):

Haven't found an easy way to add a test though

Jonas Schievink [he/him] (Dec 03 2020 at 17:45, on Zulip):

Maybe we should start writing a couple of "quick" proc macro tests that use only the proc_macro_test crate

Last update: Jul 26 2021 at 14:15UTC