Skip to content

Commit 5a42481

Browse files
committed
declare that "///" is still a doc comment, just not "////+" (fixes #5838)
1 parent 8a4bffc commit 5a42481

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libsyntax/parse/lexer.rs

Lines changed: 9 additions & 2 deletions
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)