-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add #[must_use] message to Iterator and Future #57549
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Centril (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libcore/iter/iterator.rs
Outdated
@@ -88,7 +88,7 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {} | |||
message="`{Self}` is not an iterator" | |||
)] | |||
#[doc(spotlight)] | |||
#[must_use] | |||
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing docs use "iterator adapter", so I think we want to use that spelling instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that "iterator adaptors" is used as #[must_use] message: https://github.com/rust-lang/rust/blob/master/src/libcore/iter/mod.rs#L407
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, that one should probably be changed too, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Rust code on GitHub, iterator adaptors seems to be used more than iterator adapter.
IMO, this should probably be handled by another PR that like "Unify the name of the iterator adapter".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is to just drop "adaptors" in favor of "iterators are lazy and do...", since it's more direct. It seems preferable to unify everything, in whichever direction we move, in this PR.
I believe you missed:
In Since this now drops "adaptors" from the message as I suggested I'd like to get a second opinion on this change. (It is true that not all iterators are necessarily lazy since constructing them can perform work, but that's a level of detail that I think is missing the forest for the trees...) r? @estebank |
@bors r+ rollup |
📌 Commit da933cc has been approved by |
Add #[must_use] message to Iterator and Future ~~Iterator's message is based on current iterator adaptor's #[must_use] message (added in rust-lang#15561) and https://github.com/rust-lang/rust/pull/56677/files#r241236020~~ Future's message is the same as those used in [futures-rs](https://github.com/rust-lang-nursery/futures-rs/search?q=must_use&unscoped_q=must_use) and [tokio](https://github.com/tokio-rs/tokio/search?q=must_use&unscoped_q=must_use). r? @Centril
Rollup of 4 pull requests Successful merges: - #57004 (Make `TokenStream` less recursive.) - #57102 (NLL: Add union justifications to conflicting borrows.) - #57337 (rustc: Place wasm linker args first instead of last) - #57549 (Add #[must_use] message to Iterator and Future) Failed merges: r? @ghost
Add #[must_use] message to Fn* traits This PR adds `#[must_use]` message to `Fn*` traits. Related: rust-lang#57549 r? @estebank
Add #[must_use] message to Fn* traits This PR adds `#[must_use]` message to `Fn*` traits. Related: rust-lang#57549 r? @estebank
Add #[must_use] message to Fn* traits This PR adds `#[must_use]` message to `Fn*` traits. Related: rust-lang#57549 r? @estebank
Add #[must_use] message to Fn* traits This PR adds `#[must_use]` message to `Fn*` traits. Related: rust-lang#57549 r? @estebank
Iterator's message is based on current iterator adaptor's #[must_use] message (added in #15561) and https://github.com/rust-lang/rust/pull/56677/files#r241236020Future's message is the same as those used in futures-rs and tokio.
r? @Centril