Generating comments (not documentation) with `quote` and `prettyplease`?

⚓ Rust    📅 2026-01-02    👤 surdeus    👁️ 1      

surdeus

/*
[package]
name = "token_stream_test"
version = "0.1.0"
edition = "2024"

[dependencies]
prettyplease = "0.2.37"
quote = "1.0.42"
syn = "2.0.112"
*/

fn main() {
    let tokens = quote::quote! {
        /// Documentation.
        struct Test { field: u32 /* comment */ }
    };
    let syntax_tree = syn::parse2(tokens).unwrap();
    let formatted = prettyplease::unparse(&syntax_tree);
    println!("{}", formatted);
}

This code prints the quoted code without the comment (but with the documentation).

Are there any tricks that I can apply here to make it preserve the comment as well?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed