Skip to content

Commit 9097161

Browse files
authored
Merge pull request #118 from rust-lang-nursery/misc-2
assignment ops, impls, and `|` in match patterns
2 parents 09c93cc + 77c8349 commit 9097161

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

guide/expressions.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ between a unary operator and its operand.
284284

285285
### Binary operations
286286

287-
Do include spaces around binary ops (i.e., `x + 1`, not `x+1`) (including `=`).
287+
Do include spaces around binary ops (i.e., `x + 1`, not `x+1`) (including `=`
288+
and other assignment operators such as `+=` or `*=`).
288289

289290
For comparison operators, because for `T op U`, `&T op &U` is also implemented:
290291
if you have `t: &T`, and `u: U`, prefer `*t op u` to `t op &u`. In general,
@@ -301,6 +302,9 @@ foo + bar + baz
301302
+ qux + whatever
302303
```
303304

305+
Prefer line-breaking at an assignment operator (either `=` or `+=`, etc.) rather
306+
than at other binary operators.
307+
304308
### Control flow
305309

306310
Do not include extraneous parentheses for `if` and `while` expressions.
@@ -585,8 +589,8 @@ body on a new line:
585589
```
586590

587591
If required to break the pattern, put each clause of the pattern on its own
588-
line, breaking before the `|`. If there is an `if` clause, then you must use the
589-
above form:
592+
line with no additional indent, breaking before the `|`. If there is an `if`
593+
clause, then you must use the above form:
590594

591595
```rust
592596
a_very_long_pattern

guide/items.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,40 @@ pub trait IndexRanges:
198198
```
199199

200200

201+
### Impls
202+
203+
Impl items should be block indented. If there are no items, the impl may be
204+
formatted on a single line. Otherwise there should be line-breaks after the
205+
opening brace and before the closing brace:
206+
207+
```rust
208+
impl Foo {}
209+
210+
impl Bar for Foo {
211+
...
212+
}
213+
```
214+
215+
Avoid line-breaking in the signature if possible. If a line break is required in
216+
a non-inherent impl, break immediately before `for`, block indent the concrete type
217+
and put the opening brace on it's own line:
218+
219+
```rust
220+
impl Bar
221+
for Foo
222+
{
223+
...
224+
}
225+
```
226+
227+
201228
### Extern crate
202229

203230
`extern crate foo;`
204231

205232
Use spaces around keywords, no spaces around the semi-colon.
206233

234+
207235
### Modules
208236

209237
```rust

0 commit comments

Comments
 (0)