rust-lang / rust-lang/rustfmt

Internal error "left behind trailing whitespace" for assignment with RHS comment

Open
#4,515 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1x-backport:pending A-comments C-bug I-trailing-whitespace
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Describe the bug

error[internal]: left behind trailing whitespace
 --> /playground/src/main.rs:4:4:17
  |
4 |     let new_len = 
  |                  ^
  |

To Reproduce

Repros on the playground, https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8d26c934db762f2165ab9b0cc4d2ef61

    pub unsafe fn as_chunks_mut_unchecked<const N: usize>(&mut self) -> &mut [[T; N]] {
        debug_assert_ne!(N, 0);
        debug_assert_eq!(self.len() % N, 0);
        let new_len = 
            // SAFETY: Our precondition is exactly what's needed to call this
            unsafe { crate::intrinsics::exact_div(self.len(), N) };
        // SAFETY: We cast a slice of `new_len * N` elements into
        // a slice of `new_len` many `N` elements chunks.
        unsafe { from_raw_parts_mut(self.as_mut_ptr().cast(), new_len) }
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the playground reproduction and the Rust snippet in the issue, then run rustfmt to confirm the internal “left behind trailing whitespace” error. Trace the formatter path responsible for the assignment and comment layout, and use the reproduction as the regression case; done means this input formats without the internal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.