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

try_err false positive / incorrect suggestion with Poll return type #5855

Closed
tmiasko opened this issue Aug 2, 2020 · 0 comments · Fixed by #5857
Closed

try_err false positive / incorrect suggestion with Poll return type #5855

tmiasko opened this issue Aug 2, 2020 · 0 comments · Fixed by #5857
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Aug 2, 2020

The Poll type has two implementations of Try trait, for Poll<Result<T, E>> and Poll<Option<Result<T, E>>>.

Currently try_err lint does't take those into account and generates incorrect fix suggestion, for example in code below:

use std::task::Poll;
use std::io;

pub fn poll(n: usize) -> Poll<Option<io::Result<()>>> {
    match n {
        0 => Err(io::ErrorKind::NotFound)?,
        1 => return Err(io::ErrorKind::NotFound)?,
    // Incorrect suggestion for both of above:
    //    => return Err(io::ErrorKind::NotFound.into()),
    // Possible replacement:
        3 => return Poll::Ready(Some(Err(io::ErrorKind::NotFound.into()))),
        _ => {},
    }
    Poll::Ready(None)
}

Additionally, given overall verbosity of replacement code, it is far from clear that replacing ? is an improvement in this case.

@tmiasko tmiasko added the C-bug Category: Clippy is not doing the correct thing label Aug 2, 2020
@tmiasko tmiasko changed the title try_err false positive with Poll return type try_err false positive / incorrect suggestion with Poll return type Aug 2, 2020
@flip1995 flip1995 added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Aug 2, 2020
@bors bors closed this as completed in 3d7e3fd Aug 5, 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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants