Whitespace [FIXME: needs RFC]

Spaces

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

MyStruct { foo: 3, bar: 4 }

foo(bar, baz);
fn main() { spawn(proc() { do_something(); }) Point { x: 0.1, y: 0.3 } }
spawn(proc() { do_something(); })

Point { x: 0.1, y: 0.3 }

Line wrapping

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

fn foo<T: This,
       U: That>(
       a: Bar,
       b: Bar)
       -> Baz {
    ...
}
fn main() { 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) }) }
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?

fn main() { frobnicate( arg1, arg2, arg3) }
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:

    fn main() { match foo { bar(_) | baz => quux, x | y | z => { quuux } } }
    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.

fn main() { // 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; }
// 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;