From 5d4404634a3d22a9db45f1bcfbd5b30ce9e81fb0 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 30 Mar 2025 06:36:06 -0700 Subject: [PATCH 1/2] Link everything in the precedence table This is intended to help navigate to what the thing it is referring to. Unfortunately this makes the markdown source a little messy, but other approaches weren't much better. --- src/expressions.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/expressions.md b/src/expressions.md index 8827c9592..80bbb97d2 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -76,25 +76,25 @@ Binary Operators at the same precedence level are grouped in the order given by | Operator/Expression | Associativity | |-----------------------------|---------------------| -| Paths | | -| Method calls | | -| Field expressions | left to right | -| Function calls, array indexing | | -| `?` | | -| Unary `-` `*` `!` `&` `&mut` | | -| `as` | left to right | -| `*` `/` `%` | left to right | -| `+` `-` | left to right | -| `<<` `>>` | left to right | -| `&` | left to right | -| `^` | left to right | -| | | left to right | -| `==` `!=` `<` `>` `<=` `>=` | Require parentheses | -| `&&` | left to right | -| || | left to right | -| `..` `..=` | Require parentheses | -| `=` `+=` `-=` `*=` `/=` `%=`
`&=` |= `^=` `<<=` `>>=` | right to left | -| `return` `break` closures | | +| [Paths][expr.path] | | +| [Method calls][expr.method] | | +| [Field expressions][expr.field] | left to right | +| [Function calls][expr.call], [array indexing][expr.array.index] | | +| [`?`][expr.try] | | +| Unary [`-`][expr.negate] [`!`][expr.negate] [`*`][expr.deref] [`&`][expr.operator.borrow] [`&mut`][expr.operator.borrow] | | +| [`as`][expr.as] | left to right | +| [`*`][expr.arith-logic] [`/`][expr.arith-logic] [`%`][expr.arith-logic] | left to right | +| [`+`][expr.arith-logic] [`-`][expr.arith-logic] | left to right | +| [`<<`][expr.arith-logic] [`>>`][expr.arith-logic] | left to right | +| [`&`][expr.arith-logic] | left to right | +| [`^`][expr.arith-logic] | left to right | +| [|][expr.arith-logic] | left to right | +| [`==`][expr.cmp] [`!=`][expr.cmp] [`<`][expr.cmp] [`>`][expr.cmp] [`<=`][expr.cmp] [`>=`][expr.cmp] | Require parentheses | +| [`&&`][expr.bool-logic] | left to right | +| [||][expr.bool-logic] | left to right | +| [`..`][expr.range] [`..=`][expr.range] | Require parentheses | +| [`=`][expr.assign] [`+=`][expr.compound-assign] [`-=`][expr.compound-assign] [`*=`][expr.compound-assign] [`/=`][expr.compound-assign] [`%=`][expr.compound-assign]
[`&=`][expr.compound-assign] [|=][expr.compound-assign] [`^=`][expr.compound-assign] [`<<=`][expr.compound-assign] [`>>=`][expr.compound-assign] | right to left | +| [`return`][expr.return] [`break`][expr.loop.break] [closures][expr.closure] | | r[expr.operand-order] ## Evaluation order of operands From c5183c6de079262496220d79878bec099809859f Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 30 Mar 2025 06:40:30 -0700 Subject: [PATCH 2/2] Clarify all borrow operators in the precedence table This removes `&` and `&mut` and instead just links to the full grammar for what the borrow operators are. There are many other variants, like `&&` or `&raw`, and I didn't want to write all of them down. The keywords after the `&&` are just modifiers, and are not really separate things to be considered anyways. Closes https://github.com/rust-lang/reference/issues/1726 --- src/expressions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expressions.md b/src/expressions.md index 80bbb97d2..8c5c92f32 100644 --- a/src/expressions.md +++ b/src/expressions.md @@ -81,7 +81,7 @@ Binary Operators at the same precedence level are grouped in the order given by | [Field expressions][expr.field] | left to right | | [Function calls][expr.call], [array indexing][expr.array.index] | | | [`?`][expr.try] | | -| Unary [`-`][expr.negate] [`!`][expr.negate] [`*`][expr.deref] [`&`][expr.operator.borrow] [`&mut`][expr.operator.borrow] | | +| Unary [`-`][expr.negate] [`!`][expr.negate] [`*`][expr.deref] [borrow][expr.operator.borrow] | | | [`as`][expr.as] | left to right | | [`*`][expr.arith-logic] [`/`][expr.arith-logic] [`%`][expr.arith-logic] | left to right | | [`+`][expr.arith-logic] [`-`][expr.arith-logic] | left to right |