Skip to content
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

"error[internal]: left behind trailing whitespace" reported on code with rightward drift #4750

Closed
camelid opened this issue Mar 11, 2021 · 2 comments

Comments

@camelid
Copy link
Member

camelid commented Mar 11, 2021

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

  1. Run rustfmt on this playground code.
  2. 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
@camelid camelid added the bug Panic, non-idempotency, invalid code, etc. label Mar 11, 2021
@camelid
Copy link
Member Author

camelid commented Mar 11, 2021

I manually removed the whitespace but rustfmt still isn't formatting the new code, though it stopped reporting errors.

@calebcartwright
Copy link
Member

Thanks for sharing, though closing as duplicate because the root cause is the same as #4119. If you remove those line-style comments between the patterns towards the end (e.g. // deprecated) then rustfmt will carry on happily.

@calebcartwright calebcartwright added duplicate and removed bug Panic, non-idempotency, invalid code, etc. labels Mar 12, 2021
camelid added a commit to camelid/rust that referenced this issue Mar 13, 2021
This change makes it easier to follow the control flow.

I also moved the end-of-line comments attached to some symbols to before
the symbol listing. This allows rustfmt to format the code; otherwise no
formatting occurs (see rust-lang/rustfmt#4750).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants