Skip to content

Commit 11dfc66

Browse files
authored
Merge pull request #110 from rust-lang-nursery/types
Types, macro uses, and hex lits
2 parents 167935d + 3552cdc commit 11dfc66

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

guide/expressions.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,34 @@ x.foo().bar().baz(x, y, z);
368368
```
369369

370370

371+
### Macro uses
372+
373+
Macros which can be parsed like other constructs should be formatted like those
374+
constructs. For example, a macro use `foo!(a, b, c)` can be parsed like a
375+
function call (ignoring the `!`), therefore it should be formatted following the
376+
rules for function calls.
377+
378+
#### Special case macros
379+
380+
Macros which take a format string and where all other arguments are *small* may
381+
be formatted with arguments before and after the format string on a single line
382+
and the format string on its own line, rather than putting each argument on its
383+
own line. For example,
384+
385+
```rust
386+
println!(
387+
"Hello {} and {}",
388+
name1, name2,
389+
);
390+
391+
assert_eq!(
392+
x, y,
393+
"x and y were not equal, see {}",
394+
reason,
395+
);
396+
```
397+
398+
371399
### Casts (`as`)
372400

373401
Put spaces before and after `as`:
@@ -660,3 +688,13 @@ a_long_expression
660688
For the sake of indicating precedence, we recommend that if either bound is a
661689
compound expression, then use parentheses around it, e.g., `..(x + 1)`,
662690
`(x.f)..(x.f.len())`, or `0..(x - 10)`.
691+
692+
693+
### Hexadecimal literals
694+
695+
Hexadecimal literals may use upper- or lower-case letters, but they must not be
696+
mixed within the same literal. Projects should use the same case for all
697+
literals, but we do not make a recommendation for either lower- or upper-case.
698+
Tools should have an option to convert mixed case literals to upper-case, and
699+
may have an option to convert all literals to either lower- or upper-case.
700+

guide/types.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,58 @@
11
## Types and Bounds
2+
3+
### Single line formatting
4+
5+
* `[T]` no spaces
6+
* `[T; expr]`, e.g., `[u32; 42]`, `[Vec<Foo>; 10 * 2 + foo()]` (space after colon, no spaces around square brackets)
7+
* `*const T`, `*mut T` (no space after `*`, space before type)
8+
* `&'a T`, `&T`, `&'a mut T`, `&mut T` (no space after `&`, single spaces separating other words)
9+
* `unsafe extern "C" fn<'a, 'b, 'c>(T, U, V) -> W` or `fn()` (single spaces around keyowrds and sigils, and after commas, no trailing commas, no spaces around brackets)
10+
* `!` should be treated like any other type name, `Name`
11+
* `(A, B, C, D)` (spaces after commas, no spaces around parens, no trailing comma unless it is a one-tuple)
12+
* `<Baz<T> as SomeTrait>::Foo::Bar` or `Foo::Bar` or `::Foo::Bar` (no spaces around `::` or angle brackets, single spaces around `as`)
13+
* `Foo::Bar<T, U, V>` (spaces after commas, no trailing comma, no spaces around angle brackets)
14+
* `T + T + T` (single spaces between types, and `+`).
15+
* `impl T + T + T` (single spaces between keyword, types, and `+`).
16+
17+
Parentheses used in types should not be surrounded by whitespace, e.g., `(Foo)`
18+
19+
20+
### Line breaks
21+
22+
Avoid breaking lines in types where possible. Prefer breaking at outermost scope, e.g., prefer
23+
24+
```rust
25+
Foo<
26+
Bar,
27+
Baz<Type1, Type2>,
28+
>
29+
```
30+
31+
to
32+
33+
```rust
34+
Foo<Bar, Baz<
35+
Type1,
36+
Type2,
37+
>>
38+
```
39+
40+
`[T; expr]` may be broken after the `;` if necessary.
41+
42+
Function types may be broken following the rules for function declarations.
43+
44+
Generic types may be broken following the rules for generics.
45+
46+
Types with `+` may be broken after any `+` using block indent and breaking before the `+`. When breaking such a type, all `+`s should be line broken, e.g.,
47+
48+
```rust
49+
impl Clone
50+
+ Copy
51+
+ Debug
52+
53+
Box<
54+
Clone
55+
+ Copy
56+
+ Debug
57+
>
58+
```

0 commit comments

Comments
 (0)