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

map_flatten does not cover Result.map #7496

Closed
Dionysusnu opened this issue Jul 26, 2021 · 3 comments · Fixed by #7522
Closed

map_flatten does not cover Result.map #7496

Dionysusnu opened this issue Jul 26, 2021 · 3 comments · Fixed by #7522
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@Dionysusnu
Copy link

Dionysusnu commented Jul 26, 2021

Lint name: map_flatten

I tried this code:

let a: Result<&str, ParseIntError> = Ok("1");
let c: i32 = a.map(|b| b.parse()).flatten().unwrap();

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=3c1eced0e47dac7f563945134ddc3bc8

I expected to see this happen:

This should fall under lint rule map_flatten.
The lint should advise the user to use andThen, instead of the .map(..).flatten()

Instead, this happened:

Result is not currently covered by the lint rule.
However, it is nearly the same as Option's map_flatten, and therefore makes sense to be included.

Meta

  • cargo clippy -V: e.g. clippy 0.1.53 (53cb7b09 2021-06-17)
    -- Although I did run rustup update, I'm not sure if this is the latest dev version, but the lint rule doesn't seem to have changed in any recent versions.
  • rustc -Vv:
rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-pc-windows-msvc
release: 1.53.0
LLVM version: 12.0.1
@Dionysusnu Dionysusnu added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Jul 26, 2021
@Dionysusnu
Copy link
Author

First issue here, still relatively new to Rust. Sorry if this is bad/wrong, please tell me if so.

@xFrednet
Copy link
Member

This is the right place to report this. It was probably not implemented as flatten for results is still behind a feature flag. I've created a second playground that doesn't use the parse method: playground. Thank you for providing an example, that was very helpful! 🙃

The implementation has to check that the wrapped error types are the same and that the feature result_flattening is enabled.

@camsteffen
Copy link
Contributor

camsteffen commented Jul 26, 2021

The implementation has to check that the wrapped error types are the same and that the feature result_flattening is enabled.

We already know those things are true if flatten compiled!

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-false-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants