Created
December 4, 2013 13:23
-
-
Save Blei/7787352 to your computer and use it in GitHub Desktop.
wtf, rust?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Config.rs:34 | |
fn save_PrettyJSON<'a, T: Encodable<json::PrettyEncoder<'a>>>(p: &Path, toEncode: ~[T]) { | |
match File::create(p) { | |
Some(f) => { | |
let f2 = @mut f as @mut io::Writer; | |
let a = &mut json::PrettyEncoder::init(f2); | |
toEncode.encode(a); | |
}, None => fail!("failed to save json") | |
}; | |
} |
// DOESN'T work:
fn save_PrettyJSON<'a, T: Encodable<json::PrettyEncoder<'a>>>(p: &Path, toEncode: ~[T]) {
match File::create(p) {
Some(f) => {
let mut f2 = f;
let a = &mut json::PrettyEncoder::init(
@mut f2 as @mut io::Writer);
toEncode.encode(a);
}, None => fail!("failed to save json")
};
}
// WORKS:
fn save_PrettyJSON<'a, T: Encodable<json::PrettyEncoder<'a>>>(p: &Path, toEncode: ~[T]) {
match File::create(p) {
Some(f) => {
let mut f2 = f;
let a = &mut json::PrettyEncoder::init(
&mut f2 as &mut io::Writer);
toEncode.encode(a);
}, None => fail!("failed to save json")
};
}
(gdb) thread apply all bt
Thread 9 (Thread 0x7ffff4efb700 (LWP 16244)):
#0 0x00007ffff74bc03f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1 0x0000000000576f69 in uv_cond_wait (cond=cond@entry=0xf1e6e0 <cond>,
mutex=mutex@entry=0xf1e6a0 <mutex>) at ../../../src/libuv/src/unix/thread.c:324
#2 0x0000000000577183 in worker (arg=arg@entry=0x0) at ../../../src/libuv/src/unix/threadpool.c:56
#3 0x00000000005792e7 in uv__thread_start (arg=<optimized out>)
at ../../../src/libuv/src/uv-common.c:274
#4 0x00007ffff74b80a2 in start_thread () from /usr/lib/libpthread.so.0
#5 0x00007ffff6cd049d in clone () from /usr/lib/libc.so.6
Thread 8 (Thread 0x7ffff56fc700 (LWP 16243)):
#0 0x00007ffff74bc03f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1 0x0000000000576f69 in uv_cond_wait (cond=cond@entry=0xf1e6e0 <cond>,
mutex=mutex@entry=0xf1e6a0 <mutex>) at ../../../src/libuv/src/unix/thread.c:324
#2 0x0000000000577183 in worker (arg=arg@entry=0x0) at ../../../src/libuv/src/unix/threadpool.c:56
#3 0x00000000005792e7 in uv__thread_start (arg=<optimized out>)
at ../../../src/libuv/src/uv-common.c:274
#4 0x00007ffff74b80a2 in start_thread () from /usr/lib/libpthread.so.0
#5 0x00007ffff6cd049d in clone () from /usr/lib/libc.so.6
Thread 7 (Thread 0x7ffff5efd700 (LWP 16242)):
#0 0x00007ffff74bc03f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1 0x0000000000576f69 in uv_cond_wait (cond=cond@entry=0xf1e6e0 <cond>,
mutex=mutex@entry=0xf1e6a0 <mutex>) at ../../../src/libuv/src/unix/thread.c:324
---Type <return> to continue, or q <return> to quit---
#2 0x0000000000577183 in worker (arg=arg@entry=0x0) at ../../../src/libuv/src/unix/threadpool.c:56
#3 0x00000000005792e7 in uv__thread_start (arg=<optimized out>)
at ../../../src/libuv/src/uv-common.c:274
#4 0x00007ffff74b80a2 in start_thread () from /usr/lib/libpthread.so.0
#5 0x00007ffff6cd049d in clone () from /usr/lib/libc.so.6
Thread 6 (Thread 0x7ffff66fe700 (LWP 16241)):
#0 0x00007ffff74bc03f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
#1 0x0000000000576f69 in uv_cond_wait (cond=cond@entry=0xf1e6e0 <cond>,
mutex=mutex@entry=0xf1e6a0 <mutex>) at ../../../src/libuv/src/unix/thread.c:324
#2 0x0000000000577183 in worker (arg=arg@entry=0x0) at ../../../src/libuv/src/unix/threadpool.c:56
#3 0x00000000005792e7 in uv__thread_start (arg=<optimized out>)
at ../../../src/libuv/src/uv-common.c:274
#4 0x00007ffff74b80a2 in start_thread () from /usr/lib/libpthread.so.0
#5 0x00007ffff6cd049d in clone () from /usr/lib/libc.so.6
Thread 2 (Thread 0x7ffff7f49700 (LWP 16237)):
#0 0x00007ffff6ccc379 in syscall () from /usr/lib/libc.so.6
#1 0x0000000000571d9a in uv__epoll_wait (epfd=<optimized out>, events=events@entry=0x7ffff7f45b70,
nevents=nevents@entry=1024, timeout=timeout@entry=-1)
at ../../../src/libuv/src/unix/linux-syscalls.c:282
#2 0x000000000057066e in uv__io_poll (loop=loop@entry=0xf22010, timeout=-1)
at ../../../src/libuv/src/unix/linux-core.c:168
#3 0x000000000056bd27 in uv_run (loop=0xf22010, mode=UV_RUN_DEFAULT)
at ../../../src/libuv/src/unix/core.c:276
---Type <return> to continue, or q <return> to quit---
#4 0x000000000050b1a6 in rt::sched::Scheduler::run::h826c184529eecf45SAa3::v0.9$x2dpre ()
#5 0x000000000049eea2 in rt::sched::Scheduler::bootstrap::h19e397cb2dfd268SAat::v0.9$x2dpre ()
#6 0x00000000005226aa in rt::run_::anon::expr_fn::aH ()
#7 0x000000000049d745 in rt::thread::Thread::start::anon::expr_fn::Tfa8ad ()
#8 0x000000000050f574 in rt::thread::thread_start::h65f2b6e99a9c1b16aP::v0.9$x2dpre ()
#9 0x00007ffff74b80a2 in start_thread () from /usr/lib/libpthread.so.0
#10 0x00007ffff6cd049d in clone () from /usr/lib/libc.so.6
Thread 1 (Thread 0x7ffff7fbc740 (LWP 16233)):
#0 0x00007ffff74b94a2 in pthread_join () from /usr/lib/libpthread.so.0
#1 0x000000000049ba07 in rt::thread::native_thread_join::ha56a78a194f6e1b6a3::v0.9$x2dpre ()
#2 0x000000000049d264 in rt::thread::Thread::join::h42b183f056dbd22ZCaG::v0.9$x2dpre ()
#3 0x000000000052000c in rt::run_::he81a23d5f9cf1151aV::v0.9$x2dpre ()
#4 0x00000000004fcac2 in unstable::lang::start::h3f962587acaf2991a3::v0.9$x2dpre ()
#5 0x00007ffff6c0cbc5 in __libc_start_main () from /usr/lib/libc.so.6
#6 0x0000000000407471 in _start ()
(gdb)
#[feature(managed_boxes)];
struct Whatever<'a> { w: &'a mut std::io::Writer }
impl <'a> Whatever<'a> {
fn new<'b>(w: &'b mut std::io::Writer) -> Whatever<'b> {
Whatever { w: w }
}
}
fn save_PrettyJSON(p: &Path) {
match std::io::File::create(p) {
Some(f) => {
let mut f2 = f;
let a = &mut Whatever::new(@mut f2 as @mut std::io::Writer);
},
None => fail!()
};
}
fn main() {
save_PrettyJSON(&Path::init("sntahoeu"));
}
#[feature(managed_boxes)];
struct DroppableStruct;
impl Drop for DroppableStruct {
fn drop(&mut self) {
println!("Dropping");
}
}
trait MyTrait { }
impl MyTrait for DroppableStruct {}
struct Whatever<'a> { w: &'a mut MyTrait }
impl <'a> Whatever<'a> {
fn new<'b>(w: &'b mut MyTrait) -> Whatever<'b> {
Whatever { w: w }
}
}
fn main() {
let mut f = DroppableStruct;
let _a = &mut Whatever::new(@mut f as @mut MyTrait);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// This DOESN'T work
fn save_PrettyJSON<'a, T: Encodable<json::PrettyEncoder<'a>>>(p: &Path, toEncode: ~[T]) {
match File::create(p) {
Some(f) => {
let a = &mut json::PrettyEncoder::init(
@mut f as @mut io::Writer);
toEncode.encode(a);
}, None => fail!("failed to save json")
};
}