Skip to content

Commit b5ab101

Browse files
committed
auto merge of #6680 : ben0x539/rust/slashslashslash, r=graydon
There's currently a function in the lexer that rejects a line comment that is all slashes from being a doc comment. I think the intention was that you could draw boxes, ///////////// // like so // ///////////// Since a line doc comment split up over multiple paragraphs will have a "blank" line that is just /// between the paragraphs, that would get mistaken for a box segment, lexed as a regular comment, and go missing from the sequence of doc comment attributes before they were reassembled by rustdoc into markdown input. I figure the best plan here is to just declare that a comment that is exactly `///` is a doc comment after all, and to only omit comments with four slashes or more, which is what this commit implements. Can't really draw boxes that narrow, anyway.
2 parents 2f69bb9 + 5a42481 commit b5ab101

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libsyntax/parse/lexer.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ fn consume_whitespace_and_comments(rdr: @mut StringReader)
247247
}
248248

249249
pub fn is_line_non_doc_comment(s: &str) -> bool {
250-
s.trim_right().all(|ch| ch == '/')
250+
let s = s.trim_right();
251+
s.len() > 3 && s.all(|ch| ch == '/')
251252
}
252253

253254
// PRECONDITION: rdr.curr is not whitespace
@@ -268,7 +269,7 @@ fn consume_any_line_comment(rdr: @mut StringReader)
268269
str::push_char(&mut acc, rdr.curr);
269270
bump(rdr);
270271
}
271-
// but comments with only "/"s are not
272+
// but comments with only more "/"s are not
272273
if !is_line_non_doc_comment(acc) {
273274
return Some(TokenAndSpan{
274275
tok: token::DOC_COMMENT(rdr.interner.intern(acc)),
@@ -891,4 +892,10 @@ mod test {
891892
let id = env.interner.intern("abc");
892893
assert_eq!(tok, token::LIFETIME(id));
893894
}
895+
896+
#[test] fn line_doc_comments() {
897+
assert!(!is_line_non_doc_comment("///"));
898+
assert!(!is_line_non_doc_comment("/// blah"));
899+
assert!(is_line_non_doc_comment("////"));
900+
}
894901
}

0 commit comments

Comments
 (0)