mul_add struggling with long expressions #4735
Labels
C-bug
Category: Clippy is not doing the correct thing
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
I've recently gotten the clippy lint for mul_add and ran into it with a cubic bezier calculation.
Currently the function looks like this:
The initial lint for this function alone looks something like this:
Since there is a lot of multiplication and adding going on, the output is quite a bit to take in. However, following its suggestions can lead to incorrect code.
The first expression correctly recognizes the whole thing as a single expression (potentially by pure coincidence) and suggests a change that does not break things, since it respects the order of mathematical operations.
However, when looking at more of the output, it seems like the later suggestions only look at part of the operation. Especially when both multiplication and addition is involved at the same time on multiple levels, this can be dangerous. If I look at the output in my terminal and start at the bottom with the last thing output first, then I'll break the code.
The following code would be the result of applying the last suggestion:
The issue with this is that performing a
x.mul_add
first, means that the other multiplications are done after the addition. With a single parenthesis, which fixes the suggestion, the issue is probably explained best:The text was updated successfully, but these errors were encountered: