My use case: generate a struct with given field names, attaching docs with #[doc = expr)]
.
Here's the code snippet:
macro_rules! impl_dir_cache {
($name:ident $(;CACHE: $($field_cache:ident),*)? $(;OUTPUT: $($field_output:ident),*)?) => {
#[derive(Debug, Clone, Default)]
/// Marker struct as extra info of [Dir].
pub(crate) struct $name {
/// Canonicalized base dir path
canonicalized: OnceLock<Arc<str>>,
// === CACHE ===
$(
/// Cache dir root path: `{canonicalized_root}/.cache`
cache_dir: OnceLock<Arc<str>>,
$(
#[doc = concat!("Cache dir path for `", stringify!($field_cache), "`")]
$field_cache: OnceLock<Arc<str>>,
)*
)?
// ...
Then I met with the issue: even if I enable the corresponding settings in VSCode, comments that generated by #[doc = expr)]
will not appear:
though in doc html generated by cargo doc
, the comment exists:
What's more, if not a expr but literal, everything works well:
We can see the result of macro concat!(***)
does not appear but simple text TEST TEST TEST
appears.
I wonder if it's a bug or because of any possible mistakes I have made.
Here's one MWE, just copy to your VSCode and move your mouse over the two struct, and compare their docs the hover shows you:
macro_rules! test {
($name_1: ident, $name_2:ident) => {
#[doc = concat!("Test for [", stringify!($name), "]")]
struct $name_1;
#[doc = "Test for ["]
#[doc = stringify!($name)]
#[doc = "]"]
struct $name_2;
};
}
test!(TestStructA, TestStructB);