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

unnecessary_lazy_evaluations suggestions cause type inferrence errors #6240

Closed
jyn514 opened this issue Oct 27, 2020 · 0 comments · Fixed by #6272
Closed

unnecessary_lazy_evaluations suggestions cause type inferrence errors #6240

jyn514 opened this issue Oct 27, 2020 · 0 comments · Fixed by #6272
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@jyn514
Copy link
Member

jyn514 commented Oct 27, 2020

I tried this code (https://github.com/rust-lang/rust/blob/0da6d42f297642a60f2640ec313b879b376b9ad8/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs#L539):

    (|| {
        if let Some(a) = AbstractConst::new(tcx, a, a_substs)? {
            if let Some(b) = AbstractConst::new(tcx, b, b_substs)? {
                return Ok(try_unify(tcx, a, b));
            }
        }

        Ok(false)
    })()
    .unwrap_or_else(|ErrorReported| true)

I expected to see this happen: Not entirely sure ... maybe the lint shouldn't fire at all here, since there's an explicit type annotation for a unit struct?

Instead, this happened: Since ErrorReported is helping inferrence, inference breaks once it's gone.

error[E0282]: type annotations needed
   --> compiler/rustc_trait_selection/src/traits/const_evaluatable.rs:539:26
    |
539 |         if let Some(a) = AbstractConst::new(tcx, a, a_substs)? {
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type

warning: unnecessary closure used to substitute value for `Result::Err`
   --> compiler/rustc_trait_selection/src/traits/const_evaluatable.rs:538:5
    |
538 | /     (|| {
539 | |         if let Some(a) = AbstractConst::new(tcx, a, a_substs)? {
540 | |             if let Some(b) = AbstractConst::new(tcx, b, b_substs)? {
541 | |                 return Ok(try_unify(tcx, a, b));
...   |
546 | |     })()
547 | |     .unwrap_or_else(|ErrorReported| true)
    | |_________________________________________^
    |
    = note: `#[warn(clippy::unnecessary_lazy_evaluations)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
help: Use `unwrap_or` instead
    |
538 |     (|| {
539 |         if let Some(a) = AbstractConst::new(tcx, a, a_substs)? {
540 |             if let Some(b) = AbstractConst::new(tcx, b, b_substs)? {
541 |                 return Ok(try_unify(tcx, a, b));
542 |             }
543 |         }

Meta

  • cargo clippy -V: clippy 0.0.212 (ffa2e7a 2020-10-24)
@jyn514 jyn514 added the C-bug Category: Clippy is not doing the correct thing label Oct 27, 2020
bors added a commit that referenced this issue Nov 7, 2020
Fix unnecessary_lazy_eval suggestion applicability

changelog: Fix unnecessary_lazy_eval suggestion applicability when breaking type inference

Fixes #6240
@bors bors closed this as completed in c0d1002 Nov 7, 2020
Ryan1729 pushed a commit to Ryan1729/rust-clippy that referenced this issue Nov 7, 2020
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.

1 participant