Skip to content

Commit

Permalink
style-guide: Narrow guidance about references and dereferencing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshtriplett committed Jun 29, 2023
1 parent eb76764 commit 025dd3a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/doc/style-guide/src/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ and other assignment operators such as `+=` or `*=`).

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.
within expressions, prefer dereferencing to taking references, unless necessary
(e.g. to avoid an unnecessarily expensive operation).

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

0 comments on commit 025dd3a

Please sign in to comment.