-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: add
#[must_use]
attributes to iterator adaptor structs.
It can be a little unintuitive that something like `v.iter().map(|x| println!("{}", x));` does nothing: the majority of the iterator adaptors are lazy and do not execute anything until something calls `next`, e.g. a `for` loop, `collect`, `fold`, etc. The majority of such errors can be seen by someone writing something like the above, i.e. just calling an iterator adaptor and doing nothing with it (and doing this is certainly useless), so we can co-opt the `must_use` lint, using the message functionality to give a hint to the reason why. Fixes #14666.
- Loading branch information
Showing
1 changed file
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27d18fb
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.
saw approval from alexcrichton
at huonw@27d18fb
27d18fb
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.
merging huonw/rust/must-use-iterators = 27d18fb into auto
27d18fb
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.
huonw/rust/must-use-iterators = 27d18fb merged ok, testing candidate = 6372915
27d18fb
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.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/261
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/262
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/261
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/262
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/264
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/265
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/264
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/270
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/265
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/264
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/267
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/265
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/265
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/266
27d18fb
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.
fast-forwarding master to auto = 6372915