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

For loop iteration allows mutating container. #16898

Closed
krdln opened this issue Aug 31, 2014 · 3 comments
Closed

For loop iteration allows mutating container. #16898

krdln opened this issue Aug 31, 2014 · 3 comments

Comments

@krdln
Copy link
Contributor

krdln commented Aug 31, 2014

Following code passes borrow checking leading to serious memory unsafety.

fn main() {
    let mut v = Vec::new();
    for _ in v.iter() {
        v.push('j');
    }
}

Code compiles with &c instead of _ too. Loop fails to compile only in for c in v.iter() case where there's an explicit variable with reference or when the loop is desugared manually.

@huonw
Copy link
Member

huonw commented Aug 31, 2014

cc @pcwalton, nominating.

@ghost
Copy link

ghost commented Aug 31, 2014

Duplicate of #16820.

@huonw
Copy link
Member

huonw commented Aug 31, 2014

Thanks (both @jakub- and @krdln).

@huonw huonw closed this as completed Aug 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants