diff options
| author | bors <bors@rust-lang.org> | 2013-05-24 05:34:45 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-24 05:34:45 -0700 |
| commit | b5ab1012f1f5786f550e511ba1302a22c85fcd71 (patch) | |
| tree | c61e703ad8e2f14fa1119f73ad4d662bcf6c8668 | |
| parent | 2f69bb9ba9d622ccab77840c08f4562a10b44c29 (diff) | |
| parent | 5a424813667a27a0def860d96a5e79801718592b (diff) | |
| download | rust-b5ab1012f1f5786f550e511ba1302a22c85fcd71.tar.gz rust-b5ab1012f1f5786f550e511ba1302a22c85fcd71.zip | |
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.
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 77637712c7f..d49a3d7fe42 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -247,7 +247,8 @@ fn consume_whitespace_and_comments(rdr: @mut StringReader) } pub fn is_line_non_doc_comment(s: &str) -> bool { - s.trim_right().all(|ch| ch == '/') + let s = s.trim_right(); + s.len() > 3 && s.all(|ch| ch == '/') } // PRECONDITION: rdr.curr is not whitespace @@ -268,7 +269,7 @@ fn consume_any_line_comment(rdr: @mut StringReader) str::push_char(&mut acc, rdr.curr); bump(rdr); } - // but comments with only "/"s are not + // but comments with only more "/"s are not if !is_line_non_doc_comment(acc) { return Some(TokenAndSpan{ tok: token::DOC_COMMENT(rdr.interner.intern(acc)), @@ -891,4 +892,10 @@ mod test { let id = env.interner.intern("abc"); assert_eq!(tok, token::LIFETIME(id)); } + + #[test] fn line_doc_comments() { + assert!(!is_line_non_doc_comment("///")); + assert!(!is_line_non_doc_comment("/// blah")); + assert!(is_line_non_doc_comment("////")); + } } |
