提交 4120f756 编写于 作者: J Joshua Nelson

Add back missing help for ignore blocks

This also gives a better error message when a span is missing.
上级 b574c67b
......@@ -328,7 +328,7 @@ warning: Rust code block is empty
--> src/lib.rs:8:5
|
8 | /// ```rust
| ^^^^^^^
| ^^^^^^^
```
## bare_urls
......
......@@ -61,7 +61,7 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
};
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_id);
let suggest_using_text = code_block.syntax.is_none() && code_block.is_fenced;
let empty_block = code_block.syntax.is_none() && code_block.is_fenced;
let is_ignore = code_block.is_ignore;
// The span and whether it is precise or not.
......@@ -78,40 +78,38 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
// lambda that will use the lint to start a new diagnostic and add
// a suggestion to it when needed.
let diag_builder = |lint: LintDiagnosticBuilder<'_>| {
let mut diag = if precise_span {
let msg = if buffer.has_errors {
"could not parse code block as Rust code"
} else {
"Rust code block is empty"
};
let mut diag = lint.build(msg);
if suggest_using_text {
let extended_msg = if is_ignore {
"`ignore` code blocks require valid Rust code for syntax highlighting. \
Mark blocks that do not contain Rust code as text"
} else {
"mark blocks that do not contain Rust code as text"
};
let explanation = if is_ignore {
"`ignore` code blocks require valid Rust code for syntax highlighting; \
mark blocks that do not contain Rust code as text"
} else {
"mark blocks that do not contain Rust code as text"
};
let msg = if buffer.has_errors {
"could not parse code block as Rust code"
} else {
"Rust code block is empty"
};
let mut diag = lint.build(msg);
if precise_span {
if is_ignore {
// giving an accurate suggestion is hard because `ignore` might not have come first in the list.
// just give a `help` instead.
diag.span_help(
sp.from_inner(InnerSpan::new(0, 3)),
&format!("{}: ```text", explanation),
);
} else if empty_block {
diag.span_suggestion(
sp.from_inner(InnerSpan::new(0, 3)),
extended_msg,
explanation,
String::from("```text"),
Applicability::MachineApplicable,
);
}
diag
} else {
let mut diag = lint.build("doc comment contains an invalid Rust code block");
if suggest_using_text {
diag.help("mark blocks that do not contain Rust code as text: ```text");
}
diag
};
} else if empty_block || is_ignore {
diag.help(&format!("{}: ```text", explanation));
}
// FIXME(#67563): Provide more context for these errors by displaying the spans inline.
for message in buffer.messages.iter() {
......
......@@ -3,5 +3,8 @@
/// ```ignore (to-prevent-tidy-error)
/// let heart = '❤️';
/// ```
//~^^^ WARN
//~^^^ WARNING could not parse code block
//~| NOTE on by default
//~| NOTE character literal may only contain one codepoint
//~| HELP `ignore` code blocks require valid Rust code
pub struct X;
......@@ -7,7 +7,12 @@ LL | | /// let heart = '❤️';
LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default
= note: `#[warn(rustdoc::invalid_rust_codeblock)]` on by default
help: `ignore` code blocks require valid Rust code for syntax highlighting; mark blocks that do not contain Rust code as text: ```text
--> $DIR/ignore-block-help.rs:3:5
|
LL | /// ```ignore (to-prevent-tidy-error)
| ^^^
= note: error from rustc: character literal may only contain one codepoint
warning: 1 warning emitted
......
......@@ -71,7 +71,7 @@ pub fn blargh() {}
/// \_
#[doc = "```"]
pub fn crazy_attrs() {}
//~^^^^ WARNING doc comment contains an invalid Rust code block
//~^^^^ WARNING could not parse code block
/// ```rust
/// ```
......
......@@ -7,7 +7,7 @@ LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->si
LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default
= note: `#[warn(rustdoc::invalid_rust_codeblock)]` on by default
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
......@@ -91,7 +91,7 @@ LL | | /// ```
|
= note: error from rustc: unknown start of token: \
warning: doc comment contains an invalid Rust code block
warning: could not parse code block as Rust code
--> $DIR/invalid-syntax.rs:70:1
|
LL | / #[doc = "```"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册