rust-lang / rust-lang/rust-clippy
Clippy can't fix warnings because compiler false error
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Hello everyone,
I was trying to automatically fix all the warnings of Clippy, but I got this error:
warning: failed to automatically apply fixes suggested by rustc to crate `trivial_packager`
after fixes were automatically applied the compiler reported errors within these files:
* src/register_handler.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/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[E0425]: cannot find value `user` in this scope
--> src/register_handler.rs:32:32
|
32 | Ok(HttpResponse::Ok().json(user))
| ^^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.
Original diagnostics will follow.
But the code works fine when executing cargo run.
The full project can be found at github
Reproducer
I tried this code:
pub async fn register_user(
user_data: web::Json<UserData>,
pool: web::Data<Pool>,
) -> Result<HttpResponse, actix_web::Error> {
let user_data = user_data.into_inner();
if !(user_data.gender == String::from("B") || user_data.gender == String::from("G")) {
return Err(actix_web::error::ErrorBadRequest("Missing gender"));
} else if !(user_data.role == String::from("A") || user_data.role == String::from("T")) {
return Err(actix_web::error::ErrorBadRequest("Missing role"));
}
let user = web::block(move || query(user_data, pool)).await??;
Ok(HttpResponse::Ok().json(&user))
}
I expected to see this happen: Successful. All warnings fixed
Instead, this happened: (see above)
Version
rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-unknown-linux-gnu
release: 1.68.2
LLVM version: 15.0.6
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied register_user reproducer and src/register_handler.rs using rustc 1.68.2. Reproduce the automatic Clippy fix attempt, compare it with cargo run, and determine whether the E0425 error is introduced during fixing. Done means the reported false compiler error is reproduced and the affected behavior has a clear diagnosis or regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100