From 380650217e84781d6b27377e945abf27e78c7848 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 7 Dec 2017 15:53:29 +1300 Subject: [PATCH] Binary ops Closes #18 --- guide/expressions.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/guide/expressions.md b/guide/expressions.md index 5e51b09..99fc6c2 100644 --- a/guide/expressions.md +++ b/guide/expressions.md @@ -193,7 +193,8 @@ fn main() { ### Unary operations Do not include a space between a unary op and its operand (i.e., `!x`, not -`! x`). +`! x`). However, there must be a space after `&mut`. Avoid line-breaking +between a unary operator and its operand. ### Binary operations @@ -203,6 +204,17 @@ For comparison operators, because for `T op U`, `&T op &U` is also implemented: if you have `t: &T`, and `u: U`, prefer `*t op u` to `t op &u`. In general, within expressions, prefer dereferencing to taking references. +Use parentheses liberally, do not necessarily elide them due to precedence. +Tools should not automatically insert or remove parentheses. Do not use spaces +to indicate precedence. + +If line-breaking, put the operator on a new line and block indent. E.g., + +```rust +foo + bar + baz + + qux + whatever +``` + ### Control flow Do not include extraneous parentheses for `if` and `while` expressions.