Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy hangs on .unwrap().unwrap() as usize on nightly #12506

Closed
stevenengler opened this issue Mar 18, 2024 · 5 comments · Fixed by #12508
Closed

Clippy hangs on .unwrap().unwrap() as usize on nightly #12506

stevenengler opened this issue Mar 18, 2024 · 5 comments · Fixed by #12508
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@stevenengler
Copy link
Contributor

Summary

When running cargo clippy on a library with the following code using rust nightly, it hangs and never completes. The clippy process CPU usage is at 100% of a core while it's running.

If anyone has a better title, please update it since I'm not sure exactly what's causing the bug.

Reproducer

fn _foo() -> usize {
    let bar: Result<Option<i64>, u32> = Ok(Some(10));
    bar.unwrap().unwrap() as usize
}

It hangs with the output:

    Checking clippy-bug v0.1.0 (/tmp/clippy-bug)
    Building [                             ] 0/1: clippy-bug

(I've waited 5 minutes, so I'm assuming it would hang forever.)

Version

rustc 1.79.0-nightly (eb45c8444 2024-03-17)
binary: rustc
commit-hash: eb45c844407968ea54df0d9870ebce9e3235b706
commit-date: 2024-03-17
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

@stevenengler stevenengler added the C-bug Category: Clippy is not doing the correct thing label Mar 18, 2024
@Centri3
Copy link
Member

Centri3 commented Mar 18, 2024

Can't reproduce this on beta (currently 1.77.0-beta.9. The only commit since then is fc8f662

(This commit isn't in beta despite it being a few days ago, I think.)

@stevenengler
Copy link
Contributor Author

Can't reproduce this on beta (currently 1.77.0-beta.9. The only commit since then is fc8f662

(This commit isn't in beta despite it being a few days ago, I think.)

This can also be seen on the rust playground, where clippy works when set to "beta" but not "nightly".

@Centri3
Copy link
Member

Centri3 commented Mar 18, 2024

Oh yeah I know, this is an issue, I was saying that it's something new since beta (so that PR I think)

@y21
Copy link
Member

y21 commented Mar 18, 2024

Looks like it gets stuck in this loop
https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/casts/cast_sign_loss.rs#L135 (#12126)

This should probably reassign expr to actually peel off the method calls and not get stuck on the same expr forever?

bors added a commit that referenced this issue Mar 20, 2024
Fix infinite loop in `cast_sign_loss` when peeling unwrap method calls

Fixes #12506

The lint wants to peel method calls but didn't actually reassign the expression, leading to an infinite loop.

changelog: Fix infinite loop in [`cast_sign_loss`] when having two chained `.unwrap()` calls
@bors bors closed this as completed in f2020c8 Mar 22, 2024
@stevenengler
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants