rustfmt: Confusing error message on syntax error in code in doc comments
When enabling format_code_in_doc_comments, the formatter reports that there is a syntax issue in a code block. However the syntax issue source location seems to be confusing/ambigious:
Running rustfmt on the following code snippet produces a confusing error message:
/// Some doc comment with code snippet:
///```
/// '\u{1F}
/// ```
pub struct Code {}
fn main() {}
The error that is produced:
error[E0762]: unterminated character literal
--> <stdin>:2:5
|
2 | '\u{1F}
| ^^^^^^^
This is not explicitly a bug, but nonetheless is confusing as it does not indicate the true origin of the issue.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (13 by maintainers)
Commits related to this issue
- Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily meant to allow rustfmt to igno... — committed to matthiaskrgr/rust by matthiaskrgr 3 years ago
- Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily meant to allow rustfmt to igno... — committed to matthiaskrgr/rust by matthiaskrgr 3 years ago
- Unrolled build for #122737 Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily mea... — committed to rust-lang-ci/rust by rust-timer 3 years ago
- Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily meant to allow rustfmt to igno... — committed to RenjiSann/rust by matthiaskrgr 3 years ago
- Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco conditionally ignore fatal diagnostic in the SilentEmitter This change is primarily meant to allow rustfmt to igno... — committed to ytmimi/rustfmt by matthiaskrgr 3 years ago
I don’t think it’s necessary. It’s mostly this specific case since I wanted to add a test to ensure nothing was being output to stdout and stderr. Typically a source and target file are all that’s required
@feds01 In this case yes. The previous behavior was for rustfmt to ignore the diagnostic message produced by the rustc parser, however there were some internal changes made in
rust-lang/rustthat changed that behavior. https://github.com/rust-lang/rust/pull/122737 restored rustfmts previous behavior of ignoring parser errors when formatting code in doc comments.