Skip to content

Commit a8ce669

Browse files
committed
Workaround to have doc comments desugared only in macros
1 parent 6f30a4e commit a8ce669

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
164164
_ => cx.span_fatal(sp, "malformed macro lhs")
165165
};
166166
// `None` is because we're not interpolating
167-
let arg_rdr = new_tt_reader(&cx.parse_sess().span_diagnostic,
168-
None,
169-
arg.iter()
170-
.map(|x| (*x).clone())
171-
.collect());
167+
let mut arg_rdr = new_tt_reader(&cx.parse_sess().span_diagnostic,
168+
None,
169+
arg.iter()
170+
.map(|x| (*x).clone())
171+
.collect());
172+
arg_rdr.desugar_doc_comments = true;
172173
match parse(cx.parse_sess(), cx.cfg(), arg_rdr, lhs_tt) {
173174
Success(named_matches) => {
174175
let rhs = match *rhses[i] {

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct TtReader<'a> {
4343
/* cached: */
4444
pub cur_tok: Token,
4545
pub cur_span: Span,
46+
/// Transform doc comments. Only useful in macro invocations
47+
pub desugar_doc_comments: bool,
4648
}
4749

4850
/// This can do Macro-By-Example transcription. On the other hand, if
@@ -66,6 +68,7 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler,
6668
},
6769
repeat_idx: Vec::new(),
6870
repeat_len: Vec::new(),
71+
desugar_doc_comments: false,
6972
/* dummy values, never read: */
7073
cur_tok: token::Eof,
7174
cur_span: DUMMY_SP,
@@ -279,8 +282,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
279282
}
280283
}
281284
// TtDelimited or any token that can be unzipped
282-
seq @ TtDelimited(..) | seq @ TtToken(_, DocComment(..))
283-
| seq @ TtToken(_, MatchNt(..)) => {
285+
seq @ TtDelimited(..) | seq @ TtToken(_, MatchNt(..)) => {
284286
// do not advance the idx yet
285287
r.stack.push(TtFrame {
286288
forest: seq.expand_into_tts(),
@@ -290,6 +292,14 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
290292
});
291293
// if this could be 0-length, we'd need to potentially recur here
292294
}
295+
TtToken(sp, DocComment(name)) if r.desugar_doc_comments => {
296+
r.stack.push(TtFrame {
297+
forest: TtToken(sp, DocComment(name)).expand_into_tts(),
298+
idx: 0,
299+
dotdotdoted: false,
300+
sep: None
301+
});
302+
}
293303
TtToken(sp, tok) => {
294304
r.cur_span = sp;
295305
r.cur_tok = tok;

0 commit comments

Comments
 (0)