Describe the bug
rustfmt reports error[internal]: left behind trailing whitespace on this code. Also, in a previous iteration of the code (with the if guards in the body of the match arms instead of being guards), rustfmt failed to format the code without reporting any errors or warnings.
To Reproduce
- Run rustfmt on this playground code.
- Observe rustfmt internal errors.
Here's the code (same as in the playground):
impl Foo {
fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool {
if let Some(list) = attr.meta().and_then(|mi| mi.meta_item_list()) {
for meta in list {
if let Some(i_meta) = meta.meta_item() {
match i_meta.path {
sym::alias
if !self.check_attr_crate_level(meta, hir_id, "alias")
|| !self.check_doc_alias(meta, hir_id, target)=>
{
return false;
}
sym::keyword
if !self.check_attr_crate_level(meta, hir_id, "keyword")
|| !self.check_doc_keyword(meta, hir_id)
=>{
return false;
}
sym::test
if CRATE_HIR_ID != hir_id=> {
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
meta.span(),
|lint| {
lint.build(
"`#![doc(test(...)]` is only allowed \
as a crate level attribute"
)
.emit();
},
);
return false;
}
sym::alias
| sym::cfg
| sym::hidden
| sym::html_favicon_url
| sym::html_logo_url
| sym::html_no_source
| sym::html_playground_url
| sym::html_root_url
| sym::include
| sym::inline
| sym::issue_tracker_base_url
| sym::keyword
| sym::masked
| sym::no_default_passes // deprecated
| sym::no_inline
| sym::passes // deprecated
| sym::plugins // removed, but rustdoc warns about it itself
| sym::primitive
| sym::spotlight
| sym::test => {}
_ => {
self.tcx.struct_span_lint_hir(
INVALID_DOC_ATTRIBUTES,
hir_id,
i_meta.span,
|lint| {
lint.build(&format!(
"unknown `doc` attribute `{}`",
i_meta.name_or_empty()
))
.emit();
},
);
return false;
}
}
}
}
}
true
}
}
And here's the output:
error[internal]: left behind trailing whitespace
--> /playground/src/main.rs:13:13:37
|
13 | sym::keyword
| ^
|
error[internal]: left behind trailing whitespace
--> /playground/src/main.rs:19:19:34
|
19 | sym::test
| ^
|
error[internal]: left behind trailing whitespace
--> /playground/src/main.rs:35:35:0
|
35 |
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
warning: rustfmt has failed to format. See previous 3 errors.
Expected behavior
The code should be formatted correctly and no errors should be reported.
Meta
- rustfmt version:
1.4.36-nightly (2021-02-07 7de6968) (current playground version)
- From where did you install rustfmt?: rust-lang/rust x.py as well as Rust Playground
- How do you run rustfmt: x.py and playground
Describe the bug
rustfmt reports
error[internal]: left behind trailing whitespaceon this code. Also, in a previous iteration of the code (with theifguards in the body of the match arms instead of being guards), rustfmt failed to format the code without reporting any errors or warnings.To Reproduce
Here's the code (same as in the playground):
And here's the output:
Expected behavior
The code should be formatted correctly and no errors should be reported.
Meta
1.4.36-nightly (2021-02-07 7de6968)(current playground version)