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

Allow a message on #[must_use] & mark iterator adaptor structs with it #15561

Merged
merged 2 commits into from
Jul 10, 2014

Commits on Jul 9, 2014

  1. lint: extend #[must_use] to handle a message.

    Similar to the stability attributes, a type annotated with `#[must_use =
    "informative snippet"]` will print the normal warning message along with
    "informative snippet". This allows the type author to provide some
    guidance about why the type should be used.
    huonw committed Jul 9, 2014
    Configuration menu
    Copy the full SHA
    b9e35a1 View commit details
    Browse the repository at this point in the history
  2. 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 rust-lang#14666.
    huonw committed Jul 9, 2014
    5 Configuration menu
    Copy the full SHA
    27d18fb View commit details
    Browse the repository at this point in the history