Skip to content

Strange linebreaks introduced in if-let expressions with let_chains #5946

Description

@RalfJung

I haven't found a self-contained example of this yet, but this commit demonstrates the problem: rustfmt changes

                if let Ok(name) = str::from_utf8(name) && is_dyn_sym(name) {
                    let ptr = this.fn_ptr(FnVal::Other(DynSym::from_str(name)));
                    this.write_pointer(ptr, dest)?;
                } else {
                    this.write_null(dest)?;
                }

to

                if let Ok(name) = str::from_utf8(name)
                    && is_dyn_sym(name)
                {
                    let ptr = this.fn_ptr(FnVal::Other(DynSym::from_str(name)));
                    this.write_pointer(ptr, dest)?;
                } else {
                    this.write_null(dest)?;
                }

Which looks worse due to splitting the if over multiple lines, and which looks like a bug since in the original code, this line was actually shorter than the next one, so it is clearly below the threshold for breaking long lines. I've never seen normal if behave like that, so it's probably something specific to if let, maybe specific to let_chains even.

This is a recent regression, until recently rustfmt didn't change our formatting here.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions