Skip to content

cargo clippy --fix tries to apply mul_add but causes [E0689] #14897

Open
@nik-sm

Description

@nik-sm

Summary

I tried enabling additional clippy lints and using --fix on a clean git status, but clippy reports an error and asks me to file a bug report.

Here's what I think happens:

  1. Clippy wants to change a line to use mul_add:
// Relevant lines before clippy: 
/* Line 59 */ let multiplier = if first.data > 0.0 { 1.0 } else { 0.0 };
/* Line 60 */ first.grad = Some(first.grad.unwrap_or(0.0) + multiplier * our_grad);

// What clippy wants:
/* Line 59 */ let multiplier = if first.data > 0.0 { 1.0 } else { 0.0 };
/* Line 60 */ first.grad = Some(multiplier.mul_add(our_grad, first.grad.unwrap_or(0.0)));
  1. For some reason, clippy's proposed change on line 60 causes an ambiguous type on line 59, which results in a compiler error. Here's the error that clippy causes:
error[E0689]: can't call method `mul_add` on ambiguous numeric type `{float}`
  --> src/main.rs:60:46
   |
60 |                 first.grad = Some(multiplier.mul_add(our_grad, first.grad.unwrap_or(0.0)));
   |                                              ^^^^^^^
   |
help: you must specify a type for this binding, like `f32`
   |
59 |                 let multiplier: f32 = if 2.0 > 0.0 { 1.0 } else { 0.0 };
   |                               +++++

error: aborting due to 1 previous error

Additional observations:

  • My rust analyzer VS Code plugin can infer the correct types on line 59 (the multiplier is an f64), even when line 60 is commented out. Here's the details of my rust analyzer plugin:
Identifier rust-lang.rust-analyzer
Version 0.3.2466
Last Updated 2025-05-20, 21:27:47
  • Clippy reports the same error twice
  • cargo clippy exits without error (which feels like a minor mistake perhaps) and my code ends up unchanged

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thing

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions