Skip to content

Commit a57b1fb

Browse files
committed
Tweak doc comment expansion
* Expand `!` tokens for inner doc comments * Trim leading doc comment decoration in the string literal Both of these should help bring the expansion inline with what `macro_rules!` already does. Closes #49655 Closes #49656
1 parent 553c04d commit a57b1fb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libproc_macro/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use syntax::errors::DiagnosticBuilder;
5959
use syntax::parse::{self, token};
6060
use syntax::symbol::Symbol;
6161
use syntax::tokenstream;
62+
use syntax::parse::lexer::comments;
6263
use syntax_pos::{FileMap, Pos, SyntaxContext, FileName};
6364
use syntax_pos::hygiene::Mark;
6465

@@ -1056,12 +1057,17 @@ impl TokenTree {
10561057
}
10571058
Literal(..) => tt!(self::Literal { token, span: Span(span) }),
10581059
DocComment(c) => {
1060+
let style = comments::doc_comment_style(&c.as_str());
1061+
let stripped = comments::strip_doc_comment_decoration(&c.as_str());
10591062
let stream = vec![
10601063
tt!(Term::new("doc", Span(span))),
10611064
tt!(Op::new('=', Spacing::Alone)),
1062-
tt!(self::Literal::string(&c.as_str())),
1065+
tt!(self::Literal::string(&stripped)),
10631066
].into_iter().collect();
10641067
stack.push(tt!(Group::new(Delimiter::Bracket, stream)));
1068+
if style == ast::AttrStyle::Inner {
1069+
stack.push(tt!(Op::new('!', Spacing::Alone)));
1070+
}
10651071
tt!(Op::new('#', Spacing::Alone))
10661072
}
10671073

0 commit comments

Comments
 (0)