Skip to content

rust-analyzer fails to display comment generated during nested macro expansion #13190

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

Closed
0rphon opened this issue Sep 4, 2022 · 3 comments
Closed

Comments

@0rphon
Copy link

0rphon commented Sep 4, 2022

possibly related to #13075

the following has a macro that generates documentation for A and for B. Rust-Anaylzer displays the documentation just fine for B, but shows no documentation for A.

macro_rules! tester {
    ($x:expr, $n:ident) => {
        tester! {@inner concat!("This is ", $x), $n}
    };
    (@inner $x:expr, $n:ident) => {
        #[doc = $x]
        const $n: u8 = 1u8;
    };
}

tester!("A", A);
tester!(@inner "This is B", B);

fn main() {
    A;
    B;
}

image
image

just to confirm that the docs exist, here's the output of cargo expand (cargo doc also confirms a doc string exists for A)

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
///This is A
const A: u8 = 1u8;
///This is B
const B: u8 = 1u8;
fn main() {
    A;
    B;
}

but using rust-analyzer: Expand Macro Recursively shows that the 'A' doc has parentheses around it, which would be considered a syntax error

// Recursive expansion of tester! macro
// =====================================

#[doc = ("This is A")]
const A: u8 = 1u8;
// Recursive expansion of tester! macro
// =====================================

#[doc = "This is B"]
const B: u8 = 1u8;

rust-analyzer version: both the release version 0.3.1186-standalone (e8e598f64 2022-08-28) and pre-release version 0.4.1192-standalone (8ddb8b7e8 2022-09-03)

rustc version: both rustc 1.63.0 (4b91a6ea7 2022-08-08) and rustc 1.65.0-nightly (84f0c3f79 2022-09-03)

relevant settings: None

@0rphon
Copy link
Author

0rphon commented Sep 4, 2022

i messed around with this some more and i found a similar example that may actually be a separate issue. rust-analyzer manages to generate the correct syntax for the doc string but still fails to show documentation for it

code:

macro_rules! tester {
    ($n:ident) => {
        #[doc = concat!("This is ", stringify!($n))]
        const $n: u8 = 1u8;
    };
}

tester!(A);

fn main() {
    A;
}

cargo expand:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
///This is A
const A: u8 = 1u8;
fn main() {
    A;
}

rust-analyzer expansion:

// Recursive expansion of tester! macro
// =====================================

#[doc = "This is A"]
const A: u8 = 1u8;

on hover:
image

@jonas-schievink
Copy link
Contributor

We don't support macros in attribute values at the moment

@Veykril
Copy link
Member

Veykril commented Sep 7, 2022

Duplicate of #8092

@Veykril Veykril marked this as a duplicate of #8092 Sep 7, 2022
@Veykril Veykril closed this as completed Sep 7, 2022
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

No branches or pull requests

3 participants