4134: Special case for empty comments in doc comment kind  r=matklad a=edwin0cheng

Part of #4103

Fix `ui/empty/empty-comment.rs macros`

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
bors[bot] 2020-04-25 10:53:40 +00:00 committed by GitHub
commit 7bc7173230
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View file

@ -1849,3 +1849,16 @@ fn test_expand_bad_literal() {
)
.assert_expand_err(r#"foo!(&k");"#, &ExpandError::BindingError("".into()));
}
#[test]
fn test_empty_comments() {
parse_macro(
r#"
macro_rules! one_arg_macro { ($fmt:expr) => (); }
"#,
)
.assert_expand_err(
r#"one_arg_macro!(/**/)"#,
&ExpandError::BindingError("expected Expr".into()),
);
}

View file

@ -58,6 +58,9 @@ const COMMENT_PREFIX_TO_KIND: &[(&str, CommentKind)] = {
};
fn kind_by_prefix(text: &str) -> CommentKind {
if text == "/**/" {
return CommentKind { shape: CommentShape::Block, doc: None };
}
for (prefix, kind) in COMMENT_PREFIX_TO_KIND.iter() {
if text.starts_with(prefix) {
return *kind;