Skip to content

Commit 22aa163

Browse files
committed
Rollup merge of rust-lang#26777 - barosl:macro-doc-escapes, r=pnkfelix
Escape sequences in documentation comments must not be parsed as a normal string when expanding a macro, otherwise some innocent but invalid-escape-sequence-looking comments will trigger an ICE. Although this commit replaces normal string literals with raw string literals in macro expansion, this shouldn't be much a problem considering documentation comments are converted into attributes before being passed to a macro anyways. Fixes rust-lang#25929. Fixes rust-lang#25943.
2 parents e05ac39 + 5c60d1d commit 22aa163

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ impl TokenTree {
11041104
tts: vec![TtToken(sp, token::Ident(token::str_to_ident("doc"),
11051105
token::Plain)),
11061106
TtToken(sp, token::Eq),
1107-
TtToken(sp, token::Literal(token::Str_(name), None))],
1107+
TtToken(sp, token::Literal(token::StrRaw(name, 0), None))],
11081108
close_span: sp,
11091109
}))
11101110
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// When expanding a macro, documentation attributes (including documentation comments) must be
12+
// passed "as is" without being parsed. Otherwise, some text will be incorrectly interpreted as
13+
// escape sequences, leading to an ICE.
14+
//
15+
// Related issues: #25929, #25943
16+
17+
macro_rules! homura {
18+
(#[$x:meta]) => ()
19+
}
20+
21+
homura! {
22+
/// \madoka \x41
23+
}
24+
25+
fn main() { }

0 commit comments

Comments
 (0)