Skip to content

Flickering line break #6240

Open
Open
@boozook

Description

@boozook

version: rustfmt 1.7.1-nightly (ba1d7f4a 2024-06-29)
config: rustfmt.toml

Formatting is flickering for looooong chain like this:

from this

let removed = roots.extract_if(|root| {  /* long block */ }).count();

to this and back:

let removed = 
    roots.extract_if(|root| {  /* long block */ }).count();

Flickering in this case means following:

  1. run rustfmt cargo/src/build/mod.rs => we've got new line-break
  2. run rustfmt cargo/src/build/mod.rs => line-break is gone
  3. repeat...

example as pr-annotation: boozook/playdate#399 (comment)

Activity

ytmimi

ytmimi commented on Jul 12, 2024

@ytmimi
Contributor

@boozook Thanks for the report. Please try to reduce this to a minimal reproducible example.

added
needs-mcveneeds a Minimal Complete and Verifiable Example
on Jul 12, 2024
boozook

boozook commented on Jul 12, 2024

@boozook
Author

@ytmimi, I honestly tried to get an isolated minimal reproducible example, but I can't, sorry. I suppose there is something complex 🤷🏻‍♂️

Also, just as little addition I've made neat video-demo in the IDE

Untitled.mov
ytmimi

ytmimi commented on Jul 12, 2024

@ytmimi
Contributor

Thanks for the video. You might try to copy the entire let removed assignment into a snippet that's just as indented as the current code and take it from there. If you're able to post that it might help someone start looking into what's going on.

boozook

boozook commented on Jul 13, 2024

@boozook
Author

@ytmimi, done!
example.zip

Seems to it depends on length of ling lines inside the block.

Important things in the config:

hard_tabs = true
tab_spaces = 3
mod foo {
	fn foo() {
		artifacts.extract_if(|(art, roots)| {
			         let removed = roots.extract_if(|root| {
				                       let ct =
					                       determine_crate_types(cfg, art, target, tk.clone(), ck).collect::<Vec<_>>();
			                       })
			                       .inspect(|r| {
				                       log::trace!("    excluded: {p}::{t} {:?}", match r.node().unit().platform {
					                       CompileKind::Host => "host",
				                          CompileKind::Target(ref kind) => kind.short_name(),
				                       })
			                       })
			                       .count();
		         });
	}
}

Also there is one more problem - cases of match has various indent:

  1. first has 5 tabs indent + 7*3 spaces align + 2 spaces in-block align
  2. second - 4 tabs indent + 8*3 spaces align + 2 spaces in-block align
added and removed
needs-mcveneeds a Minimal Complete and Verifiable Example
on Jan 14, 2025
boozook

boozook commented on Jan 30, 2025

@boozook
Author

I suppose there is tag bug is missed. 🤷🏻‍♂️

eirnym

eirnym commented on Jan 30, 2025

@eirnym

@ytmimi, I honestly tried to get an isolated minimal reproducible example, but I can't, sorry. I suppose there is something complex 🤷🏻‍♂️

Also, just as little addition I've made neat video-demo in the IDE
Untitled.mov

video not playable

boozook

boozook commented on Feb 5, 2025

@boozook
Author

This problem gives so much pain and requires additional complications to workaround. 😤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @eirnym@boozook@ytmimi

        Issue actions

          Flickering line break · Issue #6240 · rust-lang/rustfmt