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

Procs do not capture mutability #11958

Closed
nickdesaulniers opened this issue Jan 31, 2014 · 6 comments · Fixed by #16253
Closed

Procs do not capture mutability #11958

nickdesaulniers opened this issue Jan 31, 2014 · 6 comments · Fixed by #16253

Comments

@nickdesaulniers
Copy link

As an extension of the work from #10617 & #11626 , a proc shouldn't have to shadow a variable to get the mutability. This shouldn't be necessary.

@nickdesaulniers
Copy link
Author

When I pull the shadowing out of the test, I'm seeing:
cannot assign to immutable captured outer variable in a heap closure which I think comes from loan checking within the borrow checker. Not certain how that string is built up. cc @nikomatsakis @alexcrichton

@nikomatsakis
Copy link
Contributor

Ultimately the cause of this error is the categorization created by mem_categorization, which categorizes copied upvars as immutable.

@nickdesaulniers
Copy link
Author

@nikomatsakis , ok trying to understand this. I'm guessing I'm getting warmer? Not sure what a "one shot stack closure" is.

@nikomatsakis
Copy link
Contributor

@nickdesaulniers the relevant line is here. A "one shot stack closure" is often called a "once closure" -- not currently really supported, though some code exists -- it's a closure that only executes once, but which is stored on the stack. In any case, a proc type is (somewhat hackishly) represented as a closure with a OwnedSigil right now in the code.

@nickdesaulniers
Copy link
Author

@nikomatsakis , I had changed the mutbl member to be upvar_cmt.mutbl.inherit() (moving the definition of upvar_cmt out above the conditional). Should I instead make the var_is_refd true for OwnedSigil cases?

@alexcrichton
Copy link
Member

As @huonw noted in #12260, this code seems like it should work

fn main() {
    let mut x = 1;
    proc() { x = 2 };
}
proc-mut.rs:3:14: 3:15 error: cannot assign to immutable captured outer variable in a heap closure
proc-mut.rs:3     proc() { x = 2 };
                           ^

bors added a commit that referenced this issue Aug 9, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 11, 2024
Do not suggest `[T; n]` instead of `vec![T; n]` if `T` is not `Copy`

changelog: [`useless_vec`]: do not suggest replacing `&vec![T; N]` by `&[T; N]` if `T` is not `Copy`

Fix rust-lang#11958
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

Successfully merging a pull request may close this issue.

3 participants