Skip to content

Fixups for operator ref #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/expressions/operator-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let a = & & & & mut 10;
The `*` (dereference) operator is also a unary prefix operator. When applied to
a [pointer](types.html#pointer-types) it denotes the pointed-to location. If
the expression is of type `&mut T` and `*mut T`, and is either a local
variable, a (nested) field of a local variance or is a mutable [place
variable, a (nested) field of a local variable or is a mutable [place
expression], then the resulting memory location can be assigned to.
Dereferencing a raw pointer requires `unsafe`.

Expand Down Expand Up @@ -207,15 +207,17 @@ expression context][value expression] so are moved or copied.
| `+` | Addition | | Addition | `std::ops::Add` |
| `-` | Subtraction | | Subtraction | `std::ops::Sub` |
| `*` | Multiplication | | Multiplication | `std::ops::Mul` |
| `/` | Division | | Division | `std::ops::Div` |
| `/` | Division* | | Division | `std::ops::Div` |
| `%` | Remainder | | Remainder | `std::ops::Rem` |
| `&` | Bitwise AND | Logical AND | | `std::ops::BitAnd` |
| <code>&#124;</code> | Bitwise OR | Logical OR | | `std::ops::BitOr` |
| `^` | Bitwise XOR | Logical XOR | | `std::ops::BitXor` |
| `<<` | Left Shift | | | `std::ops::Shl` |
| `>>` | Right Shift* | | | `std::ops::Shr` |
| `>>` | Right Shift** | | | `std::ops::Shr` |

\* Arithmetic right shift on signed integer types, logical right shift on
\* Integer division rounds towards zero.

\*\* Arithmetic right shift on signed integer types, logical right shift on
unsigned integer types.

Here are examples of these operators being used.
Expand Down Expand Up @@ -345,10 +347,13 @@ well as the following additional casts. Here `*T` means either `*const T` or
| `&[T; n]` | `*const T` | Array to pointer cast |
| [Function pointer](types.html#function-pointer-types) | `*V` where `V: Sized` | Function pointer to pointer cast |
| Function pointer | Integer | Function pointer to address cast |
| Closure \*\* | Function pointer | Closure to function pointer cast |

\* or `T` and `V` are compatible unsized types, e.g., both slices, both the
same trait object.

\*\* only for closures that do capture (close over) any local variables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "do not" I believe, and probably should link to the closure types section which details this further.


### Semantics

* Numeric cast
Expand Down Expand Up @@ -390,7 +395,8 @@ same trait object.
> &nbsp;&nbsp; | [_Expression_] `=` [_Expression_]

An _assignment expression_ consists of a [place expression] followed by an
equals sign (`=`) and a [value expression].
equals sign (`=`) and a [value expression]. Such an expression always has
the [`unit` type].

Evaluating an assignment expression [drops](destructors.html) the left-hand
operand, unless it's an uninitialized local variable or field of a local variable,
Expand Down