diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 74413a7f905d4..8bf01d2cc1aac 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -931,7 +931,10 @@ crate fn rust_code_blocks(md: &str) -> Vec {
is_fenced = true;
previous_offset + fence_idx
}
- None => offset,
+ None => {
+ is_fenced = false;
+ offset
+ }
};
}
}
diff --git a/src/test/rustdoc-ui/invalid-syntax.rs b/src/test/rustdoc-ui/invalid-syntax.rs
index 3ef66e273d0d0..97a0f4aaec1eb 100644
--- a/src/test/rustdoc-ui/invalid-syntax.rs
+++ b/src/test/rustdoc-ui/invalid-syntax.rs
@@ -74,3 +74,11 @@ pub fn empty_rust() {}
///
/// ```
pub fn empty_rust_with_whitespace() {}
+
+/// ```
+/// let x = 1;
+/// ```
+///
+/// \____/
+///
+pub fn indent_after_fenced() {}
diff --git a/src/test/rustdoc-ui/invalid-syntax.stderr b/src/test/rustdoc-ui/invalid-syntax.stderr
index 36209e2927771..6f50edae65034 100644
--- a/src/test/rustdoc-ui/invalid-syntax.stderr
+++ b/src/test/rustdoc-ui/invalid-syntax.stderr
@@ -201,6 +201,24 @@ help: mark blocks that do not contain Rust code as text
LL | /// ```text
| ^^^^^^^
+error: unknown start of token: \
+ --> :1:1
+ |
+1 | \____/
+ | ^
+
+warning: could not parse code block as Rust code
+ --> $DIR/invalid-syntax.rs:82:9
+ |
+LL | /// \____/
+ | ^^^^^^
+
+error: unknown start of token: \
+ --> :1:1
+ |
+1 | \____/
+ | ^
+
error: unknown start of token: \
--> :1:1
|