-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustdoc: provide more context for parse errors in code blocks #67857
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-parser
Area: The parsing of Rust source code to an AST
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
Comments
Triage: the errors are still the same on 1.50 nightly. |
I tried this change: diff --git a/src/librustdoc/passes/check_code_block_syntax.rs b/src/librustdoc/passes/check_code_block_syntax.rs
index 74d396efd57..11c59d6326a 100644
--- a/src/librustdoc/passes/check_code_block_syntax.rs
+++ b/src/librustdoc/passes/check_code_block_syntax.rs
@@ -111,11 +111,14 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
diag.help(&format!("{}: ```text", explanation));
}
- // FIXME(#67563): Provide more context for these errors by displaying the spans inline.
- for message in buffer.messages.iter() {
- diag.note(&message);
+ for new_diag in &buffer.messages {
+ if let Some(sp) = new_diag.span.primary_span() {
+ diag.span_warn(dbg!(sp), &new_diag.message());
+ } else {
+ diag.warn(&new_diag.message());
+ }
+ diag.suggestions.extend(new_diag.suggestions.clone());
}
-
diag.emit();
};
@@ -147,7 +150,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
#[derive(Default)]
struct Buffer {
- messages: Vec<String>,
+ messages: Vec<Diagnostic>,
has_errors: bool,
}
@@ -158,7 +161,9 @@ struct BufferEmitter {
impl Emitter for BufferEmitter {
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
let mut buffer = self.buffer.borrow_mut();
- buffer.messages.push(format!("error from rustc: {}", diag.message[0].0));
+ let mut formatted_diag = diag.clone();
+ formatted_diag.message[0].0 = format!("error from rustc: {}", diag.message[0].0);
+ buffer.messages.push(formatted_diag);
if diag.is_error() {
buffer.has_errors = true;
} Unfortunately it doesn't work very well; I think the spans don't match up between sessions.
|
This also doesn't work well: for new_diag in &buffer.messages {
diag.warn(&new_diag.message());
for (span, label) in new_diag.span.labels {
diag.span_note(span, label);
}
diag.suggestions.extend(new_diag.suggestions.clone());
}
|
That's just because you need to offset the span by the position of the start of the codeblock (the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-parser
Area: The parsing of Rust source code to an AST
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
Split from #67563.
Currently, the bad_codeblock_syntax_pass in rustdoc provides error messages like the following:
Ideally, we could display the error spans inline (but downgrade them to warnings).
The text was updated successfully, but these errors were encountered: