Skip to content

Danger with stack-allocated structs/initializer syntax #9259

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alexcrichton opened this issue Sep 17, 2013 · 2 comments · Fixed by #11606
Closed

Danger with stack-allocated structs/initializer syntax #9259

alexcrichton opened this issue Sep 17, 2013 · 2 comments · Fixed by #11606
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority
Milestone

Comments

@alexcrichton
Copy link
Member

This code produces some disturbing results:

struct A<'self> {                                  
    a: &'self [~str],                              
    b: Option<&'self [~str]>,                      
}                                                  

fn main() {                                        
    let b = Some(&[~"foo"]);                       
    let a = A {                                    
        a: [~"test"],                              
        b: b,                                      
    };                                             
    assert_eq!(a.b.get_ref()[0].as_slice(), "foo");
}                                                  
$ rust run bar.rs
warning: no debug symbols in executable (-arch x86_64)
task <unnamed> failed at 'assertion failed: `(left == right) && (right == left)` (left: `"test"`, right: `"foo"`)', bar.rs:12

Somehow the string ~"foo" is getting overwritten with ~"test"...

@alexcrichton
Copy link
Member Author

Nominating for production ready (this is a codegen bug)

@catamorphism
Copy link
Contributor

1.0, high

bors added a commit that referenced this issue Jan 18, 2014
This must have been fixed in some recent trans refactor/rewrite, hurray!

Closes #9259
Jarcho pushed a commit to Jarcho/rust that referenced this issue Aug 29, 2022
Fix `to_string_in_format_args` false positive

Fix rust-lang#9256

changelog: none
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. P-medium Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants