-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Documentation of Iterator flatten()
improvement
#82687
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
Comments
@rustbot label T-doc T-libs. |
I'm not sure I like clippy's suggestion, personally, but I think your suggested documentation is reasonable. I would also point out that mapping to |
I was also confused when I saw the suggestion. But once I realizing what is was doing it sounded in line with things like |
I encountered the same clippy warning when iterating over Results, and got perplexed. With the current state of documentation, I personally perceive the warning as suggestion to write obfuscated code hiding the fact that error checking is missing. Adding the documentation change suggested by @ralpha would make it much easier to realize what flatten() does. Maybe it might be made even more clear how it works if phrasing the first line something like this:
Me too am no longer new to Rust, and thought I had a proficient understanding of flatten() after having used it to unroll nested arrays. Likely I'll not be the last person to be surprised it can also be used to discard Err values. |
@rustbot claim |
…flatten_doc, r=cuviper Add example for iterator_flatten Adds an Example to iterator_flatten Fixes rust-lang#82687
While linting my code I came across
manual_flatten
which was triggered in my code.This suggests the change from:
Into:
Both are valid code with same result.
But the rust docs on
flatten()
does not state that this is expected behavior. Yes, this is stated here.But this was not strait forward (in my opinion) to find. It took me writing a whole bug report and looking a bunch of thing up to figure this out. (and I'm not even new to Rust anymore)
I would suggest adding some example code to make his explicit. Here is a suggestion:
(after the "Mapping and then flattening:
<code>...</code>
" section)(or something similar)
This makes both this behavior cleared, easier to find and exposes people to code like this so they are less surprised if clippy starts warning them.
It looks like this behavior might be more common in the future too.
rust-lang/rust-clippy#6061
rust-lang/rust-clippy#6676
The text was updated successfully, but these errors were encountered: