diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index 6261e843d23..f1d00b81eed 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1213,6 +1213,7 @@ crate struct RustCodeBlock {
crate code: Range,
crate is_fenced: bool,
crate syntax: Option,
+ crate is_ignore: bool,
}
/// Returns a range of bytes for each code block in the markdown that is tagged as `rust` or
@@ -1228,7 +1229,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec {
let syntax = syntax.as_ref();
let lang_string = if syntax.is_empty() {
@@ -1249,6 +1250,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec) -> Vec) -> Vec {
// The ending of the offset goes too far sometime so we reduce it by one in
@@ -1278,9 +1281,10 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_, '_>) -> Vec) -> Vec SyntaxChecker<'a, 'tcx> {
let mut diag = if let Some(sp) =
super::source_span_for_markdown_range(self.cx, &dox, &code_block.range, &item.attrs)
{
- let warning_message = if buffer.has_errors {
- "could not parse code block as Rust code"
+ let (warning_message, suggest_using_text) = if buffer.has_errors {
+ ("could not parse code block as Rust code", true)
} else {
- "Rust code block is empty"
+ ("Rust code block is empty", false)
};
let mut diag = self.cx.sess().struct_span_warn(sp, warning_message);
@@ -67,6 +67,15 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
String::from("```text"),
Applicability::MachineApplicable,
);
+ } else if suggest_using_text && code_block.is_ignore {
+ let sp = sp.from_inner(InnerSpan::new(0, 3));
+ diag.span_suggestion(
+ sp,
+ "`ignore` code blocks require valid Rust code for syntax highlighting. \
+ Mark blocks that do not contain Rust code as text",
+ String::from("```text,"),
+ Applicability::MachineApplicable,
+ );
}
diag