Skip to content

Instantly share code, notes, and snippets.

resource rsrc(_x: ()) {
#error["Hello, world!"];
}
fn hide_rsrc() -> fn@() {
let r = @rsrc(());
ret fn@[move r]() { #error["You got me."]; };
}
fn do_not_pass_go() { fail; }
fn unwrap<T, U>(-res: result<T, U>) -> T unsafe {
let addr = alt res {
ok(x) { ptr::addr_of(x) }
err(_) { fail "option none" }
};
let liberated_value = unsafe::reinterpret_cast(*addr);
unsafe::forget(res);
ret liberated_value;
}
rust-try:
#!/bin/bash
git diff --quiet HEAD
if [[ "$?" != "0" ]]; then
echo "Cannot push to master with uncommited changes."
exit 1
fi
git push -f mozilla HEAD:try
diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs
index 069fc7f..b071e25 100644
--- a/src/rustc/middle/typeck/check.rs
+++ b/src/rustc/middle/typeck/check.rs
@@ -66,9 +66,8 @@ type parameter).
*/
-import astconv::{ast_conv, region_scope, empty_rscope, ast_ty_to_ty,
- in_anon_rscope};
// xfail-fast (compile-flags unsupported on windows)
// compile-flags:--borrowck=err
// exec-env:RUST_POISON_ON_FREE=1
fn main() {
let x: @mut @option<~int> = @mut @none;
alt x {
@@some(y) {
// here, the refcount of `*x` is bumped so
// `y` remains valid even if `*x` is modified.
fn ok(r: &r.uint, f: fn@(x: &uint))
{
let mut g = fn@(x: &r.uint) {
};
g = f;
}
fn not_ok(r: &r.uint, s: &s.uint)
{
let mut g: fn@(x: &uint) = fn@(x: &r.uint) {
import comm::{port, chan, methods};
use std;
import std::arc;
enum e<T: send> { e(arc::arc<T>) }
resource r(x : e<arc::arc<int>>) {
}
fn foo() -> r {fail;}
fn main() {
let x = {mut f: 3};
let y = [x];
let z = y[0];
let f = fn@() {
x.f = 4;
};
f();
# BAD CASE
Unoptimized:
```
%15 = bitcast %"enum parse::token::token[#0]"* %3 to { i64, i8 }*
%16 = getelementptr inbounds { i64, i8 }* %15, i32 0, i32 0
%17 = load i64* %16
switch i64 %17, label %match_else28672 [
i64 35, label %match_case28673

Map API

iface map<K, V: copy> {
    fn size() -> uint;
    fn insert(K, V) -> bool;
    fn contains_key(^K) -> bool;
    fn get(^K) -> V;
    fn find(^K) -> option<V>;
 fn remove(^K) -&gt; option;