Closed
Description
I'm getting "An unknown error occurred" when trying to use a value that I got out of a match statement - when I set the thing being matched upon to None.
Here's the code to reproduce this:
struct Client {
option: Option<String>,
}
fn main() {
let mut client = Client {
option: Some("address".into_string())
};
let address = match client.option {
Some(v) => {
// This seems to make 'v' invalid, but still lets me use it
client.option = None;
v
},
None => return
};
println!("Cloning")
// This is where the error occurs
address.clone();
}
The output when running via cargo:
$ cargo run
Compiling test-irc v0.0.1 (file:///home/daboross/Projects/Rust/Learn/test-irc)
Running `target/test-irc`
Cloning
An unknown error occurred
To learn more, run the command again with --verbose.
The output when running via gdb:
Starting program: /home/daboross/Projects/Rust/test-irc/target/test-irc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Cloning
Program received signal SIGSEGV, Segmentation fault.
0x000055555555bf0e in ptr::write::h984757489268428869 ()
Here's a rust playpen share with the code in it: http://is.gd/GCa24t
This occurs when using the above code in the playpen, though here are my system details in case it matters:
$ rustc --version=verbose
rustc 0.13.0-nightly (fac5a0767 2014-11-26 22:37:06 +0000)
binary: rustc
commit-hash: fac5a07679cac21a580badc84b755b8df0f975cf
commit-date: 2014-11-26 22:37:06 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly
$ uname -a
Linux M14x 3.13.0-39-generic #66-Ubuntu SMP Tue Oct 28 13:30:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: elementary OS
Description: elementary OS Freya
Release: 0.3
Codename: freya