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

Stack Closure Owned Pointer Reference Crash #6762

Closed
simonjlewis opened this issue May 27, 2013 · 4 comments
Closed

Stack Closure Owned Pointer Reference Crash #6762

simonjlewis opened this issue May 27, 2013 · 4 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@simonjlewis
Copy link

Creating a stack closure which references an owned pointer and then transferring ownership of the owned box before invoking the stack closure results in a crash.

For example, in Rust 0.6, this will compile

fn twice(x: ~uint) -> uint
{
     *x * 2
}

fn invoke(f : &fn() -> uint)
{
     f();
}

fn main()
{
      let x  : ~uint         = ~9;
      let sq : &fn() -> uint = || { *x * *x };

      twice(x);
      invoke(sq);
}

and the resulting program will then crash with a SEGV

@jdm
Copy link
Contributor

jdm commented May 27, 2013

Does it still crash on the incoming branch?

@lkuper
Copy link
Contributor

lkuper commented May 27, 2013

It dumps core for me, on incoming:

lkuper@lenny:~/repos/rust$ x86_64-unknown-linux-gnu/stage2/bin/rustc /home/lkuper/repos/rust/src/test/compile-fail/issue-6762.rs -o x86_64-unknown-linux-gnu/test/compile-fail/issue-6762.stage2-x86_64-unknown-linux-gnu -L x86_64-unknown-linux-gnu/test/compile-fail -L x86_64-unknown-linux-gnu/test/compile-fail/issue-6762.libaux --target=x86_64-unknown-linux-gnu
lkuper@lenny:~/repos/rust$ x86_64-unknown-linux-gnu/test/compile-fail/issue-6762.stage2-x86_64-unknown-linux-gnu 
Segmentation fault (core dumped)
lkuper@lenny:~/repos/rust$ 

Adding an xfailed test. We want this to fail compilation, I guess.

lkuper added a commit to lkuper/rust that referenced this issue May 27, 2013
@bblum
Copy link
Contributor

bblum commented May 29, 2013

This bug could be fixed by the proposed solution in this post: http://smallcultfollowing.com/babysteps/blog/2013/04/30/the-case-of-the-recurring-closure/ (namely, bullet 1, not 2)

@nikomatsakis
Copy link
Contributor

Dup of #2202 and more specifically #6801.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 16, 2022
…r=llogiq

improve [`for_loops_over_fallibles`] to detect the usage of iter, iter_mut and into_iterator

fix rust-lang#6762

detects code like
```rust
for _ in option.iter() {
    //..
}
```

changelog: Improve [`for_loops_over_fallibles`] to detect `for _ in option.iter() {}` or using `iter_mut()` or `into_iterator()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

5 participants