Fixed implicit borrow of expressions #390
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This does not introduce any breaking changes*.
The change fixes so expressions are now borrowed as a whole, instead of only the first value. Which would cause compile errors, for types that don't implement e.g.
Add<T> for &T
.In short expressions now expand into
&(...)
instead of&...
.* Technically, it would be considered a breaking change. However, I'd say it's highly unlikely someone has implemented e.g.
Add<T> for &T
and notAdd<T> for T
. To be able to rely on something that could be considered inconsistent behavior.Example 1
Minimal example:
Which expands like this:
Before:
&true && true
After:
&(true && true)
Resulting in the following compile error:
This isn't and was never an issue for e.g.
{{ 1 + 2 }}
, as the various operators e.g.Add<&T> for T
are implemented for various types. However, this is not the case for short-circuit operators.To have a more complete example of when this applies. I personally have a few macros, which accept booleans to decide on what it expands to.
Which expands like this:
Before:
let (b) = (&true && true);
After:
let (b) = (&(true && true));
The fact that
.clone()
is needed, is a whole other can of worms.Example 2
Another example where this also manifests itself is:
Once again only
Add<Duration> for SystemTime
exists, so this also resulted in a compile error: