Skip to content

Instantly share code, notes, and snippets.

View bstrie's full-sized avatar

bstrie bstrie

View GitHub Profile
fn main() {
let bar = result_err();
match bar {
Ok(foo) => io::println(fmt!("Success: %?", foo)),
Err(foo) => fail foo.to_str()
}
}
fn result_ok() -> Result<int, int> {
@bstrie
bstrie / After
Created November 9, 2012 20:15
Drop trait
struct PoisonOnFail {
failed: &mut bool,
}
impl PoisonOnFail : Drop {
fn finalize() {
/* assert !*self.failed; -- might be false in case of cond.wait() */
if task::failing() { *self.failed = true; }
}
}
@bstrie
bstrie / 1
Created November 12, 2012 21:10
Rust Drop trait crash
compile_and_link: x86_64-unknown-linux-gnu/stage1/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so
*** glibc detected *** x86_64-unknown-linux-gnu/stage1/bin/rustc: double free or corruption (fasttop): 0x00002aeac680b660 ***
*** glibc detected *** x86_64-unknown-linux-gnu/stage1/bin/rustc: double free or corruption (fasttop): 0x00002aeab81010a0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x2aeab585cb96]
======= Backtrace: =========
/media/linhaus/rust/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt.so(upcall_exchange_free+0x190)[0x2aeab55866d0]
/media/linhaus/rust/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt.so(+0x2d2b9)[0x2aeab55972b9]
/media/linhaus/rust/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc-c84825241471686d-0.5.so(+0x6c67dc)[0x2aeab517c7dc]
/media/linhaus/rust/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc-c84825241471686d-0.5.so(_ZN7monitor16_15559bd12ca78183_05E+0x1bee)[0x2aeab51792de]
error: auxiliary build of /media/linhaus/rust/src/test/auxiliary/cci_class_4.rs failed to compile:
command: x86_64-unknown-linux-gnu/stage2/bin/rustc /media/linhaus/rust/src/test/auxiliary/cci_class_4.rs -o x86_64-unknown-linux-gnu/test/run-pass/classes-cross-crate.libaux/cci_class_4 -L x86_64-unknown-linux-gnu/test/run-pass --lib -L x86_64-unknown-linux-gnu/test/run-pass/classes-cross-crate.libaux -O --target=x86_64-unknown-linux-gnu
stdout:
------------------------------------------
------------------------------------------
stderr:
------------------------------------------
/media/linhaus/rust/src/test/auxiliary/cci_class_4.rs:43:18: 43:25 warning: implicitly copying a non-implicitly-copyable value
/media/linhaus/rust/src/test/auxiliary/cci_class_4.rs:43 name: in_name
error: auxiliary build of /media/linhaus/rust/src/test/auxiliary/cci_class_4.rs failed to compile:
command: x86_64-unknown-linux-gnu/stage2/bin/rustc /media/linhaus/rust/src/test/auxiliary/cci_class_4.rs -o x86_64-unknown-linux-gnu/test/run-pass/classes-cross-crate.libaux/cci_class_4 -L x86_64-unknown-linux-gnu/test/run-pass --lib -L x86_64-unknown-linux-gnu/test/run-pass/classes-cross-crate.libaux -O --target=x86_64-unknown-linux-gnu
stdout:
------------------------------------------
------------------------------------------
stderr:
------------------------------------------
/media/linhaus/rust/src/test/auxiliary/cci_class_4.rs:43:18: 43:25 warning: implicitly copying a non-implicitly-copyable value
/media/linhaus/rust/src/test/auxiliary/cci_class_4.rs:43 name: in_name
extern mod rust_lua;
extern mod rust_lualib;
extern mod rust_lauxlib;
use rust_lua::*;
use rust_lualib::*;
use rust_lauxlib::*;
fn main() {
let L = luaL_newstate();
@bstrie
bstrie / Compiler error
Created November 15, 2012 20:25
Overloading + on Option
compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so
/media/linhaus/rust/src/libcore/option.rs:331:46: 331:48 error: mismatched types: expected `'a` but found `'b` (expected type parameter but found type parameter)
/media/linhaus/rust/src/libcore/option.rs:331 (Some(v1), Some(v2)) => Some(v1 + v2)
^~
/media/linhaus/rust/src/libcore/option.rs:331:36: 332:9 error: mismatched types: expected `option::Option<'b>` but found `option::Option<'a>` (expected type parameter but found type parameter)
/media/linhaus/rust/src/libcore/option.rs:331 (Some(v1), Some(v2)) => Some(v1 + v2)
/media/linhaus/rust/src/libcore/option.rs:332 }
error: aborting due to 2 previous errors
make: *** [x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so] Error 101
@bstrie
bstrie / gist:4081040
Created November 15, 2012 20:26
Rust error
compile_and_link: x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so
/media/linhaus/rust/src/libcore/option.rs:331:46: 331:48 error: mismatched types: expected `'a` but found `'b` (expected type parameter but found type parameter)
/media/linhaus/rust/src/libcore/option.rs:331 (Some(v1), Some(v2)) => Some(v1 + v2)
^~
/media/linhaus/rust/src/libcore/option.rs:331:36: 332:9 error: mismatched types: expected `option::Option<'b>` but found `option::Option<'a>` (expected type parameter but found type parameter)
/media/linhaus/rust/src/libcore/option.rs:331 (Some(v1), Some(v2)) => Some(v1 + v2)
/media/linhaus/rust/src/libcore/option.rs:332 }
error: aborting due to 2 previous errors
make: *** [x86_64-unknown-linux-gnu/stage0/lib/rustc/x86_64-unknown-linux-gnu/lib/libcore.so] Error 101
impl<T: Copy Add<T,T>> Option<T> : Add<Option<T>, Option<T>> {
#[inline(always)]
pure fn add(other: &Option<T>) -> Option<T> {
match (self, *other) {
(None, None) => None,
(_, None) => self,
(None, _) => *other,
(Some(ref v1), Some(ref v2)) => Some(*v1 + *v2)
}
}
pub pure fn get_default_with<T>(def: T, f: fn() -> Option<T>) -> T {
match f() { Some(x) => move x, None => move def }
}