declare that "///" is still a doc comment, just not "////+" (fixes #5838)

This commit is contained in:
Benjamin Herr 2013-05-22 15:53:26 +02:00
parent 8a4bffc7ee
commit 5a42481366

View File

@ -247,7 +247,8 @@ fn consume_whitespace_and_comments(rdr: @mut StringReader)
} }
pub fn is_line_non_doc_comment(s: &str) -> bool { 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 // 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); str::push_char(&mut acc, rdr.curr);
bump(rdr); bump(rdr);
} }
// but comments with only "/"s are not // but comments with only more "/"s are not
if !is_line_non_doc_comment(acc) { if !is_line_non_doc_comment(acc) {
return Some(TokenAndSpan{ return Some(TokenAndSpan{
tok: token::DOC_COMMENT(rdr.interner.intern(acc)), tok: token::DOC_COMMENT(rdr.interner.intern(acc)),
@ -891,4 +892,10 @@ fn mk_ident (env: Env, id: &str, is_mod_name: bool) -> token::Token {
let id = env.interner.intern("abc"); let id = env.interner.intern("abc");
assert_eq!(tok, token::LIFETIME(id)); 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("////"));
}
} }