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 #6141

Closed
skrobchik opened this issue Apr 8, 2024 · 6 comments
Closed

error[internal]: left behind trailing whitespace #6141

skrobchik opened this issue Apr 8, 2024 · 6 comments
Labels
duplicate e-trailing whitespace error[internal]: left behind trailing whitespace

Comments

@skrobchik
Copy link

skrobchik commented Apr 8, 2024

Hello 👋

I'm getting an error when running cargo fmt in my project. Here's the commit.

Not sure if you need any logs? I didn't see any guidelines for filing bug reports, so please let me know if anything is needed 😄

PS C:\Users\Robert\Desktop\Git Projects\calenda-rs> git clean -ffdx
PS C:\Users\Robert\Desktop\Git Projects\calenda-rs> git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
PS C:\Users\Robert\Desktop\Git Projects\calenda-rs> cargo fmt
error[internal]: left behind trailing whitespace
   --> \\?\C:\Users\Robert\Desktop\Git Projects\calenda-rs\crates\calendars_egui\src\class_editor.rs:132:132:1
    |
132 |
    | ^^^^
    |

error[internal]: left behind trailing whitespace
   --> \\?\C:\Users\Robert\Desktop\Git Projects\calenda-rs\crates\calendars_egui\src\class_editor.rs:145:145:1
    |
145 |
    | ^^^^
    |

warning: rustfmt has failed to format. See previous 2 errors.

PS C:\Users\Robert\Desktop\Git Projects\calenda-rs> rustfmt --version
rustfmt 1.7.0-nightly (9d5cdf75 2024-04-07)
PS C:\Users\Robert\Desktop\Git Projects\calenda-rs> rustc --version
rustc 1.79.0-nightly (9d5cdf75a 2024-04-07)
PS C:\Users\Robert\Desktop\Git Projects\calenda-rs> cargo --version
cargo 1.79.0-nightly (28e7b2bc0 2024-04-05)
PS C:\Users\Robert\Desktop\Git Projects\calenda-rs>
@ytmimi
Copy link
Contributor

ytmimi commented Apr 8, 2024

@skrobchik thanks for the report. When you get a chance, can you try to minimize the reproducible example to be as small as possible. Taking a look at the commit that you referenced I suspect this might be another duplicate of #3863 leading to rustfmt complaining about whitespace that exists within the source code.

@ytmimi ytmimi added e-trailing whitespace error[internal]: left behind trailing whitespace needs-mcve needs a Minimal Complete and Verifiable Example labels Apr 8, 2024
@ealinye
Copy link

ealinye commented Apr 10, 2024

this error also happen in my project, while formating chain-call, like:

        let benches: Vec<_> = self[gidx]
            .res
            
            .iter()

then:

yiyue@terc ~/Pin1Yin1-Compiler-Rust (main)> rustfmt py-ast/src/semantic/declare/map.rs
error[internal]: left behind trailing whitespace
  --> /home/yiyue/Pin1Yin1-Compiler-Rust/py-ast/src/semantic/declare/map.rs:72:72:1
   |
72 |             
   | ^^^^^^^^^^^^
   |

warning: rustfmt has failed to format. See previous 1 errors.

because i always use vscode's format on save to format my code, it's hard to not notice that the code is not formated after i changed the code

although i can get error by using cli, there are not any log are printed...

@konstin
Copy link

konstin commented Apr 17, 2024

Here's a semi minimal example (make sure your ide doesn't remove trailing whitespace by default):

impl Preferences {
    fn from_iter() -> Self {
        Self(
            preferences
                .filter_map(|preference| {
                    trace!(
                        "Excluding {} from preferences due to unmatched markers.", requirement.name
                    );
                    match requirement {
                        UvSource => {
                            if *ve {
                                trace!(
                                    "Excluding {} from preferences due to inexact version specifier.", requirement.name
                                );
                            }
                        }
                    }

                    

                })
                .collect(),
        )
    }
}

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=01c66f1e423afb96d09aaebbbf5f7e33

@ytmimi
Copy link
Contributor

ytmimi commented Apr 17, 2024

@konstin your example is definitely a duplicate of #3863. preferences.filter_map().collect() is a chain, and there are lines that exceed the max_width.

Because of the nested nature of the code, the line with the string literal exceeds the default width of 100.

                                trace!(
                                    "Excluding {} from preferences due to inexact version specifier.", requirement.name
                                );

You have 3 options:

  1. bump the max_width
  2. manually break the string literal over multiple lines
  3. if you're using nightly rustfmt you can try using format_strings=true

@ytmimi
Copy link
Contributor

ytmimi commented Apr 17, 2024

@skrobchik having just reviewed the commit it would seem that this line 👇🏼 is causing the ui.vertical(|ui| {}) call on line 60 from being formatted, therefore failing to remove whitespace that exists in the program.

              "El programa intentara asignar una aula de las categorias seleccionadas a esta clase.",

Taking a look at the file shows that there is indeed trailing whitespace in the commit:

Screen Shot 2024-04-17 at 11 25 21 AM

The advice to resolve this is the same as I mentioned above, with the addition that you could refactor your code and extract your message into a constant. For example:

const HOVER_TEXT: &str = "El programa intentara asignar una aula de las categorias seleccionadas a esta clase.";

ui.label(RichText::new("Aulas Permitidas").strong()).on_hover_text(HOVER_TEXT);

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
@ytmimi ytmimi added duplicate and removed needs-mcve needs a Minimal Complete and Verifiable Example labels Apr 17, 2024
@konstin
Copy link

konstin commented Apr 17, 2024

Would it be possible to disable the trailing whitespace check if rustfmt gave up on a too long line? Rustfmt not touching a piece of the AST is fine, the current error makes it look like you discovered a bad rustfmt bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate e-trailing whitespace error[internal]: left behind trailing whitespace
Projects
None yet
Development

No branches or pull requests

4 participants