Skip to content

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

Closed

Description

@camelid

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

Activity

  1. added
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    on Mar 11, 2021
  2. camelid commented on Mar 11, 2021

    @camelid
    MemberAuthor

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

  3. calebcartwright commented on Mar 12, 2021

    @calebcartwright
    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.

  4. added
    S-duplicateStatus: duplicate of another issue or PR
    and removed
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    on Mar 12, 2021
  5. added a commit that references this issue on Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S-duplicateStatus: duplicate of another issue or PR

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions