Skip to content

Commit

Permalink
Auto merge of #97442 - hafeoz:master, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Fix multiline attributes processing in doctest

Fixes #97440.

It seems like the call to `check_if_attr_is_complete` is not provided with the correct argument: the pending attribute should be passed, while the current line is actually being passed. This causes any attribute with more than 2 lines to fail and produces ICE when running through doctest.
  • Loading branch information
bors committed May 27, 2022
2 parents f558990 + c3beb03 commit 4614711
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,9 @@ fn partition_source(s: &str, edition: Edition) -> (String, String, String) {
// If not, then we append the new line into the pending attribute to check
// if this time it's complete...
mod_attr_pending.push_str(line);
if !trimline.is_empty() && check_if_attr_is_complete(line, edition) {
if !trimline.is_empty()
&& check_if_attr_is_complete(&mod_attr_pending, edition)
{
// If it's complete, then we can clear the pending content.
mod_attr_pending.clear();
}
Expand Down
11 changes: 11 additions & 0 deletions src/test/rustdoc-ui/doc-comment-multi-line-attr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Regression test for #97440: Multiline inner attribute triggers ICE during doctest
// compile-flags:--test
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
// check-pass

//! ```rust
//! #![deny(
//! unused_parens,
//! )]
//! ```
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/doc-comment-multi-line-attr.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

running 1 test
test $DIR/doc-comment-multi-line-attr.rs - (line 7) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

0 comments on commit 4614711

Please sign in to comment.