Skip to content

Delay of iteration side effects is confusing #14666

Closed
@kmcallister

Description

@kmcallister

This code produces no output:

fn main() {
    let xs = &[1u,2u,3u];
    let f = |x: &uint| {
        println!("{:u}", *x);
    };
    xs.iter().map(f);
}

It's because the iterator returned by map is never used. Switching to .map(f).last() produces the expected output.

Perhaps iterator structs should be #[must_use]?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions