Add failing tests (fmt panic) on weird doc comments.
Isolated doc comments causes the compiler to panic with: ``` 'no consecutive empty lines' ``` This is reproducible when doc comments are wrapped in sandwich between comments and newlines.
This commit is contained in:
@@ -322,6 +322,25 @@ fn utf8_hex_literal_warning() {
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weird_comments() {
|
||||
let source_code = r#"
|
||||
// A
|
||||
|
||||
/// B
|
||||
|
||||
// C
|
||||
fn foo () {
|
||||
todo
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(matches!(
|
||||
check(parse(source_code)),
|
||||
Err((_, Error::UnexpectedDocComment { .. }))
|
||||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn discarded_let_bindings() {
|
||||
let source_code = r#"
|
||||
|
||||
@@ -629,3 +629,29 @@ fn test_preserve_pipe() {
|
||||
|
||||
assert_fmt(src, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn weird_comments() {
|
||||
let src = indoc! { r#"
|
||||
// A
|
||||
|
||||
/// B
|
||||
|
||||
/// C
|
||||
fn bar () {
|
||||
todo
|
||||
}
|
||||
"#};
|
||||
|
||||
let expected = indoc! { r#"
|
||||
// A
|
||||
|
||||
/// B
|
||||
/// C
|
||||
fn bar () {
|
||||
todo
|
||||
}
|
||||
"#};
|
||||
|
||||
assert_fmt(src, expected);
|
||||
}
|
||||
|
||||
@@ -892,6 +892,13 @@ The best thing to do from here is to remove it."#))]
|
||||
#[label("{} arguments", if *count < 2 { "not enough" } else { "too many" })]
|
||||
location: Span,
|
||||
},
|
||||
|
||||
#[error("I ran into a lonely doc comment not attached to any function definition.")]
|
||||
#[diagnostic(code("unexpected::doc_comment"))]
|
||||
UnexpectedDocComment {
|
||||
#[label("unexpected doc comment")]
|
||||
location: Span,
|
||||
},
|
||||
}
|
||||
|
||||
impl Error {
|
||||
|
||||
Reference in New Issue
Block a user