Whitespace [FIXME: needs RFC]

Spaces

#[deprecated = "Use `bar` instead."]
fn foo(a: uint, b: uint) -> uint {
    a + b
}
fn foo(a: Bar);

MyStruct { foo: 3, bar: 4 }

foo(bar, baz);
spawn(proc() { do_something(); })

Point { x: 0.1, y: 0.3 }

Line wrapping

fn frobnicate(a: Bar, b: Bar,
              c: Bar, d: Bar)
              -> Bar {
    ...
}

fn foo<T: This,
       U: That>(
       a: Bar,
       b: Bar)
       -> Baz {
    ...
}
fn foo_bar(a: Bar, b: Bar,
           c: |Bar|) -> Bar {
    ...
}

// Same line is fine:
foo_bar(x, y, |z| { z.transpose(y) });

// Indented body on new line is also fine:
foo_bar(x, y, |z| {
    z.quux();
    z.rotate(x)
})

[FIXME] Do we also want to allow the following?

frobnicate(
    arg1,
    arg2,
    arg3)

This style could ease the conflict between line length and functions with many parameters (or long method chains).

Matches

  • [Deprecated] If you have multiple patterns in a single match arm, write each pattern on a separate line:

    match foo {
        bar(_)
        | baz => quux,
        x
        | y
        | z => {
            quuux
        }
    }
    

Alignment

Idiomatic code should not use extra whitespace in the middle of a line to provide alignment.

// Good
struct Foo {
    short: f64,
    really_long: f64,
}

// Bad
struct Bar {
    short:       f64,
    really_long: f64,
}

// Good
let a = 0;
let radius = 7;

// Bad
let b        = 0;
let diameter = 7;