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

Mutable borrow of unit-like struct is a weird edge case #11267

Closed
comex opened this issue Jan 2, 2014 · 3 comments
Closed

Mutable borrow of unit-like struct is a weird edge case #11267

comex opened this issue Jan 2, 2014 · 3 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@comex
Copy link
Contributor

comex commented Jan 2, 2014

// We need a mutable borrow to an empty struct because it implements a trait
// that takes &mut self.
struct Empty;
impl Iterator<int> for Empty {
    fn next(&mut self) -> Option<int> { None }
}

fn do_something_with(a : &mut Iterator<int>) {
    println!("{}", a.next())
}

fn main() {
    // This is OK...
    let mut a = Empty;
    do_something_with(&mut a);
    // But if I want to use an immediate expression, as is possible with
    // non-empty structs...
    // "error: cannot borrow immutable static item as mutable"
    do_something_with(&mut Empty);
}

It seems like it would make sense to allow mutably borrowing the Empty singleton.

@glaebhoerl
Copy link
Contributor

Seems related to #10800, possibly a dupe.

@dmski
Copy link
Contributor

dmski commented Mar 12, 2014

No longer reproduces with master for me.
cc #11681

@alexcrichton
Copy link
Member

Flagging as needstest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants