Skip to content

Trying to iterate over &mut Iterator using a for loop, results in lifetime error #21655

Closed
@japaric

Description

@japaric

STR

fn test(it: &mut Iterator<Item=()>) {
    for _ in it {}
}

fn main() {}

Output

for.rs:2:14: 2:16 error: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
for.rs:2     for _ in it {}
                      ^~
for.rs:2:14: 2:16 error: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
for.rs:2     for _ in it {}
                      ^~
for.rs:2:14: 2:16 error: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
for.rs:2     for _ in it {}
                      ^~
for.rs:1:1: 3:2 help: consider using an explicit lifetime parameter as shown: fn test<'a>(it: &'a mut Iterator<Item = ()>)
for.rs:1 fn test(it: &mut Iterator<Item=()>) {
for.rs:2     for _ in it {}
for.rs:3 }
error: aborting due to 3 previous errors

Version

rustc 1.0.0-nightly (458a6a2f6 2015-01-25 21:20:37 +0000)

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions