1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//!
//!
use super::SpanExt;
use proc_macro2::{Literal, Spacing, Span, TokenNode, TokenTree};
use syn::*;
use syn::punctuated::Pair;

/// Creates a comment from `s`.
pub fn comment<S>(s: S) -> Attribute
where
    S: AsRef<str>,
{
    let span = Span::call_site();

    Attribute {
        style: AttrStyle::Outer,
        bracket_token: span.as_token(),
        pound_token: span.as_token(),
        is_sugared_doc: true,
        path: Path {
            leading_colon: None,
            segments: vec![
                Pair::End(PathSegment {
                    ident: Ident::new("doc", span),
                    arguments: Default::default(),
                }),
            ].into_iter()
                .collect(),
        },
        tts: vec![
            TokenTree {
                span,
                kind: TokenNode::Op('=', Spacing::Alone),
            },
            TokenTree {
                span,
                kind: TokenNode::Literal(Literal::string(s.as_ref())),
            },
        ].into_iter()
            .collect(),
    }
}