Skip to content

Commit

Permalink
Tweak doc comment expansion
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexcrichton committed Apr 4, 2018
1 parent 553c04d commit a57b1fb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use syntax::errors::DiagnosticBuilder;
use syntax::parse::{self, token};
use syntax::symbol::Symbol;
use syntax::tokenstream;
use syntax::parse::lexer::comments;
use syntax_pos::{FileMap, Pos, SyntaxContext, FileName};
use syntax_pos::hygiene::Mark;

Expand Down Expand Up @@ -1056,12 +1057,17 @@ impl TokenTree {
}
Literal(..) => tt!(self::Literal { token, span: Span(span) }),
DocComment(c) => {
let style = comments::doc_comment_style(&c.as_str());
let stripped = comments::strip_doc_comment_decoration(&c.as_str());
let stream = vec![
tt!(Term::new("doc", Span(span))),
tt!(Op::new('=', Spacing::Alone)),
tt!(self::Literal::string(&c.as_str())),
tt!(self::Literal::string(&stripped)),
].into_iter().collect();
stack.push(tt!(Group::new(Delimiter::Bracket, stream)));
if style == ast::AttrStyle::Inner {
stack.push(tt!(Op::new('!', Spacing::Alone)));
}
tt!(Op::new('#', Spacing::Alone))
}

Expand Down

0 comments on commit a57b1fb

Please sign in to comment.