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

Illegal mutable borrow incorrectly allowed #14036

Closed
samyatchmenoff opened this issue May 8, 2014 · 4 comments · Fixed by #15190
Closed

Illegal mutable borrow incorrectly allowed #14036

samyatchmenoff opened this issue May 8, 2014 · 4 comments · Fixed by #15190
Milestone

Comments

@samyatchmenoff
Copy link

Example:

fn main() {
    let mut x = Some(~1);
    let mut p: proc(&mut Option<~int>) = proc(_) {};
    match x {
        Some(ref y) => {
            p = proc(z: &mut Option<~int>) {
                *z = None;
                println!("{}", y);
            }
        }
        None => {}
    }
    p(&mut x);
}

The last statement p(&mut x) is mutably borrowing x but x is already borrowed (or rather should be) by the proc.

The result is a program that compiles fine but segfaults when run.

@alexcrichton
Copy link
Member

cc @nikomatsakis

Nominating, closure shouldn't be able to capture borrowed variables.

@nikomatsakis
Copy link
Contributor

I'm pretty sure the proc "code" needs a thorough review, giving this issue along with all the other similar proc bugs.

@flaper87
Copy link
Contributor

flaper87 commented May 8, 2014

cc @flaper87

@brson brson added this to the 1.0 milestone May 8, 2014
@brson
Copy link
Contributor

brson commented May 8, 2014

P-backcompat-lang, 1.0.

pcwalton added a commit to pcwalton/rust that referenced this issue Jun 26, 2014
Since procs do not have lifetime bounds, we must do this to maintain
safety.

This can break code that incorrectly captured references in procedure
types. Change such code to not do this, perhaps with a trait object
instead.

A better solution would be to add higher-rank lifetime support to procs.
However, this would be a lot of work for a feature we want to remove in
favor of unboxed closures. The corresponding "real fix" is rust-lang#15067.

Closes rust-lang#14036.

[breaking-change]
bors added a commit that referenced this issue Jun 26, 2014
Since procs do not have lifetime bounds, we must do this to maintain
safety.

This can break code that incorrectly captured references in procedure
types. Change such code to not do this, perhaps with a trait object
instead.

Closes #14036.

[breaking-change]

r? @alexcrichton
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
…ykril

Record method resolution for remaining operator expressions

This allows goto def and future substituted hover to work for the concrete impls.
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.

5 participants