Skip to content

Commit 7a7ffce

Browse files
authored
Rollup merge of #113143 - joshtriplett:style-guide-narrow-dereference-guidance, r=calebcartwright
style-guide: Narrow guidance about references and dereferencing The style guide advises "prefer dereferencing to taking references", but doesn't give guidance on when that "preference" should get overridden by other considerations. Give an example of when it's fine to ignore that advice.
2 parents c0e37ad + 025dd3a commit 7a7ffce

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: src/doc/style-guide/src/expressions.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ and other assignment operators such as `+=` or `*=`).
288288

289289
For comparison operators, because for `T op U`, `&T op &U` is also implemented:
290290
if you have `t: &T`, and `u: U`, prefer `*t op u` to `t op &u`. In general,
291-
within expressions, prefer dereferencing to taking references.
291+
within expressions, prefer dereferencing to taking references, unless necessary
292+
(e.g. to avoid an unnecessarily expensive operation).
292293

293294
Use parentheses liberally, do not necessarily elide them due to precedence.
294295
Tools should not automatically insert or remove parentheses. Do not use spaces

0 commit comments

Comments
 (0)