Skip to content

Nested call chains have weird formatting #7119

Open

Description

@Xyndra
/// Returns n_1, b_1, n_2, b_2
fn distribute(sum: u64) -> (u64, u64, u64, u64) {
    let mut a = sum;
    // ...
    if a == 1 {
        // ...
    } else {
        let kmax: u64 = a.ilog2().into();
        let pow_2_kmax: u64 = (2_i32
            .pow(kmax.try_into().expect("k_max could not convert into u32")))
        .try_into()
        .expect("2^(k_max) could not convert to u64");
        return (kmax + 1 + m, 1, a - pow_2_kmax + 1 + m, a - pow_2_kmax);
    }
}

What I would expect:

/// Returns n_1, b_1, n_2, b_2
fn distribute(sum: u64) -> (u64, u64, u64, u64) {
    let mut a = sum;
    // ...
    if a == 1 {
        // ...
    } else {
        let kmax: u64 = a.ilog2().into();
        let pow_2_kmax: u64 = (2_i32
                .pow(kmax.try_into().expect("k_max could not convert into u32")))
            .try_into()
            .expect("2^(k_max) could not convert to u64");
        return (kmax + 1 + m, 1, a - pow_2_kmax + 1 + m, a - pow_2_kmax);
    }
}

Activity

  1. added
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Sep 13, 2026
  2. ytmimi commented on Sep 13, 2026

    @ytmimi
    Contributor

    Can you do a better job explaining what the issue is?

  3. Xyndra commented on Sep 13, 2026

    @Xyndra
    Author

    The issue is that it is not indenting the function calls like it normally would.
    Usually, it indents like this:

        stdin()
            .read_line(&mut file_path)
            .expect("Eingabe konnte nicht eingelesen werden!");

    But in the example I provided, they are all in the column where the base calls/assignments/definitions usually are

  4. added
    A-ASTArea: Abstract Syntax Tree (AST) related things
    on Sep 14, 2026
  5. ytmimi commented on Sep 14, 2026

    @ytmimi
    Contributor

    There's something about wrapping 2_i32.pow(kmax.try_into().expect("k_max could not convert into u32")) in parens that's causing the issue. The following formats just fine:

    Input

    /// Returns n_1, b_1, n_2, b_2
    fn distribute(sum: u64) -> (u64, u64, u64, u64) {
        let mut a = sum;
        // ...
        if a == 1 {
            // ...
        } else {
            let kmax: u64 = a.ilog2().into();
            let pow_2_kmax: u64 = 2_i32
                .pow(kmax.try_into().expect("k_max could not convert into u32"))
            .try_into()
            .expect("2^(k_max) could not convert to u64");
            return (kmax + 1 + m, 1, a - pow_2_kmax + 1 + m, a - pow_2_kmax);
        }
    }

    Output

    /// Returns n_1, b_1, n_2, b_2
    fn distribute(sum: u64) -> (u64, u64, u64, u64) {
        let mut a = sum;
        // ...
        if a == 1 {
            // ...
        } else {
            let kmax: u64 = a.ilog2().into();
            let pow_2_kmax: u64 = 2_i32
                .pow(kmax.try_into().expect("k_max could not convert into u32"))
                .try_into()
                .expect("2^(k_max) could not convert to u64");
            return (kmax + 1 + m, 1, a - pow_2_kmax + 1 + m, a - pow_2_kmax);
        }
    }
  6. added
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    and removed
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Sep 15, 2026
  7. changed the title [-]Ugly formatting[/-] [+]Nested call chains have weird formatting[/+] on Sep 22, 2026
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

    A-ASTArea: Abstract Syntax Tree (AST) related thingsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEI-poor-formattingIssue: poor formatting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions