- Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
It seems that disallowed-methods' replacement is pasted in as an opaque string, which stops it working for different method call syntaxes.
Reproducer
I tried this code:
// src/main.rs fn main() { let x: f64 = 5.0; _ = x.round(); }# clippy.toml disallowed-methods = [{ path = "f64::round", replacement = "f64::round_ties_even" }] # Cargo.toml [package] name = "foo" edition = "2024"cargo clippy --fix --allow-no-vcsI expected to see this happen:
.round replaced with .round_ties_even.
Instead, this happened:
Clippy tries to produce _ = x.f64::round_ties_even(); and then gets upset. Click for full error message.
Checking foo v0.0.0 (/home/tom.fryers/clippytest) warning: failed to automatically apply fixes suggested by rustc to crate `foo` after fixes were automatically applied the compiler reported errors within these files: * src/main.rs This likely indicates a bug in either rustc or cargo itself, and we would appreciate a bug report! You're likely to see a number of compiler warnings after this message which cargo attempted to fix but failed. If you could open an issue at https://github.com/rust-lang/rust-clippy/issues quoting the full output of this command we'd be very appreciative! Note that you may be able to make some more progress in the near-term fixing code with the `--broken-code` flag The following errors were reported: error: expected one of `(`, `.`, `;`, `?`, `else`, `}`, or an operator, found `::` --> src/main.rs:3:14 | 3 | _ = x.f64::round_ties_even(); | ^^ expected one of 7 possible tokens error: aborting due to 1 previous error Original diagnostics will follow. warning: use of a disallowed method `f64::round` --> src/main.rs:3:11 | 3 | _ = x.round(); | ^^^^^ help: use: `f64::round_ties_even` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods = note: `#[warn(clippy::disallowed_methods)]` on by default warning: `foo` (bin "foo") generated 1 warning (run `cargo clippy --fix --bin "foo"` to apply 1 suggestion) warning: failed to automatically apply fixes suggested by rustc to crate `foo` after fixes were automatically applied the compiler reported errors within these files: * src/main.rs This likely indicates a bug in either rustc or cargo itself, and we would appreciate a bug report! You're likely to see a number of compiler warnings after this message which cargo attempted to fix but failed. If you could open an issue at https://github.com/rust-lang/rust-clippy/issues quoting the full output of this command we'd be very appreciative! Note that you may be able to make some more progress in the near-term fixing code with the `--broken-code` flag The following errors were reported: error: expected one of `(`, `.`, `;`, `?`, `else`, `}`, or an operator, found `::` --> src/main.rs:3:14 | 3 | _ = x.f64::round_ties_even(); | ^^ expected one of 7 possible tokens error: aborting due to 1 previous error Original diagnostics will follow. warning: `foo` (bin "foo" test) generated 1 warning (1 duplicate) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s The replacement works fine if I qualify the method call:
_ = f64::round(x); It also works if I change replacement in clippy.toml to round_ties_even. But that breaks the qualified call.
Version
rustc 1.87.0 (17067e9ac 2025-05-09) binary: rustc commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359 commit-date: 2025-05-09 host: x86_64-unknown-linux-gnu release: 1.87.0 LLVM version: 20.1.1 Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied