diff --git a/RELEASES.txt b/RELEASES.txt index ec8d3ef6c0d..5da6314c4d1 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -1,3 +1,47 @@ +Version 0.3 (June 2012) - not yet! +----------------------------------- + + * ~1500 changes, numerous bugfixes + + * New coding conveniences + * Integer-literal suffix inference + * Per-module control over warnings, errors + * #[cfg(windows)] and #[cfg(unix)] attributes + + * Semantic cleanup + * Resolve pass and exhaustiveness checker rewritten + * Borrow-check taking over from alias-analysis + * Liveness taking over from last-use, typestate + * Extensive work on region pointers + + * Experimental new language features + * Slices and fixed-size, interior-allocated vectors + * #!-comments for lang versioning, shell execution + * More work on classes + * Type reflection + + * Removal of various obsolete features + * Keywords: be, prove, syntax, note, mutable, do, bind + * Constructs: do-while loops, fn binding, + + * Compiler reorganization + * Syntax-layer of compiler split into separate crate + * Clang (from LLVM project) integrated into build + * Typechecker split into sub-modules + + * New library code + * New time functions + * Extension methods for many built-in types + * Arc: atomic-refcount read-only / exclusive-use shared cells + * Par: parallel map and search routines + * Extensive work on libuv interface + * Much vector code moved to libraries + * Syntax extensions: #line, #col, #file, #mod, + #stringify, #include, #include_str, #include_bin. + + * Tool improvements + * Cargo automatically resolves dependencies + Version 0.2 (March 2012) ------------------------- diff --git a/src/libcore/box.rs b/src/libcore/box.rs index 28323f49ff0..881d736d2ba 100644 --- a/src/libcore/box.rs +++ b/src/libcore/box.rs @@ -2,9 +2,9 @@ export ptr_eq; -pure fn ptr_eq(a: @T, b: @T) -> bool unchecked { +pure fn ptr_eq(a: @T, b: @T) -> bool { #[doc = "Determine if two shared boxes point to the same object"]; - ptr::addr_of(*a) == ptr::addr_of(*b) + unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) } } #[test] diff --git a/src/libcore/char.rs b/src/libcore/char.rs index fdc44e02696..9aa1614114b 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -231,7 +231,7 @@ fn test_to_digit() { } #[test] -fn test_is_ascii() unsafe { +fn test_is_ascii() { assert str::all("banana", char::is_ascii); assert ! str::all("ประเทศไทย中华Việt Nam", char::is_ascii); } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 722c485d72e..8cc82e56b8f 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -210,13 +210,13 @@ fn recv_(p: *rust_port) -> T { ret res; } -fn peek_(p: *rust_port) -> bool unsafe { +fn peek_(p: *rust_port) -> bool { rustrt::rust_port_size(p) != 0u as libc::size_t } #[doc = "Receive on one of two ports"] fn select2(p_a: port, p_b: port) - -> either unsafe { + -> either { let ports = [(**p_a).po, (**p_b).po]; let n_ports = 2 as libc::size_t; let yield = 0u, yieldp = ptr::addr_of(yield); @@ -440,7 +440,7 @@ fn test_recv_chan_wrong_task() { let po = port(); let ch = chan(po); send(ch, "flower"); - assert result::is_failure(task::try {|| + assert result::is_err(task::try {|| recv_chan(ch) }) } diff --git a/src/libcore/core.rs b/src/libcore/core.rs index 2522a98609c..8b55a04ca48 100644 --- a/src/libcore/core.rs +++ b/src/libcore/core.rs @@ -11,6 +11,7 @@ import option::extensions; import option_iter::extensions; import ptr::extensions; import rand::extensions; +import result::extensions; export path, option, some, none, unreachable; export extensions; diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 144ea571d7c..175974f09cb 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -81,7 +81,7 @@ mod ct { enum piece { piece_string(str), piece_conv(conv), } type error_fn = fn@(str) -> ! ; - fn parse_fmt_string(s: str, error: error_fn) -> [piece] unsafe { + fn parse_fmt_string(s: str, error: error_fn) -> [piece] { let mut pieces: [piece] = []; let lim = str::len(s); let mut buf = ""; @@ -225,7 +225,7 @@ mod ct { } else { {count: count_implied, next: i} }; } fn parse_type(s: str, i: uint, lim: uint, error: error_fn) -> - {ty: ty, next: uint} unsafe { + {ty: ty, next: uint} { if i >= lim { error("missing type in conversion"); } let tstr = str::slice(s, i, i+1u); // TODO: Do we really want two signed types here? @@ -314,7 +314,7 @@ mod rt { let mut s = str::from_char(c); ret pad(cv, s, pad_nozero); } - fn conv_str(cv: conv, s: str) -> str unsafe { + fn conv_str(cv: conv, s: str) -> str { // For strings, precision is the maximum characters // displayed let mut unpadded = alt cv.precision { @@ -378,7 +378,7 @@ mod rt { }; } enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float } - fn pad(cv: conv, &s: str, mode: pad_mode) -> str unsafe { + fn pad(cv: conv, &s: str, mode: pad_mode) -> str { let uwidth : uint = alt cv.width { count_implied { ret s; } count_is(width) { diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 1ee91495c57..f1017488ee7 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -93,10 +93,10 @@ fn parse_buf(buf: [u8], radix: uint) -> option { fn from_str(s: str) -> option { parse_buf(str::bytes(s), 10u) } #[doc = "Convert to a string in a given base"] -fn to_str(n: T, radix: uint) -> str unsafe { +fn to_str(n: T, radix: uint) -> str { to_str_bytes(n, radix) {|slice| vec::unpack_slice(slice) {|p, len| - str::unsafe::from_buf_len(p, len) + unsafe { str::unsafe::from_buf_len(p, len) } } } } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index df1cf16781d..5fda13bcd70 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -192,13 +192,13 @@ fn convert_whence(whence: seek_style) -> i32 { } impl of reader for *libc::FILE { - fn read_bytes(len: uint) -> [u8] unsafe { + fn read_bytes(len: uint) -> [u8] { let mut buf : [mut u8] = [mut]; vec::reserve(buf, len); vec::as_mut_buf(buf) {|b| let read = libc::fread(b as *mut c_void, 1u as size_t, len as size_t, self); - vec::unsafe::set_len(buf, read as uint); + unsafe { vec::unsafe::set_len(buf, read as uint) }; } ret vec::from_mut(buf); } @@ -333,7 +333,7 @@ impl of writer for {base: T, cleanup: C} { } impl of writer for *libc::FILE { - fn write(v: [const u8]/&) unsafe { + fn write(v: [const u8]/&) { vec::unpack_const_slice(v) {|vbuf, len| let nout = libc::fwrite(vbuf as *c_void, len as size_t, 1u as size_t, self); @@ -361,7 +361,7 @@ fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer { } impl of writer for fd_t { - fn write(v: [const u8]/&) unsafe { + fn write(v: [const u8]/&) { let mut count = 0u; vec::unpack_const_slice(v) {|vbuf, len| while count < len { diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 72305906010..fe07198b422 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -70,7 +70,7 @@ pure fn iter(opt: option, f: fn(T)) { alt opt { none { } some(t) { f(t); } } } -pure fn unwrap(-opt: option) -> T unsafe { +pure fn unwrap(-opt: option) -> T { #[doc = " Moves a value out of an option type and returns it. @@ -78,13 +78,15 @@ pure fn unwrap(-opt: option) -> T unsafe { option types without copying them. "]; - let addr = alt opt { - some(x) { ptr::addr_of(x) } - none { fail "option none" } - }; - let liberated_value = unsafe::reinterpret_cast(*addr); - unsafe::forget(opt); - ret liberated_value; + unsafe { + let addr = alt opt { + some(x) { ptr::addr_of(x) } + none { fail "option none" } + }; + let liberated_value = unsafe::reinterpret_cast(*addr); + unsafe::forget(opt); + ret liberated_value; + } } impl extensions for option { diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 9ee7a80fcda..ee26bfc5496 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -180,19 +180,21 @@ mod global_env { } } - fn global_env_task(msg_po: comm::port) unsafe { - priv::weaken_task {|weak_po| - loop { - alt comm::select2(msg_po, weak_po) { - either::left(msg_getenv(n, resp_ch)) { - comm::send(resp_ch, impl::getenv(n)) - } - either::left(msg_setenv(n, v, resp_ch)) { - comm::send(resp_ch, impl::setenv(n, v)) - } - either::right(_) { - break; - } + fn global_env_task(msg_po: comm::port) { + unsafe { + priv::weaken_task {|weak_po| + loop { + alt comm::select2(msg_po, weak_po) { + either::left(msg_getenv(n, resp_ch)) { + comm::send(resp_ch, impl::getenv(n)) + } + either::left(msg_setenv(n, v, resp_ch)) { + comm::send(resp_ch, impl::setenv(n, v)) + } + either::right(_) { + break; + } + } } } } @@ -201,18 +203,20 @@ mod global_env { mod impl { #[cfg(unix)] - fn getenv(n: str) -> option unsafe { - let s = str::as_c_str(n, libc::getenv); - ret if unsafe::reinterpret_cast(s) == 0 { - option::none:: - } else { - let s = unsafe::reinterpret_cast(s); - option::some::(str::unsafe::from_buf(s)) - }; + fn getenv(n: str) -> option { + unsafe { + let s = str::as_c_str(n, libc::getenv); + ret if unsafe::reinterpret_cast(s) == 0 { + option::none:: + } else { + let s = unsafe::reinterpret_cast(s); + option::some::(str::unsafe::from_buf(s)) + }; + } } #[cfg(windows)] - fn getenv(n: str) -> option unsafe { + fn getenv(n: str) -> option { import libc::types::os::arch::extra::*; import libc::funcs::extra::kernel32::*; import win32::*; @@ -362,21 +366,23 @@ fn dll_filename(base: str) -> str { fn self_exe_path() -> option { #[cfg(target_os = "freebsd")] - fn load_self() -> option unsafe { - import libc::funcs::bsd44::*; - import libc::consts::os::extra::*; - fill_charp_buf() {|buf, sz| - let mib = [CTL_KERN as c_int, - KERN_PROC as c_int, - KERN_PROC_PATHNAME as c_int, -1 as c_int]; - sysctl(vec::unsafe::to_ptr(mib), vec::len(mib) as c_uint, - buf as *mut c_void, ptr::mut_addr_of(sz), - ptr::null(), 0u as size_t) == (0 as c_int) + fn load_self() -> option { + unsafe { + import libc::funcs::bsd44::*; + import libc::consts::os::extra::*; + fill_charp_buf() {|buf, sz| + let mib = [CTL_KERN as c_int, + KERN_PROC as c_int, + KERN_PROC_PATHNAME as c_int, -1 as c_int]; + sysctl(vec::unsafe::to_ptr(mib), vec::len(mib) as c_uint, + buf as *mut c_void, ptr::mut_addr_of(sz), + ptr::null(), 0u as size_t) == (0 as c_int) + } } } #[cfg(target_os = "linux")] - fn load_self() -> option unsafe { + fn load_self() -> option { import libc::funcs::posix01::unistd::readlink; fill_charp_buf() {|buf, sz| as_c_charp("/proc/self/exe") { |proc_self_buf| @@ -386,9 +392,10 @@ fn self_exe_path() -> option { } #[cfg(target_os = "macos")] - fn load_self() -> option unsafe { + fn load_self() -> option { // FIXME: remove imports when export globs work properly. #1238 import libc::funcs::extra::*; + fill_charp_buf() {|buf, sz| _NSGetExecutablePath(buf, ptr::mut_addr_of(sz as u32)) == (0 as c_int) @@ -396,7 +403,7 @@ fn self_exe_path() -> option { } #[cfg(windows)] - fn load_self() -> option unsafe { + fn load_self() -> option { // FIXME: remove imports when export globs work properly. #1238 import libc::types::os::arch::extra::*; import libc::funcs::extra::kernel32::*; @@ -525,14 +532,14 @@ fn make_dir(p: path, mode: c_int) -> bool { ret mkdir(p, mode); #[cfg(windows)] - fn mkdir(p: path, _mode: c_int) -> bool unsafe { + fn mkdir(p: path, _mode: c_int) -> bool { // FIXME: remove imports when export globs work properly. #1238 import libc::types::os::arch::extra::*; import libc::funcs::extra::kernel32::*; import win32::*; // FIXME: turn mode into something useful? #2623 as_utf16_p(p) {|buf| - CreateDirectoryW(buf, unsafe::reinterpret_cast(0)) + CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(0) }) != (0 as BOOL) } } @@ -645,7 +652,7 @@ fn copy_file(from: path, to: path) -> bool { } #[cfg(unix)] - fn do_copy_file(from: path, to: path) -> bool unsafe { + fn do_copy_file(from: path, to: path) -> bool { let istream = as_c_charp(from) {|fromp| as_c_charp("rb") {|modebuf| libc::fopen(fromp, modebuf) diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 560e4282411..93b32b6b8bd 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -105,14 +105,20 @@ Given paths `pre` and `post, removes any trailing path separator on `pre` and any leading path separator on `post`, and returns the concatenation of the two with a single path separator between them. "] -fn connect(pre: path, post: path) -> path unsafe { +fn connect(pre: path, post: path) -> path { let mut pre_ = pre; let mut post_ = post; let sep = consts::path_sep as u8; let pre_len = str::len(pre); let post_len = str::len(post); - if pre_len > 1u && pre[pre_len-1u] == sep { str::unsafe::pop_byte(pre_); } - if post_len > 1u && post[0] == sep { str::unsafe::shift_byte(post_); } + unsafe { + if pre_len > 1u && pre[pre_len-1u] == sep { + str::unsafe::pop_byte(pre_); + } + if post_len > 1u && post[0] == sep { + str::unsafe::shift_byte(post_); + } + } ret pre_ + path_sep() + post_; } diff --git a/src/libcore/priv.rs b/src/libcore/priv.rs index 922d7c72819..5b59496a488 100644 --- a/src/libcore/priv.rs +++ b/src/libcore/priv.rs @@ -82,7 +82,7 @@ unsafe fn chan_from_global_ptr( } #[test] -fn test_from_global_chan1() unsafe { +fn test_from_global_chan1() { // This is unreadable, right? @@ -91,11 +91,13 @@ fn test_from_global_chan1() unsafe { let globchanp = ptr::addr_of(globchan); // Create the global channel, attached to a new task - let ch = chan_from_global_ptr(globchanp, task::builder) {|po| - let ch = comm::recv(po); - comm::send(ch, true); - let ch = comm::recv(po); - comm::send(ch, true); + let ch = unsafe { + chan_from_global_ptr(globchanp, task::builder) {|po| + let ch = comm::recv(po); + comm::send(ch, true); + let ch = comm::recv(po); + comm::send(ch, true); + } }; // Talk to it let po = comm::port(); @@ -103,9 +105,11 @@ fn test_from_global_chan1() unsafe { assert comm::recv(po) == true; // This one just reuses the previous channel - let ch = chan_from_global_ptr(globchanp, task::builder) {|po| - let ch = comm::recv(po); - comm::send(ch, false); + let ch = unsafe { + chan_from_global_ptr(globchanp, task::builder) {|po| + let ch = comm::recv(po); + comm::send(ch, false); + } }; // Talk to the original global task @@ -115,7 +119,7 @@ fn test_from_global_chan1() unsafe { } #[test] -fn test_from_global_chan2() unsafe { +fn test_from_global_chan2() { iter::repeat(100u) {|| // The global channel @@ -129,12 +133,14 @@ fn test_from_global_chan2() unsafe { // create the global channel for uint::range(0u, 10u) {|i| task::spawn() {|| - let ch = chan_from_global_ptr( - globchanp, task::builder) {|po| + let ch = unsafe { + chan_from_global_ptr( + globchanp, task::builder) {|po| - for uint::range(0u, 10u) {|_j| - let ch = comm::recv(po); - comm::send(ch, {i}); + for uint::range(0u, 10u) {|_j| + let ch = comm::recv(po); + comm::send(ch, {i}); + } } }; let po = comm::port(); @@ -174,10 +180,12 @@ This function is super-unsafe. Do not use. * Weak tasks must not be supervised. A supervised task keeps a reference to its parent, so the parent will not die. "] -unsafe fn weaken_task(f: fn(comm::port<()>)) unsafe { +unsafe fn weaken_task(f: fn(comm::port<()>)) { let po = comm::port(); let ch = comm::chan(po); - rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch)); + unsafe { + rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch)); + } let _unweaken = unweaken(ch); f(po); @@ -191,50 +199,60 @@ unsafe fn weaken_task(f: fn(comm::port<()>)) unsafe { } #[test] -fn test_weaken_task_then_unweaken() unsafe { +fn test_weaken_task_then_unweaken() { task::try {|| - weaken_task {|_po| + unsafe { + weaken_task {|_po| + } } }; } #[test] -fn test_weaken_task_wait() unsafe { +fn test_weaken_task_wait() { let builder = task::builder(); task::unsupervise(builder); task::run(builder) {|| - weaken_task {|po| - comm::recv(po); - } - } -} - -#[test] -fn test_weaken_task_stress() unsafe { - // Create a bunch of weak tasks - iter::repeat(100u) {|| - task::spawn {|| - weaken_task {|_po| - } - } - let builder = task::builder(); - task::unsupervise(builder); - task::run(builder) {|| + unsafe { weaken_task {|po| - // Wait for it to tell us to die comm::recv(po); } } } } +#[test] +fn test_weaken_task_stress() { + // Create a bunch of weak tasks + iter::repeat(100u) {|| + task::spawn {|| + unsafe { + weaken_task {|_po| + } + } + } + let builder = task::builder(); + task::unsupervise(builder); + task::run(builder) {|| + unsafe { + weaken_task {|po| + // Wait for it to tell us to die + comm::recv(po); + } + } + } + } +} + #[test] #[ignore(cfg(windows))] -fn test_weaken_task_fail() unsafe { +fn test_weaken_task_fail() { let res = task::try {|| - weaken_task {|_po| - fail; + unsafe { + weaken_task {|_po| + fail; + } } }; - assert result::is_failure(res); + assert result::is_err(res); } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 2a89abc040f..d6288ea2126 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -39,20 +39,26 @@ pure fn addr_of(val: T) -> *T { unchecked { rusti::addr_of(val) } } #[doc = "Get an unsafe mut pointer to a value"] #[inline(always)] -pure fn mut_addr_of(val: T) -> *mut T unsafe { - unsafe::reinterpret_cast(rusti::addr_of(val)) +pure fn mut_addr_of(val: T) -> *mut T { + unsafe { + unsafe::reinterpret_cast(rusti::addr_of(val)) + } } #[doc = "Calculate the offset from a pointer"] #[inline(always)] -fn offset(ptr: *T, count: uint) -> *T unsafe { - (ptr as uint + count * sys::size_of::()) as *T +fn offset(ptr: *T, count: uint) -> *T { + unsafe { + (ptr as uint + count * sys::size_of::()) as *T + } } #[doc = "Calculate the offset from a const pointer"] #[inline(always)] -fn const_offset(ptr: *const T, count: uint) -> *const T unsafe { - (ptr as uint + count * sys::size_of::()) as *T +fn const_offset(ptr: *const T, count: uint) -> *const T { + unsafe { + (ptr as uint + count * sys::size_of::()) as *T + } } #[doc = "Calculate the offset from a mut pointer"] @@ -79,7 +85,7 @@ unsafe fn position(buf: *T, f: fn(T) -> bool) -> uint { #[doc = "Create an unsafe null pointer"] #[inline(always)] -pure fn null() -> *T unsafe { ret unsafe::reinterpret_cast(0u); } +pure fn null() -> *T { unsafe { unsafe::reinterpret_cast(0u) } } #[doc = "Returns true if the pointer is equal to the null pointer."] pure fn is_null(ptr: *const T) -> bool { ptr == null() } @@ -127,48 +133,52 @@ impl extensions for *T { } #[test] -fn test() unsafe { - type pair = {mut fst: int, mut snd: int}; - let p = {mut fst: 10, mut snd: 20}; - let pptr: *mut pair = mut_addr_of(p); - let iptr: *mut int = unsafe::reinterpret_cast(pptr); - assert (*iptr == 10);; - *iptr = 30; - assert (*iptr == 30); - assert (p.fst == 30);; +fn test() { + unsafe { + type pair = {mut fst: int, mut snd: int}; + let p = {mut fst: 10, mut snd: 20}; + let pptr: *mut pair = mut_addr_of(p); + let iptr: *mut int = unsafe::reinterpret_cast(pptr); + assert (*iptr == 10);; + *iptr = 30; + assert (*iptr == 30); + assert (p.fst == 30);; - *pptr = {mut fst: 50, mut snd: 60}; - assert (*iptr == 50); - assert (p.fst == 50); - assert (p.snd == 60); + *pptr = {mut fst: 50, mut snd: 60}; + assert (*iptr == 50); + assert (p.fst == 50); + assert (p.snd == 60); - let v0 = [32000u16, 32001u16, 32002u16]; - let v1 = [0u16, 0u16, 0u16]; + let v0 = [32000u16, 32001u16, 32002u16]; + let v1 = [0u16, 0u16, 0u16]; - ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 1u), - ptr::offset(vec::unsafe::to_ptr(v0), 1u), 1u); - assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16); - ptr::memcpy(vec::unsafe::to_ptr(v1), - ptr::offset(vec::unsafe::to_ptr(v0), 2u), 1u); - assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16); - ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 2u), - vec::unsafe::to_ptr(v0), 1u); - assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16); + ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 1u), + ptr::offset(vec::unsafe::to_ptr(v0), 1u), 1u); + assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16); + ptr::memcpy(vec::unsafe::to_ptr(v1), + ptr::offset(vec::unsafe::to_ptr(v0), 2u), 1u); + assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16); + ptr::memcpy(ptr::offset(vec::unsafe::to_ptr(v1), 2u), + vec::unsafe::to_ptr(v0), 1u); + assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16); + } } #[test] -fn test_position() unsafe { +fn test_position() { import str::as_c_str; import libc::c_char; let s = "hello"; - assert 2u == as_c_str(s) {|p| position(p) {|c| c == 'l' as c_char} }; - assert 4u == as_c_str(s) {|p| position(p) {|c| c == 'o' as c_char} }; - assert 5u == as_c_str(s) {|p| position(p) {|c| c == 0 as c_char } }; + unsafe { + assert 2u == as_c_str(s) {|p| position(p) {|c| c == 'l' as c_char} }; + assert 4u == as_c_str(s) {|p| position(p) {|c| c == 'o' as c_char} }; + assert 5u == as_c_str(s) {|p| position(p) {|c| c == 0 as c_char } }; + } } #[test] -fn test_buf_len() unsafe { +fn test_buf_len() { let s0 = "hello"; let s1 = "there"; let s2 = "thing"; @@ -177,7 +187,7 @@ fn test_buf_len() unsafe { str::as_c_str(s2) {|p2| let v = [p0, p1, p2, null()]; vec::as_buf(v) {|vp| - assert buf_len(vp) == 3u; + assert unsafe { buf_len(vp) } == 3u; } } } diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 3c6622ba69d..5c65971f2ea 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -43,16 +43,16 @@ pure fn get_err(res: result) -> U { } #[doc = "Returns true if the result is `ok`"] -pure fn is_success(res: result) -> bool { +pure fn is_ok(res: result) -> bool { alt res { ok(_) { true } err(_) { false } } } -#[doc = "Returns true if the result is `error`"] -pure fn is_failure(res: result) -> bool { - !is_success(res) +#[doc = "Returns true if the result is `err`"] +pure fn is_err(res: result) -> bool { + !is_ok(res) } #[doc = " @@ -180,22 +180,10 @@ fn map_err(res: result, op: fn(E) -> F) } } -impl extensions for result { - fn get() -> T { get(self) } +impl extensions for result { + fn is_ok() -> bool { is_ok(self) } - fn get_err() -> E { get_err(self) } - - fn is_success() -> bool { is_success(self) } - - fn is_failure() -> bool { is_failure(self) } - - fn chain(op: fn(T) -> result) -> result { - chain(self, op) - } - - fn chain_err(op: fn(E) -> result) -> result { - chain_err(self, op) - } + fn is_err() -> bool { is_err(self) } fn iter(f: fn(T)) { alt self { @@ -210,6 +198,21 @@ impl extensions for result { err(e) { f(e) } } } +} + +impl extensions for result { + fn get() -> T { get(self) } + + fn map_err(op: fn(E) -> F) -> result { + alt self { + ok(t) { ok(t) } + err(e) { err(op(e)) } + } + } +} + +impl extensions for result { + fn get_err() -> E { get_err(self) } fn map(op: fn(T) -> U) -> result { alt self { @@ -217,12 +220,15 @@ impl extensions for result { err(e) { err(e) } } } +} - fn map_err(op: fn(E) -> F) -> result { - alt self { - ok(t) { ok(t) } - err(e) { err(op(e)) } - } +impl extensions for result { + fn chain(op: fn(T) -> result) -> result { + chain(self, op) + } + + fn chain_err(op: fn(E) -> result) -> result { + chain_err(self, op) } } @@ -320,14 +326,16 @@ fn iter_vec2(ss: [S], ts: [T], #[doc=" Unwraps a result, assuming it is an `ok(T)` "] -fn unwrap(-res: result) -> T unsafe { - let addr = alt res { - ok(x) { ptr::addr_of(x) } - err(_) { fail "error result" } - }; - let liberated_value = unsafe::reinterpret_cast(*addr); - unsafe::forget(res); - ret liberated_value; +fn unwrap(-res: result) -> T { + unsafe { + let addr = alt res { + ok(x) { ptr::addr_of(x) } + err(_) { fail "error result" } + }; + let liberated_value = unsafe::reinterpret_cast(*addr); + unsafe::forget(res); + ret liberated_value; + } } #[cfg(test)] diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 4183056b741..beb314593ab 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -66,7 +66,7 @@ fn spawn_process(prog: str, args: [str], env: option<[(str,str)]>, dir: option, in_fd: c_int, out_fd: c_int, err_fd: c_int) - -> pid_t unsafe { + -> pid_t { with_argv(prog, args) {|argv| with_envp(env) { |envp| with_dirp(dir) { |dirp| @@ -78,7 +78,7 @@ fn spawn_process(prog: str, args: [str], } fn with_argv(prog: str, args: [str], - cb: fn(**libc::c_char) -> T) -> T unsafe { + cb: fn(**libc::c_char) -> T) -> T { let mut argptrs = str::as_c_str(prog) {|b| [b] }; let mut tmps = []; for vec::each(args) {|arg| @@ -92,7 +92,7 @@ fn with_argv(prog: str, args: [str], #[cfg(unix)] fn with_envp(env: option<[(str,str)]>, - cb: fn(*c_void) -> T) -> T unsafe { + cb: fn(*c_void) -> T) -> T { // On posixy systems we can pass a char** for envp, which is // a null-terminated array of "k=v\n" strings. alt env { @@ -107,7 +107,9 @@ fn with_envp(env: option<[(str,str)]>, ptrs += str::as_c_str(*t) {|b| [b]}; } ptrs += [ptr::null()]; - vec::as_buf(ptrs) { |p| cb(::unsafe::reinterpret_cast(p)) } + vec::as_buf(ptrs) { |p| + unsafe { cb(::unsafe::reinterpret_cast(p)) } + } } _ { cb(ptr::null()) @@ -117,31 +119,33 @@ fn with_envp(env: option<[(str,str)]>, #[cfg(windows)] fn with_envp(env: option<[(str,str)]>, - cb: fn(*c_void) -> T) -> T unsafe { + cb: fn(*c_void) -> T) -> T { // On win32 we pass an "environment block" which is not a char**, but // rather a concatenation of null-terminated k=v\0 sequences, with a final // \0 to terminate. - alt env { - some(es) if !vec::is_empty(es) { - let mut blk : [u8] = []; - for vec::each(es) {|e| - let (k,v) = e; - let t = #fmt("%s=%s", k, v); - let mut v : [u8] = ::unsafe::reinterpret_cast(t); - blk += v; - ::unsafe::forget(v); + unsafe { + alt env { + some(es) if !vec::is_empty(es) { + let mut blk : [u8] = []; + for vec::each(es) {|e| + let (k,v) = e; + let t = #fmt("%s=%s", k, v); + let mut v : [u8] = ::unsafe::reinterpret_cast(t); + blk += v; + ::unsafe::forget(v); + } + blk += [0_u8]; + vec::as_buf(blk) {|p| cb(::unsafe::reinterpret_cast(p)) } + } + _ { + cb(ptr::null()) + } } - blk += [0_u8]; - vec::as_buf(blk) {|p| cb(::unsafe::reinterpret_cast(p)) } - } - _ { - cb(ptr::null()) - } } } fn with_dirp(d: option, - cb: fn(*libc::c_char) -> T) -> T unsafe { + cb: fn(*libc::c_char) -> T) -> T { alt d { some(dir) { str::as_c_str(dir, cb) } none { cb(ptr::null()) } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index dbdd798033c..90138468fa8 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -122,9 +122,9 @@ Convert a vector of bytes to a UTF-8 string Fails if invalid UTF-8 "] -pure fn from_bytes(vv: [u8]) -> str unsafe { - assert is_utf8(vv); - ret unsafe::from_bytes(vv); +pure fn from_bytes(vv: [u8]) -> str { + assert is_utf8(vv); + ret unsafe { unsafe::from_bytes(vv) }; } #[doc = " @@ -134,83 +134,85 @@ Convert a byte to a UTF-8 string Fails if invalid UTF-8 "] -pure fn from_byte(b: u8) -> str unsafe { +pure fn from_byte(b: u8) -> str { assert b < 128u8; let mut v = [b, 0u8]; - ::unsafe::transmute(v) + unsafe { ::unsafe::transmute(v) } } #[doc = "Appends a character at the end of a string"] -fn push_char(&s: str, ch: char) unsafe { - let code = ch as uint; - let nb = if code < max_one_b { 1u } +fn push_char(&s: str, ch: char) { + unsafe { + let code = ch as uint; + let nb = if code < max_one_b { 1u } else if code < max_two_b { 2u } else if code < max_three_b { 3u } else if code < max_four_b { 4u } else if code < max_five_b { 5u } else { 6u }; - let len = len(s); - let new_len = len + nb; - reserve_at_least(s, new_len); - let off = len; - as_buf(s) {|buf| - let buf: *mut u8 = ::unsafe::reinterpret_cast(buf); - if nb == 1u { - *ptr::mut_offset(buf, off) = - code as u8; - } else if nb == 2u { - *ptr::mut_offset(buf, off) = - (code >> 6u & 31u | tag_two_b) as u8; - *ptr::mut_offset(buf, off + 1u) = - (code & 63u | tag_cont) as u8; - } else if nb == 3u { - *ptr::mut_offset(buf, off) = - (code >> 12u & 15u | tag_three_b) as u8; - *ptr::mut_offset(buf, off + 1u) = - (code >> 6u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 2u) = - (code & 63u | tag_cont) as u8; - } else if nb == 4u { - *ptr::mut_offset(buf, off) = - (code >> 18u & 7u | tag_four_b) as u8; - *ptr::mut_offset(buf, off + 1u) = - (code >> 12u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 2u) = - (code >> 6u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 3u) = - (code & 63u | tag_cont) as u8; - } else if nb == 5u { - *ptr::mut_offset(buf, off) = - (code >> 24u & 3u | tag_five_b) as u8; - *ptr::mut_offset(buf, off + 1u) = - (code >> 18u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 2u) = - (code >> 12u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 3u) = - (code >> 6u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 4u) = - (code & 63u | tag_cont) as u8; - } else if nb == 6u { - *ptr::mut_offset(buf, off) = - (code >> 30u & 1u | tag_six_b) as u8; - *ptr::mut_offset(buf, off + 1u) = - (code >> 24u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 2u) = - (code >> 18u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 3u) = - (code >> 12u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 4u) = - (code >> 6u & 63u | tag_cont) as u8; - *ptr::mut_offset(buf, off + 5u) = - (code & 63u | tag_cont) as u8; + let len = len(s); + let new_len = len + nb; + reserve_at_least(s, new_len); + let off = len; + as_buf(s) {|buf| + let buf: *mut u8 = ::unsafe::reinterpret_cast(buf); + if nb == 1u { + *ptr::mut_offset(buf, off) = + code as u8; + } else if nb == 2u { + *ptr::mut_offset(buf, off) = + (code >> 6u & 31u | tag_two_b) as u8; + *ptr::mut_offset(buf, off + 1u) = + (code & 63u | tag_cont) as u8; + } else if nb == 3u { + *ptr::mut_offset(buf, off) = + (code >> 12u & 15u | tag_three_b) as u8; + *ptr::mut_offset(buf, off + 1u) = + (code >> 6u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 2u) = + (code & 63u | tag_cont) as u8; + } else if nb == 4u { + *ptr::mut_offset(buf, off) = + (code >> 18u & 7u | tag_four_b) as u8; + *ptr::mut_offset(buf, off + 1u) = + (code >> 12u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 2u) = + (code >> 6u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 3u) = + (code & 63u | tag_cont) as u8; + } else if nb == 5u { + *ptr::mut_offset(buf, off) = + (code >> 24u & 3u | tag_five_b) as u8; + *ptr::mut_offset(buf, off + 1u) = + (code >> 18u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 2u) = + (code >> 12u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 3u) = + (code >> 6u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 4u) = + (code & 63u | tag_cont) as u8; + } else if nb == 6u { + *ptr::mut_offset(buf, off) = + (code >> 30u & 1u | tag_six_b) as u8; + *ptr::mut_offset(buf, off + 1u) = + (code >> 24u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 2u) = + (code >> 18u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 3u) = + (code >> 12u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 4u) = + (code >> 6u & 63u | tag_cont) as u8; + *ptr::mut_offset(buf, off + 5u) = + (code & 63u | tag_cont) as u8; + } + *ptr::mut_offset(buf, off + nb) = 0u8; } - *ptr::mut_offset(buf, off + nb) = 0u8; - } - as_bytes(s) {|bytes| - let mut mut_bytes: [u8] = ::unsafe::reinterpret_cast(bytes); - vec::unsafe::set_len(mut_bytes, new_len + 1u); - ::unsafe::forget(mut_bytes); + as_bytes(s) {|bytes| + let mut mut_bytes: [u8] = ::unsafe::reinterpret_cast(bytes); + vec::unsafe::set_len(mut_bytes, new_len + 1u); + ::unsafe::forget(mut_bytes); + } } } @@ -276,9 +278,9 @@ Remove the first character from a string and return it If the string does not contain any characters "] -fn shift_char(&s: str) -> char unsafe { +fn shift_char(&s: str) -> char { let {ch, next} = char_range_at(s, 0u); - s = unsafe::slice_bytes(s, next, len(s)); + s = unsafe { unsafe::slice_bytes(s, next, len(s)) }; ret ch; } @@ -320,20 +322,22 @@ Converts a string to a vector of bytes The result vector is not null-terminated. "] -pure fn bytes(s: str) -> [u8] unsafe { - let mut s_copy = s; - let mut v: [u8] = ::unsafe::transmute(s_copy); - vec::unsafe::set_len(v, len(s)); - ret v; +pure fn bytes(s: str) -> [u8] { + unsafe { + let mut s_copy = s; + let mut v: [u8] = ::unsafe::transmute(s_copy); + vec::unsafe::set_len(v, len(s)); + ret v; + } } #[doc = " Work with the string as a byte slice, not including trailing null. "] #[inline(always)] -pure fn byte_slice(s: str/&, f: fn([u8]/&) -> T) -> T unsafe { +pure fn byte_slice(s: str/&, f: fn([u8]/&) -> T) -> T { unpack_slice(s) {|p,n| - vec::unsafe::form_slice(p, n-1u, f) + unsafe { vec::unsafe::form_slice(p, n-1u, f) } } } @@ -365,10 +369,10 @@ Returns a slice of the given string from the byte range [`begin`..`end`) Fails when `begin` and `end` do not point to valid characters or beyond the last character of the string "] -pure fn slice(s: str/&, begin: uint, end: uint) -> str unsafe { +pure fn slice(s: str/&, begin: uint, end: uint) -> str { assert is_char_boundary(s, begin); assert is_char_boundary(s, end); - unsafe::slice_bytes(s, begin, end) + unsafe { unsafe::slice_bytes(s, begin, end) } } #[doc = " @@ -396,7 +400,7 @@ pure fn split_char_nonempty(s: str/&, sep: char) -> [str] { } pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) - -> [str] unsafe { + -> [str] { if sep < 128u as char { let b = sep as u8, l = len(s); let mut result = [], done = 0u; @@ -404,7 +408,7 @@ pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) while i < l && done < count { if s[i] == b { if allow_empty || start < i { - result += [unsafe::slice_bytes(s, start, i)]; + result += [unsafe { unsafe::slice_bytes(s, start, i) }]; } start = i + 1u; done += 1u; @@ -412,7 +416,7 @@ pure fn split_char_inner(s: str/&, sep: char, count: uint, allow_empty: bool) i += 1u; } if allow_empty || start < l { - result += [unsafe::slice_bytes(s, start, l)]; + result += [unsafe { unsafe::slice_bytes(s, start, l) }]; } result } else { @@ -440,14 +444,14 @@ pure fn split_nonempty(s: str/&, sepfn: fn(char) -> bool) -> [str] { } pure fn split_inner(s: str/&, sepfn: fn(cc: char) -> bool, count: uint, - allow_empty: bool) -> [str] unsafe { + allow_empty: bool) -> [str] { let l = len(s); let mut result = [], i = 0u, start = 0u, done = 0u; while i < l && done < count { let {ch, next} = char_range_at(s, i); if sepfn(ch) { if allow_empty || start < i { - result += [unsafe::slice_bytes(s, start, i)]; + result += [unsafe { unsafe::slice_bytes(s, start, i) }]; } start = next; done += 1u; @@ -455,7 +459,7 @@ pure fn split_inner(s: str/&, sepfn: fn(cc: char) -> bool, count: uint, i = next; } if allow_empty || start < l { - result += [unsafe::slice_bytes(s, start, l)]; + result += [unsafe { unsafe::slice_bytes(s, start, l) }]; } result } @@ -578,7 +582,7 @@ Replace all occurrences of one string with another The original string with all occurances of `from` replaced with `to` "] -pure fn replace(s: str, from: str, to: str) -> str unsafe { +pure fn replace(s: str, from: str, to: str) -> str { let mut result = "", first = true; iter_between_matches(s, from) {|start, end| if first { first = false; } else { result += to; } @@ -709,7 +713,7 @@ Apply a function to each substring after splitting by character, up to `count` times "] pure fn splitn_char_iter(ss: str/&, sep: char, count: uint, - ff: fn(&&str)) unsafe { + ff: fn(&&str)) { vec::iter(splitn_char(ss, sep, count), ff) } @@ -1149,7 +1153,7 @@ Returns true if one string starts with another * haystack - The string to look in * needle - The string to look for "] -pure fn starts_with(haystack: str/&a, needle: str/&b) -> bool unsafe { +pure fn starts_with(haystack: str/&a, needle: str/&b) -> bool { let haystack_len = len(haystack), needle_len = len(needle); if needle_len == 0u { true } else if needle_len > haystack_len { false } @@ -1564,9 +1568,11 @@ interop. let i = str::as_bytes(\"Hello World\") { |bytes| vec::len(bytes) }; ~~~ "] -pure fn as_bytes(s: str, f: fn([u8]) -> T) -> T unsafe { - let v: *[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s)); - f(*v) +pure fn as_bytes(s: str, f: fn([u8]) -> T) -> T { + unsafe { + let v: *[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s)); + f(*v) + } } #[doc = " @@ -1575,8 +1581,8 @@ Work with the byte buffer of a string. Allows for unsafe manipulation of strings, which is useful for native interop. "] -pure fn as_buf(s: str, f: fn(*u8) -> T) -> T unsafe { - as_bytes(s) { |v| vec::as_buf(v, f) } +pure fn as_buf(s: str, f: fn(*u8) -> T) -> T { + as_bytes(s) { |v| unsafe { vec::as_buf(v, f) } } } #[doc = " @@ -1591,7 +1597,7 @@ interop, without copying the original string. let s = str::as_buf(\"PATH\", { |path_buf| libc::getenv(path_buf) }); ~~~ "] -pure fn as_c_str(s: str, f: fn(*libc::c_char) -> T) -> T unsafe { +pure fn as_c_str(s: str, f: fn(*libc::c_char) -> T) -> T { as_buf(s) {|buf| f(buf as *libc::c_char) } } @@ -1605,10 +1611,12 @@ indexable area for a null byte, as is the case in slices pointing to full strings, or suffixes of them. "] #[inline(always)] -pure fn unpack_slice(s: str/&, f: fn(*u8, uint) -> T) -> T unsafe { - let v : *(*u8,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s)); - let (buf,len) = *v; - f(buf, len) +pure fn unpack_slice(s: str/&, f: fn(*u8, uint) -> T) -> T { + unsafe { + let v : *(*u8,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s)); + let (buf,len) = *v; + f(buf, len) + } } #[doc = " @@ -1653,7 +1661,7 @@ capacity, then no action is taken. * s - A string * n - The number of bytes to reserve space for "] -fn reserve_at_least(&s: str, n: uint) unsafe { +fn reserve_at_least(&s: str, n: uint) { reserve(s, uint::next_power_of_two(n + 1u) - 1u) } @@ -1661,7 +1669,7 @@ fn reserve_at_least(&s: str, n: uint) unsafe { Returns the number of single-byte characters the string can hold without reallocating "] -pure fn capacity(&&s: str) -> uint unsafe { +pure fn capacity(&&s: str) -> uint { as_bytes(s) {|buf| let vcap = vec::capacity(buf); assert vcap > 0u; @@ -1742,10 +1750,12 @@ mod unsafe { Does not verify that the vector contains valid UTF-8. "] - unsafe fn from_bytes(v: [const u8]) -> str unsafe { - let mut vcopy : [u8] = ::unsafe::transmute(copy v); - vec::push(vcopy, 0u8); - ::unsafe::transmute(vcopy) + unsafe fn from_bytes(v: [const u8]) -> str { + unsafe { + let mut vcopy : [u8] = ::unsafe::transmute(copy v); + vec::push(vcopy, 0u8); + ::unsafe::transmute(vcopy) + } } #[doc = " @@ -1765,20 +1775,22 @@ mod unsafe { If begin is greater than end. If end is greater than the length of the string. "] - unsafe fn slice_bytes(s: str/&, begin: uint, end: uint) -> str unsafe { + unsafe fn slice_bytes(s: str/&, begin: uint, end: uint) -> str { unpack_slice(s) { |sbuf, n| assert (begin <= end); assert (end <= n); let mut v = []; vec::reserve(v, end - begin + 1u); - vec::as_buf(v) { |vbuf| - let src = ptr::offset(sbuf, begin); - ptr::memcpy(vbuf, src, end - begin); + unsafe { + vec::as_buf(v) { |vbuf| + let src = ptr::offset(sbuf, begin); + ptr::memcpy(vbuf, src, end - begin); + } + vec::unsafe::set_len(v, end - begin); + v += [0u8]; + ::unsafe::transmute(v) } - vec::unsafe::set_len(v, end - begin); - v += [0u8]; - ::unsafe::transmute(v) } } @@ -1795,22 +1807,22 @@ mod unsafe { #[doc = " Removes the last byte from a string and returns it. (Not UTF-8 safe). "] - unsafe fn pop_byte(&s: str) -> u8 unsafe { + unsafe fn pop_byte(&s: str) -> u8 { let len = len(s); assert (len > 0u); let b = s[len - 1u]; - set_len(s, len - 1u); + unsafe { set_len(s, len - 1u) }; ret b; } #[doc = " Removes the first byte from a string and returns it. (Not UTF-8 safe). "] - unsafe fn shift_byte(&s: str) -> u8 unsafe { + unsafe fn shift_byte(&s: str) -> u8 { let len = len(s); assert (len > 0u); let b = s[0]; - s = unsafe::slice_bytes(s, 1u, len); + s = unsafe { unsafe::slice_bytes(s, 1u, len) }; ret b; } @@ -1825,11 +1837,13 @@ mod unsafe { } #[test] - fn test_from_buf_len() unsafe { - let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; - let b = vec::unsafe::to_ptr(a); - let c = from_buf_len(b, 3u); - assert (c == "AAA"); + fn test_from_buf_len() { + unsafe { + let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; + let b = vec::unsafe::to_ptr(a); + let c = from_buf_len(b, 3u); + assert (c == "AAA"); + } } } @@ -2274,24 +2288,27 @@ mod tests { } #[test] - fn test_unsafe_slice() unsafe { - assert (eq("ab", unsafe::slice_bytes("abc", 0u, 2u))); - assert (eq("bc", unsafe::slice_bytes("abc", 1u, 3u))); - assert (eq("", unsafe::slice_bytes("abc", 1u, 1u))); - fn a_million_letter_a() -> str { - let mut i = 0; - let mut rs = ""; - while i < 100000 { rs += "aaaaaaaaaa"; i += 1; } - ret rs; + fn test_unsafe_slice() { + unsafe { + assert (eq("ab", unsafe::slice_bytes("abc", 0u, 2u))); + assert (eq("bc", unsafe::slice_bytes("abc", 1u, 3u))); + assert (eq("", unsafe::slice_bytes("abc", 1u, 1u))); + fn a_million_letter_a() -> str { + let mut i = 0; + let mut rs = ""; + while i < 100000 { rs += "aaaaaaaaaa"; i += 1; } + ret rs; + } + fn half_a_million_letter_a() -> str { + let mut i = 0; + let mut rs = ""; + while i < 100000 { rs += "aaaaa"; i += 1; } + ret rs; + } + assert eq(half_a_million_letter_a(), + unsafe::slice_bytes(a_million_letter_a(), + 0u, 500000u)); } - fn half_a_million_letter_a() -> str { - let mut i = 0; - let mut rs = ""; - while i < 100000 { rs += "aaaaa"; i += 1; } - ret rs; - } - assert (eq(half_a_million_letter_a(), - unsafe::slice_bytes(a_million_letter_a(), 0u, 500000u))); } #[test] @@ -2483,25 +2500,25 @@ mod tests { } #[test] - fn test_shift_byte() unsafe { + fn test_shift_byte() { let mut s = "ABC"; - let b = unsafe::shift_byte(s); + let b = unsafe { unsafe::shift_byte(s) }; assert (s == "BC"); assert (b == 65u8); } #[test] - fn test_pop_byte() unsafe { + fn test_pop_byte() { let mut s = "ABC"; - let b = unsafe::pop_byte(s); + let b = unsafe { unsafe::pop_byte(s) }; assert (s == "AB"); assert (b == 67u8); } #[test] - fn test_unsafe_from_bytes() unsafe { + fn test_unsafe_from_bytes() { let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8]; - let b = unsafe::from_bytes(a); + let b = unsafe { unsafe::from_bytes(a) }; assert (b == "AAAAAAA"); } @@ -2541,11 +2558,13 @@ mod tests { } #[test] - fn test_from_buf() unsafe { - let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; - let b = vec::unsafe::to_ptr(a); - let c = unsafe::from_buf(b); - assert (c == "AAAAAAA"); + fn test_from_buf() { + unsafe { + let a = [65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 65u8, 0u8]; + let b = vec::unsafe::to_ptr(a); + let c = unsafe::from_buf(b); + assert (c == "AAAAAAA"); + } } #[test] @@ -2557,25 +2576,33 @@ mod tests { } #[test] - fn test_as_buf() unsafe { + fn test_as_buf() { let a = "Abcdefg"; - let b = as_buf(a, {|buf| assert (*buf == 65u8); 100 }); + let b = as_buf(a, {|buf| + assert unsafe { *buf } == 65u8; + 100 + }); assert (b == 100); } #[test] - fn test_as_buf_small() unsafe { + fn test_as_buf_small() { let a = "A"; - let b = as_buf(a, {|buf| assert (*buf == 65u8); 100 }); + let b = as_buf(a, {|buf| + assert unsafe { *buf } == 65u8; + 100 + }); assert (b == 100); } #[test] - fn test_as_buf2() unsafe { - let s = "hello"; - let sb = as_buf(s, {|b| b }); - let s_cstr = unsafe::from_buf(sb); - assert (eq(s_cstr, s)); + fn test_as_buf2() { + unsafe { + let s = "hello"; + let sb = as_buf(s, {|b| b }); + let s_cstr = unsafe::from_buf(sb); + assert (eq(s_cstr, s)); + } } #[test] @@ -2813,14 +2840,16 @@ mod tests { } #[test] - fn test_unpack_slice() unsafe { + fn test_unpack_slice() { let a = "hello"; unpack_slice(a) {|buf, len| - assert a[0] == 'h' as u8; - assert *buf == 'h' as u8; - assert len == 6u; - assert *ptr::offset(buf,4u) == 'o' as u8; - assert *ptr::offset(buf,5u) == 0u8; + unsafe { + assert a[0] == 'h' as u8; + assert *buf == 'h' as u8; + assert len == 6u; + assert *ptr::offset(buf,4u) == 'o' as u8; + assert *ptr::offset(buf,5u) == 0u8; + } } } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 53e8e4017ba..771107cd1a7 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -52,7 +52,7 @@ pure fn get_type_desc() -> *type_desc { #[doc = "Returns the size of a type"] #[inline(always)] -pure fn size_of() -> uint unsafe { +pure fn size_of() -> uint { unchecked { rusti::size_of::() } } @@ -62,12 +62,12 @@ Returns the ABI-required minimum alignment of a type This is the alignment used for struct fields. It may be smaller than the preferred alignment. "] -pure fn min_align_of() -> uint unsafe { +pure fn min_align_of() -> uint { unchecked { rusti::min_align_of::() } } #[doc = "Returns the preferred alignment of a type"] -pure fn pref_align_of() -> uint unsafe { +pure fn pref_align_of() -> uint { unchecked { rusti::pref_align_of::() } } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 2a746d76127..a284fc13e2e 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -504,7 +504,7 @@ type task_id = int; type rust_task = libc::c_void; type rust_closure = libc::c_void; -fn spawn_raw(opts: task_opts, +f: fn~()) unsafe { +fn spawn_raw(opts: task_opts, +f: fn~()) { let mut f = if opts.supervise { f @@ -519,26 +519,28 @@ fn spawn_raw(opts: task_opts, +f: fn~()) unsafe { } }; - let fptr = ptr::addr_of(f); - let closure: *rust_closure = unsafe::reinterpret_cast(fptr); + unsafe { + let fptr = ptr::addr_of(f); + let closure: *rust_closure = unsafe::reinterpret_cast(fptr); - let new_task = alt opts.sched { - none { - rustrt::new_task() - } - some(sched_opts) { - new_task_in_new_sched(sched_opts) - } - }; + let new_task = alt opts.sched { + none { + rustrt::new_task() + } + some(sched_opts) { + new_task_in_new_sched(sched_opts) + } + }; - option::iter(opts.notify_chan) {|c| - // FIXME (#1087): Would like to do notification in Rust - rustrt::rust_task_config_notify(new_task, c); + option::iter(opts.notify_chan) {|c| + // FIXME (#1087): Would like to do notification in Rust + rustrt::rust_task_config_notify(new_task, c); + } + + rustrt::start_task(new_task, closure); + unsafe::forget(f); } - rustrt::start_task(new_task, closure); - unsafe::forget(f); - fn new_task_in_new_sched(opts: sched_opts) -> *rust_task { if opts.native_stack_size != none { fail "native_stack_size scheduler option unimplemented"; @@ -962,7 +964,7 @@ fn test_osmain() { #[test] #[ignore(cfg(windows))] #[should_fail] -fn test_unkillable() unsafe { +fn test_unkillable() { import comm::methods; let po = comm::port(); let ch = po.chan(); @@ -980,14 +982,16 @@ fn test_unkillable() unsafe { fail; } - unkillable {|| - let p = ~0; - let pp: *uint = unsafe::transmute(p); + unsafe { + unkillable {|| + let p = ~0; + let pp: *uint = unsafe::transmute(p); - // If we are killed here then the box will leak - po.recv(); + // If we are killed here then the box will leak + po.recv(); - let _p: ~int = unsafe::transmute(pp); + let _p: ~int = unsafe::transmute(pp); + } } // Now we can be killed diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index be491433cd0..d5f0cc465c7 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -131,17 +131,17 @@ Convert to a string in a given base Fails if `radix` < 2 or `radix` > 16 "] -fn to_str(num: T, radix: uint) -> str unsafe { +fn to_str(num: T, radix: uint) -> str { to_str_bytes(false, num, radix) {|slice| vec::unpack_slice(slice) {|p, len| - str::unsafe::from_buf_len(p, len) + unsafe { str::unsafe::from_buf_len(p, len) } } } } #[doc = "Low-level helper routine for string conversion."] fn to_str_bytes(neg: bool, num: T, radix: uint, - f: fn([u8]/&) -> U) -> U unsafe { + f: fn([u8]/&) -> U) -> U { #[inline(always)] fn digit(n: T) -> u8 { @@ -177,28 +177,30 @@ fn to_str_bytes(neg: bool, num: T, radix: uint, // pointers and unsafe bits, and the codegen will prove it's all // in-bounds, no extra cost. - vec::unpack_slice(buf) {|p, len| - let mp = p as *mut u8; - let mut i = len; - let mut n = num; - let radix = radix as T; - loop { - i -= 1u; + unsafe { + vec::unpack_slice(buf) {|p, len| + let mp = p as *mut u8; + let mut i = len; + let mut n = num; + let radix = radix as T; + loop { + i -= 1u; + assert 0u < i && i < len; + *ptr::mut_offset(mp, i) = digit(n % radix); + n /= radix; + if n == 0 as T { break; } + } + assert 0u < i && i < len; - *ptr::mut_offset(mp, i) = digit(n % radix); - n /= radix; - if n == 0 as T { break; } + + if neg { + i -= 1u; + *ptr::mut_offset(mp, i) = '-' as u8; + } + + vec::unsafe::form_slice(ptr::offset(p, i), + len - i, f) } - - assert 0u < i && i < len; - - if neg { - i -= 1u; - *ptr::mut_offset(mp, i) = '-' as u8; - } - - vec::unsafe::form_slice(ptr::offset(p, i), - len - i, f) } } diff --git a/src/libcore/unsafe.rs b/src/libcore/unsafe.rs index 0c8261f71ad..85e2f8d8934 100644 --- a/src/libcore/unsafe.rs +++ b/src/libcore/unsafe.rs @@ -45,20 +45,24 @@ unsafe fn transmute(-thing: L) -> G { mod tests { #[test] - fn test_reinterpret_cast() unsafe { - assert reinterpret_cast(1) == 1u; + fn test_reinterpret_cast() { + assert unsafe { reinterpret_cast(1) } == 1u; } #[test] - fn test_transmute() unsafe { - let x = @1; - let x: *int = transmute(x); - assert *x == 1; - let _x: @int = transmute(x); + fn test_transmute() { + unsafe { + let x = @1; + let x: *int = transmute(x); + assert *x == 1; + let _x: @int = transmute(x); + } } #[test] - fn test_transmute2() unsafe { - assert transmute("L") == [76u8, 0u8]; + fn test_transmute2() { + unsafe { + assert transmute("L") == [76u8, 0u8]; + } } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 494470e32e4..b81073c729f 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -158,14 +158,16 @@ fn reserve_at_least(&v: [const T], n: uint) { Returns the number of elements the vector can hold without reallocating "] #[inline(always)] -pure fn capacity(&&v: [const T]) -> uint unsafe { - let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); - (**repr).alloc / sys::size_of::() +pure fn capacity(&&v: [const T]) -> uint { + unsafe { + let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); + (**repr).alloc / sys::size_of::() + } } #[doc = "Returns the length of a vector"] #[inline(always)] -pure fn len(&&v: [const T]/&) -> uint unsafe { +pure fn len(&&v: [const T]/&) -> uint { unpack_const_slice(v) {|_p, len| len} } @@ -179,7 +181,7 @@ pure fn from_fn(n_elts: uint, op: init_op) -> [T] { let mut v = []; unchecked{reserve(v, n_elts);} let mut i: uint = 0u; - while i < n_elts { v += [op(i)]; i += 1u; } + while i < n_elts unsafe { push(v, op(i)); i += 1u; } ret v; } @@ -200,13 +202,13 @@ pure fn from_elem(n_elts: uint, t: T) -> [T] { } #[doc = "Produces a mut vector from an immutable vector."] -fn to_mut(+v: [T]) -> [mut T] unsafe { - ::unsafe::transmute(v) +fn to_mut(+v: [T]) -> [mut T] { + unsafe { ::unsafe::transmute(v) } } #[doc = "Produces an immutable vector from a mut vector."] -fn from_mut(+v: [mut T]) -> [T] unsafe { - ::unsafe::transmute(v) +fn from_mut(+v: [mut T]) -> [T] { + unsafe { ::unsafe::transmute(v) } } // Accessors @@ -385,7 +387,6 @@ fn shift(&v: [T]) -> T { let mut r <- *vv; for uint::range(1u, ln) {|i| - // FIXME (#2703): this isn't legal, per se... let r <- *ptr::offset(vv, i); push(v, r); } @@ -397,14 +398,25 @@ fn shift(&v: [T]) -> T { } } +#[doc = "Prepend an element to the vector"] +fn unshift(&v: [T], +x: T) { + let mut vv = [x]; + v <-> vv; + while len(vv) > 0 { + push(v, shift(vv)); + } +} + #[doc = "Remove the last element from a vector and return it"] -fn pop(&v: [const T]) -> T unsafe { +fn pop(&v: [const T]) -> T { let ln = len(v); assert ln > 0u; let valptr = ptr::mut_addr_of(v[ln - 1u]); - let val <- *valptr; - unsafe::set_len(v, ln - 1u); - val + unsafe { + let val <- *valptr; + unsafe::set_len(v, ln - 1u); + val + } } #[doc = "Append an element to a vector"] @@ -556,7 +568,7 @@ Apply a function to each element of a vector and return the results pure fn mapi(v: [T]/&, f: fn(uint, T) -> U) -> [U] { let mut result = []; unchecked{reserve(result, len(v));} - for eachi(v) {|i, elem| result += [f(i, elem)]; } + for eachi(v) {|i, elem| unsafe { push(result, f(i, elem)); } } ret result; } @@ -955,13 +967,15 @@ Iterates over a vector, with option to break Return true to continue, false to break. "] #[inline(always)] -pure fn each(v: [const T]/&, f: fn(T) -> bool) unsafe { +pure fn each(v: [const T]/&, f: fn(T) -> bool) { vec::unpack_slice(v) {|p, n| let mut n = n; let mut p = p; while n > 0u { - if !f(*p) { break; } - p = ptr::offset(p, 1u); + unsafe { + if !f(*p) { break; } + p = ptr::offset(p, 1u); + } n -= 1u; } } @@ -973,13 +987,15 @@ Iterates over a vector's elements and indices Return true to continue, false to break. "] #[inline(always)] -pure fn eachi(v: [const T]/&, f: fn(uint, T) -> bool) unsafe { +pure fn eachi(v: [const T]/&, f: fn(uint, T) -> bool) { vec::unpack_slice(v) {|p, n| let mut i = 0u; let mut p = p; while i < n { - if !f(i, *p) { break; } - p = ptr::offset(p, 1u); + unsafe { + if !f(i, *p) { break; } + p = ptr::offset(p, 1u); + } i += 1u; } } @@ -1080,11 +1096,11 @@ Work with the buffer of a vector. Allows for unsafe manipulation of vector contents, which is useful for native interop. "] -fn as_buf(v: [E]/&, f: fn(*E) -> T) -> T unsafe { +fn as_buf(v: [E]/&, f: fn(*E) -> T) -> T { unpack_slice(v) { |buf, _len| f(buf) } } -fn as_mut_buf(v: [mut E]/&, f: fn(*mut E) -> T) -> T unsafe { +fn as_mut_buf(v: [mut E]/&, f: fn(*mut E) -> T) -> T { unpack_mut_slice(v) { |buf, _len| f(buf) } } @@ -1093,10 +1109,12 @@ Work with the buffer and length of a slice. "] #[inline(always)] pure fn unpack_slice(s: [const T]/&, - f: fn(*T, uint) -> U) -> U unsafe { - let v : *(*T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s)); - let (buf,len) = *v; - f(buf, len / sys::size_of::()) + f: fn(*T, uint) -> U) -> U { + unsafe { + let v : *(*T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s)); + let (buf,len) = *v; + f(buf, len / sys::size_of::()) + } } #[doc = " @@ -1104,10 +1122,13 @@ Work with the buffer and length of a slice. "] #[inline(always)] pure fn unpack_const_slice(s: [const T]/&, - f: fn(*const T, uint) -> U) -> U unsafe { - let v : *(*const T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s)); - let (buf,len) = *v; - f(buf, len / sys::size_of::()) + f: fn(*const T, uint) -> U) -> U { + unsafe { + let v : *(*const T,uint) = + ::unsafe::reinterpret_cast(ptr::addr_of(s)); + let (buf,len) = *v; + f(buf, len / sys::size_of::()) + } } #[doc = " @@ -1115,10 +1136,13 @@ Work with the buffer and length of a slice. "] #[inline(always)] pure fn unpack_mut_slice(s: [mut T]/&, - f: fn(*mut T, uint) -> U) -> U unsafe { - let v : *(*const T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s)); - let (buf,len) = *v; - f(buf, len / sys::size_of::()) + f: fn(*mut T, uint) -> U) -> U { + unsafe { + let v : *(*const T,uint) = + ::unsafe::reinterpret_cast(ptr::addr_of(s)); + let (buf,len) = *v; + f(buf, len / sys::size_of::()) + } } impl extensions for [T] { @@ -1372,12 +1396,14 @@ mod u8 { export hash; #[doc = "Bytewise string comparison"] - pure fn cmp(&&a: [u8], &&b: [u8]) -> int unsafe { + pure fn cmp(&&a: [u8], &&b: [u8]) -> int { let a_len = len(a); let b_len = len(b); let n = uint::min(a_len, b_len) as libc::size_t; - let r = libc::memcmp(unsafe::to_ptr(a) as *libc::c_void, - unsafe::to_ptr(b) as *libc::c_void, n) as int; + let r = unsafe { + libc::memcmp(unsafe::to_ptr(a) as *libc::c_void, + unsafe::to_ptr(b) as *libc::c_void, n) as int + }; if r != 0 { r } else { if a_len == b_len { @@ -1397,10 +1423,10 @@ mod u8 { pure fn le(&&a: [u8], &&b: [u8]) -> bool { cmp(a, b) <= 0 } #[doc = "Bytewise equality"] - pure fn eq(&&a: [u8], &&b: [u8]) -> bool unsafe { cmp(a, b) == 0 } + pure fn eq(&&a: [u8], &&b: [u8]) -> bool { unsafe { cmp(a, b) == 0 } } #[doc = "Bytewise inequality"] - pure fn ne(&&a: [u8], &&b: [u8]) -> bool unsafe { cmp(a, b) != 0 } + pure fn ne(&&a: [u8], &&b: [u8]) -> bool { unsafe { cmp(a, b) != 0 } } #[doc ="Bytewise greater than or equal"] pure fn ge(&&a: [u8], &&b: [u8]) -> bool { cmp(a, b) >= 0 } @@ -1474,26 +1500,28 @@ mod tests { fn add(&&x: uint, &&y: uint) -> uint { ret x + y; } #[test] - fn test_unsafe_ptrs() unsafe { - // Test on-stack copy-from-buf. - let a = [1, 2, 3]; - let mut ptr = unsafe::to_ptr(a); - let b = unsafe::from_buf(ptr, 3u); - assert (len(b) == 3u); - assert (b[0] == 1); - assert (b[1] == 2); - assert (b[2] == 3); + fn test_unsafe_ptrs() { + unsafe { + // Test on-stack copy-from-buf. + let a = [1, 2, 3]; + let mut ptr = unsafe::to_ptr(a); + let b = unsafe::from_buf(ptr, 3u); + assert (len(b) == 3u); + assert (b[0] == 1); + assert (b[1] == 2); + assert (b[2] == 3); - // Test on-heap copy-from-buf. - let c = [1, 2, 3, 4, 5]; - ptr = unsafe::to_ptr(c); - let d = unsafe::from_buf(ptr, 5u); - assert (len(d) == 5u); - assert (d[0] == 1); - assert (d[1] == 2); - assert (d[2] == 3); - assert (d[3] == 4); - assert (d[4] == 5); + // Test on-heap copy-from-buf. + let c = [1, 2, 3, 4, 5]; + ptr = unsafe::to_ptr(c); + let d = unsafe::from_buf(ptr, 5u); + assert (len(d) == 5u); + assert (d[0] == 1); + assert (d[1] == 2); + assert (d[2] == 3); + assert (d[3] == 4); + assert (d[4] == 5); + } } #[test] @@ -2181,21 +2209,32 @@ mod tests { } #[test] - fn to_mut_no_copy() unsafe { - let x = [1, 2, 3]; - let addr = unsafe::to_ptr(x); - let x_mut = to_mut(x); - let addr_mut = unsafe::to_ptr(x_mut); - assert addr == addr_mut; + fn to_mut_no_copy() { + unsafe { + let x = [1, 2, 3]; + let addr = unsafe::to_ptr(x); + let x_mut = to_mut(x); + let addr_mut = unsafe::to_ptr(x_mut); + assert addr == addr_mut; + } } #[test] - fn from_mut_no_copy() unsafe { - let x = [mut 1, 2, 3]; - let addr = unsafe::to_ptr(x); - let x_imm = from_mut(x); - let addr_imm = unsafe::to_ptr(x_imm); - assert addr == addr_imm; + fn from_mut_no_copy() { + unsafe { + let x = [mut 1, 2, 3]; + let addr = unsafe::to_ptr(x); + let x_imm = from_mut(x); + let addr_imm = unsafe::to_ptr(x_imm); + assert addr == addr_imm; + } + } + + #[test] + fn test_unshift() { + let mut x = [1, 2, 3]; + unshift(x, 0); + assert x == [0, 1, 2, 3]; } #[test] diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 5e116cd11cf..c828566841e 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -822,7 +822,7 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) log(debug, "starting tcp::read"); let iotask = (*socket_data).iotask; let rs_result = read_start_common_impl(socket_data); - if result::is_failure(rs_result) { + if result::is_err(rs_result) { let err_data = result::get_err(rs_result); result::err(err_data) } @@ -1433,7 +1433,7 @@ mod test { let accept_result = accept(new_conn); log(debug, "SERVER: after accept()"); - if result::is_failure(accept_result) { + if result::is_err(accept_result) { log(debug, "SERVER: error accept connection"); let err_data = result::get_err(accept_result); comm::send(kill_ch, some(err_data)); @@ -1474,7 +1474,7 @@ mod test { log(debug, "SERVER: recv'd on cont_ch..leaving listen cb"); }); // err check on listen_result - if result::is_failure(listen_result) { + if result::is_err(listen_result) { let err_data = result::get_err(listen_result); log(debug, #fmt("SERVER: exited abnormally name %s msg %s", err_data.err_name, err_data.err_msg)); @@ -1495,7 +1495,7 @@ mod test { let server_ip_addr = ip::v4::parse_addr(server_ip); let new_listener_result = new_listener(server_ip_addr, server_port, 128u, iotask); - if result::is_failure(new_listener_result) { + if result::is_err(new_listener_result) { let err_data = result::get_err(new_listener_result); log(debug, #fmt("SERVER: exited abnormally name %s msg %s", err_data.err_name, err_data.err_msg)); @@ -1507,7 +1507,7 @@ mod test { // in a loop {}, but we're just going to take a single // client.. get their req, write a resp and then exit let new_conn_result = server_port.recv(); - if result::is_failure(new_conn_result) { + if result::is_err(new_conn_result) { let err_data = result::get_err(new_conn_result); log(debug, #fmt("SERVER: exited abnormally name %s msg %s", err_data.err_name, err_data.err_msg)); @@ -1544,7 +1544,7 @@ mod test { log(debug, "CLIENT: starting.."); let connect_result = connect(server_ip_addr, server_port, iotask); - if result::is_failure(connect_result) { + if result::is_err(connect_result) { log(debug, "CLIENT: failed to connect"); let err_data = result::get_err(connect_result); log(debug, #fmt("CLIENT: connect err name: %s msg: %s", @@ -1556,7 +1556,7 @@ mod test { let resp_bytes = str::bytes(resp); tcp_write_single(sock, resp_bytes); let read_result = sock.read(0u); - if read_result.is_failure() { + if read_result.is_err() { log(debug, "CLIENT: failure to read"); "" } @@ -1573,7 +1573,7 @@ mod test { fn tcp_write_single(sock: tcp_socket, val: [u8]) { let write_result_future = sock.write_future(val); let write_result = write_result_future.get(); - if result::is_failure(write_result) { + if result::is_err(write_result) { log(debug, "tcp_write_single: write failed!"); let err_data = result::get_err(write_result); log(debug, #fmt("tcp_write_single err name: %s msg: %s", diff --git a/src/libstd/par.rs b/src/libstd/par.rs index e621fd78724..17297d94bd9 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -42,7 +42,7 @@ fn map_slices( // FIXME: why is the :: annotation required here? (#2617) vec::unpack_slice::(xs) {|p, _len| let f = f(); - futures += [future::spawn() {|copy base| + let f = future::spawn() {|copy base| unsafe { let len = end - base; let slice = (ptr::offset(p, base), @@ -55,7 +55,8 @@ fn map_slices( assert(vec::len(slice) == end - base); f(base, slice) } - }]; + }; + vec::push(futures, f); }; base += items_per_task; } diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 75a88fb221b..fe9f59d5538 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -452,10 +452,7 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, [] } - ast::ty_vstore(_, _) { - cx.span_unimpl(ty.span, "serialization for vstore types"); - } - + ast::ty_vstore(@{node: ast::ty_vec(mt),_}, ast::vstore_uniq) | ast::ty_vec(mt) { let ser_e = cx.expr( @@ -472,6 +469,11 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, std::serialization::emit_from_vec($(s), $(v), {|__e| $(ser_e) }) }] } + + ast::ty_vstore(_, _) { + cx.span_unimpl(ty.span, "serialization for vstore types"); + } + } } @@ -673,14 +675,15 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, #ast{ fail } } - ast::ty_vstore(_, _) { - cx.span_unimpl(ty.span, "deserialization for vstore types"); - } - + ast::ty_vstore(@{node: ast::ty_vec(mt),_}, ast::vstore_uniq) | ast::ty_vec(mt) { let l = deser_lambda(cx, tps, mt.ty, cx.clone(d)); #ast{ std::serialization::read_to_vec($(d), $(l)) } } + + ast::ty_vstore(_, _) { + cx.span_unimpl(ty.span, "deserialization for vstore types"); + } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2196ae9d4be..a1043c4ed2f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -771,9 +771,9 @@ class parser { } else if self.eat_keyword("if") { ret pexpr(self.parse_if_expr()); } else if self.eat_keyword("for") { - ret pexpr(self.parse_for_expr()); + ret pexpr(self.parse_sugary_call_expr("for", expr_loop_body)); } else if self.eat_keyword("do") { - ret pexpr(self.parse_do_expr()); + ret pexpr(self.parse_sugary_call_expr("do", expr_do_body)); } else if self.eat_keyword("while") { ret pexpr(self.parse_while_expr()); } else if self.eat_keyword("loop") { @@ -1283,36 +1283,21 @@ class parser { } } - fn parse_for_expr() -> @expr { + fn parse_sugary_call_expr(keyword: str, + ctor: fn(+@expr) -> expr_) -> @expr { let lo = self.last_span; let call = self.parse_expr_res(RESTRICT_STMT_EXPR); alt call.node { expr_call(f, args, true) { let b_arg = vec::last(args); let last = self.mk_expr(b_arg.span.lo, b_arg.span.hi, - expr_loop_body(b_arg)); + ctor(b_arg)); @{node: expr_call(f, vec::init(args) + [last], true) with *call} } _ { - self.span_fatal(lo, "`for` must be followed by a block call"); - } - } - } - - fn parse_do_expr() -> @expr { - let lo = self.last_span; - let call = self.parse_expr_res(RESTRICT_STMT_EXPR); - alt call.node { - expr_call(f, args, true) { - let b_arg = vec::last(args); - let last = self.mk_expr(b_arg.span.lo, b_arg.span.hi, - expr_do_body(b_arg)); - @{node: expr_call(f, vec::init(args) + [last], true) - with *call} - } - _ { - self.span_fatal(lo, "`do` must be followed by a block call"); + self.span_fatal( + lo, #fmt("`%s` must be followed by a block call", keyword)); } } } @@ -1956,7 +1941,7 @@ class parser { let rp = self.parse_region_param(); let ty_params = self.parse_ty_params(); let class_path = self.ident_to_path_tys(class_name, rp, ty_params); - let ifaces : [@iface_ref] = if self.eat_keyword("implements") + let ifaces : [@iface_ref] = if self.eat(token::COLON) { self.parse_iface_ref_list() } else { [] }; self.expect(token::LBRACE); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 478d7f53658..9240e3d7a9f 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -251,7 +251,6 @@ fn contextual_keyword_table() -> hashmap { let keys = [ "as", "else", - "implements", "move", "of", "priv", "pub", diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 54864c287ae..b38f4c35d86 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -495,9 +495,11 @@ fn print_item(s: ps, &&item: @ast::item) { word_nbsp(s, *item.ident); print_region_param(s, rp); print_type_params(s, tps); - word_space(s, "implements"); - commasep(s, inconsistent, ifaces, {|s, p| - print_path(s, p.path, false)}); + if vec::len(ifaces) != 0u { + word_space(s, ":"); + commasep(s, inconsistent, ifaces, {|s, p| + print_path(s, p.path, false)}); + } bopen(s); hardbreak_if_not_bol(s); maybe_print_comment(s, ctor.span.lo); diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index cab1b6b427c..ad729494c45 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -891,9 +891,7 @@ rust_unlock_cond_lock(rust_cond_lock *lock) { extern "C" void rust_wait_cond_lock(rust_cond_lock *lock) { rust_task *task = rust_get_current_task(); -#ifdef DEBUG_LOCKS - assert(lock->lock.lock_held_by_current_thread()); -#endif + lock->lock.must_have_lock(); assert(NULL == lock->waiting); lock->waiting = task; task->block(lock, "waiting for signal"); @@ -905,9 +903,7 @@ rust_wait_cond_lock(rust_cond_lock *lock) { extern "C" bool rust_signal_cond_lock(rust_cond_lock *lock) { -#ifdef DEBUG_LOCKS - assert(lock->lock.lock_held_by_current_thread()); -#endif + lock->lock.must_have_lock(); if(NULL == lock->waiting) { return false; } diff --git a/src/rustc/middle/block_use.rs b/src/rustc/middle/block_use.rs index ea1cb3f235e..9fcc3d286fc 100644 --- a/src/rustc/middle/block_use.rs +++ b/src/rustc/middle/block_use.rs @@ -34,7 +34,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt) { i += 1u; } } - expr_loop_body(body) { + expr_loop_body(body) | expr_do_body(body) { cx.allow_block = true; v.visit_expr(body, cx, v); } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index 13201d4e673..43eb9f8c58d 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -1752,7 +1752,6 @@ fn trans_assign_op(bcx: block, ex: @ast::expr, op: ast::binop, arg_exprs([src]), save_in(target)); ret move_val(bcx, DROP_EXISTING, lhs_res.val, - // FIXME (#2704): should kind be owned? {bcx: bcx, val: target, kind: owned}, dty); } diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index 1c0f5ed053c..c5aa42186bc 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -677,7 +677,7 @@ fn mk_nil_ptr(cx: ctxt) -> t { mk_ptr(cx, {ty: mk_nil(cx), mutbl: ast::m_imm}) } -fn mk_vec(cx: ctxt, tm: mt) -> t { mk_t(cx, ty_vec(tm)) } +fn mk_vec(cx: ctxt, tm: mt) -> t { mk_evec(cx, tm, vstore_uniq) } fn mk_evec(cx: ctxt, tm: mt, t: vstore) -> t { mk_t(cx, ty_evec(tm, t)) @@ -1472,7 +1472,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind { ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) | ty_ptr(_) { kind_implicitly_sendable() | kind_const() } // Implicit copyability of strs is configurable - ty_str { + ty_str | ty_estr(vstore_uniq) { if cx.vecs_implicitly_copyable { kind_implicitly_sendable() | kind_const() } else { kind_sendable() | kind_const() } @@ -1502,7 +1502,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind { remove_implicit(mutable_type_kind(cx, tm)) } // Implicit copyability of vecs is configurable - ty_vec(tm) { + ty_vec(tm) | ty_evec(tm, vstore_uniq) { if cx.vecs_implicitly_copyable { mutable_type_kind(cx, tm) } else { remove_implicit(mutable_type_kind(cx, tm)) } @@ -1520,9 +1520,6 @@ fn type_kind(cx: ctxt, ty: t) -> kind { kind_implicitly_copyable() } } - ty_evec(tm, vstore_uniq) { - remove_implicit(mutable_type_kind(cx, tm)) - } ty_evec(tm, vstore_fixed(_)) { mutable_type_kind(cx, tm) } @@ -1530,7 +1527,6 @@ fn type_kind(cx: ctxt, ty: t) -> kind { // All estrs are copyable; uniques and interiors are sendable. ty_estr(vstore_box) | ty_estr(vstore_slice(_)) { kind_implicitly_copyable() | kind_const() } - ty_estr(vstore_uniq) { kind_sendable() | kind_const() } ty_estr(vstore_fixed(_)) { kind_implicitly_sendable() | kind_const() } // Records lower to the lowest of their members. diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 3c7bddc9022..ad1a613e739 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -218,7 +218,7 @@ fn require_same_types( fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool { alt ty::get(a.ty).struct { - ty::ty_vec(mt) { + ty::ty_evec(mt, vstore_uniq) { if mt.mutbl != ast::m_imm { ret false; } alt ty::get(mt.ty).struct { ty::ty_str { ret true; } @@ -271,12 +271,12 @@ fn check_main_fn_ty(ccx: @crate_ctxt, } } -fn check_for_main_fn(ccx: @crate_ctxt, crate: @ast::crate) { +fn check_for_main_fn(ccx: @crate_ctxt) { let tcx = ccx.tcx; if !tcx.sess.building_library { alt copy tcx.sess.main_fn { some((id, sp)) { check_main_fn_ty(ccx, id, sp); } - none { tcx.sess.span_err(crate.span, "main function not found"); } + none { tcx.sess.err("main function not found"); } } } } @@ -289,7 +289,7 @@ fn check_crate(tcx: ty::ctxt, impl_map: resolve::impl_map, tcx: tcx}; collect::collect_item_types(ccx, crate); check::check_item_types(ccx, crate); - check_for_main_fn(ccx, crate); + check_for_main_fn(ccx); tcx.sess.abort_if_errors(); (ccx.method_map, ccx.vtable_map) } diff --git a/src/rustc/middle/typeck/astconv.rs b/src/rustc/middle/typeck/astconv.rs index 476ef9d3ba5..c40b86d0530 100644 --- a/src/rustc/middle/typeck/astconv.rs +++ b/src/rustc/middle/typeck/astconv.rs @@ -170,6 +170,12 @@ fn ast_ty_to_ty( ret ty::mk_evec(tcx, mt, vst); } + // HACK: if we get a []/~, we assume that it was actually a + // [] that got written down, and we throw away the /~... + ty::ty_evec(mt, vstore_uniq) { + ret ty::mk_evec(tcx, mt, vst); + } + ty::ty_str { ret ty::mk_estr(tcx, vst); } diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 86d105adb99..5ba7c88d3cd 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -381,7 +381,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { // Check that there's at least one field let (fields,_) = split_class_items(members); if fields.len() < 1u { - ccx.tcx.sess.span_err(it.span, "A class must have at least one \ + ccx.tcx.sess.span_err(it.span, "a class must have at least one \ field"); } // Check that the class is instantiable @@ -938,7 +938,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, // separate case below. tcx.sess.span_bug( expr.span, - #fmt["Comparison operator in expr_binop: %s", + #fmt["comparison operator in expr_binop: %s", ast_util::binop_to_str(op)]); } _ { lhs_t } @@ -1217,7 +1217,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, result::ok(_) { /* fall through */ } result::err(_) { tcx.sess.span_err(expr.span, - "ret; in function returning non-nil"); } + "`ret;` in function returning non-nil"); } } } some(e) { check_expr_with(fcx, e, ret_ty); } @@ -1299,7 +1299,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, result::ok(_) {} result::err(err) { tcx.sess.span_fatal( - expr.span, #fmt("a loop function's last argument \ + expr.span, #fmt("a `loop` function's last argument \ should return `bool`, not `%s`", fcx.infcx.ty_to_str(fty.output))); } @@ -1307,8 +1307,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, (ty::mk_fn(tcx, {output: ty::mk_nil(tcx) with fty}), fty.proto) } _ { - tcx.sess.span_fatal(expr.span, "a loop function's last argument \ - should be of function type"); + tcx.sess.span_fatal(expr.span, "a `loop` function's last \ + argument should be of function \ + type"); } }; alt check b.node { @@ -1334,7 +1335,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, (ty::mk_fn(tcx, fty), fty.proto) } _ { - tcx.sess.span_fatal(expr.span, "a do function's last argument \ + tcx.sess.span_fatal(expr.span, "a `do` function's last argument \ should be of function type"); } }; @@ -1547,8 +1548,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, } none { let t_err = fcx.infcx.resolve_type_vars_if_possible(expr_t); - let msg = #fmt["attempted access of field %s on type %s, but \ - no public field or method with that name was found", + let msg = #fmt["attempted access of field `%s` on type `%s`, \ + but no public field or method with that name \ + was found", *field, fcx.infcx.ty_to_str(t_err)]; tcx.sess.span_err(expr.span, msg); // NB: Adding a bogus type to allow typechecking to continue @@ -1781,8 +1783,8 @@ fn check_instantiable(tcx: ty::ctxt, let rty = ty::node_id_to_type(tcx, item_id); if !ty::is_instantiable(tcx, rty) { tcx.sess.span_err(sp, #fmt["this type cannot be instantiated \ - without an instance of itself. \ - Consider using option<%s>.", + without an instance of itself; \ + consider using `option<%s>`", ty_to_str(tcx, rty)]); } } @@ -1821,7 +1823,7 @@ fn check_enum_variants(ccx: @crate_ctxt, } if vec::contains(disr_vals, disr_val) { ccx.tcx.sess.span_err(v.span, - "discriminator value already exists."); + "discriminator value already exists"); } disr_vals += [disr_val]; let ctor_ty = ty::node_id_to_type(ccx.tcx, v.node.id); @@ -1848,7 +1850,7 @@ fn check_enum_variants(ccx: @crate_ctxt, _ { false } } }) { - ccx.tcx.sess.span_err(sp, "illegal recursive enum type. \ + ccx.tcx.sess.span_err(sp, "illegal recursive enum type; \ wrap the inner value in a box to \ make it representable"); } @@ -2195,13 +2197,13 @@ fn check_bounds_are_used(ccx: @crate_ctxt, if !r_used { ccx.tcx.sess.span_err( span, "lifetime `self` unused inside \ - reference-parameterized type."); + reference-parameterized type"); } for tps_used.eachi { |i, b| if !b { ccx.tcx.sess.span_err( - span, #fmt["Type parameter %s is unused.", *tps[i].ident]); + span, #fmt["type parameter `%s` is unused", *tps[i].ident]); } } } @@ -2268,13 +2270,13 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) { let i_n_tps = (*i_ty.bounds).len(); if i_n_tps != n_tps { tcx.sess.span_err(it.span, #fmt("intrinsic has wrong number \ - of type parameters. found %u, \ + of type parameters: found %u, \ expected %u", i_n_tps, n_tps)); } else { require_same_types( tcx, none, it.span, i_ty.ty, fty, - {|| #fmt["intrinsic has wrong type. \ - expected %s", + {|| #fmt["intrinsic has wrong type: \ + expected `%s`", ty_to_str(ccx.tcx, fty)]}); } } diff --git a/src/test/auxiliary/cci_class_cast.rs b/src/test/auxiliary/cci_class_cast.rs index 997cab28155..63b8426ac93 100644 --- a/src/test/auxiliary/cci_class_cast.rs +++ b/src/test/auxiliary/cci_class_cast.rs @@ -3,7 +3,7 @@ import to_str::to_str; mod kitty { -class cat implements to_str { +class cat : to_str { priv { let mut meows : uint; fn meow() { diff --git a/src/test/bench/graph500-bfs.rs b/src/test/bench/graph500-bfs.rs index 6c6466017ef..56733b29178 100644 --- a/src/test/bench/graph500-bfs.rs +++ b/src/test/bench/graph500-bfs.rs @@ -305,7 +305,7 @@ fn validate(edges: [(node_id, node_id)], status = false; } - path += [parent]; + vec::push(path, parent); parent = tree[parent]; } diff --git a/src/test/bench/msgsend.rs b/src/test/bench/msgsend.rs index aaeb070ce34..b6a6ba60a9f 100644 --- a/src/test/bench/msgsend.rs +++ b/src/test/bench/msgsend.rs @@ -40,7 +40,7 @@ fn run(args: [str]) { let mut worker_results = []; for uint::range(0u, workers) {|_i| let builder = task::builder(); - worker_results += [task::future_result(builder)]; + vec::push(worker_results, task::future_result(builder)); task::run(builder) {|| for uint::range(0u, size / workers) {|_i| comm::send(to_child, bytes(100u)); diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index f43f27f425f..c4e51902628 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -77,7 +77,6 @@ mod map_reduce { type putter = fn(K, V); - // FIXME: the first K1 parameter should probably be a - (#2599) type mapper = fn~(K1, putter); type getter = fn() -> option; diff --git a/src/test/compile-fail/class-cast-to-iface.rs b/src/test/compile-fail/class-cast-to-iface.rs index faebae34694..e79c021d9f3 100644 --- a/src/test/compile-fail/class-cast-to-iface.rs +++ b/src/test/compile-fail/class-cast-to-iface.rs @@ -1,9 +1,9 @@ -// error-pattern: attempted access of field eat on type noisy +// error-pattern: attempted access of field `eat` on type `noisy` iface noisy { fn speak(); } -class cat implements noisy { +class cat : noisy { priv { let mut meows : uint; fn meow() { diff --git a/src/test/compile-fail/class-implements-bad-iface.rs b/src/test/compile-fail/class-implements-bad-iface.rs index ff7d9fbe327..4e95b986a9a 100644 --- a/src/test/compile-fail/class-implements-bad-iface.rs +++ b/src/test/compile-fail/class-implements-bad-iface.rs @@ -1,5 +1,5 @@ // error-pattern:unresolved typename: nonexistent -class cat implements nonexistent { +class cat : nonexistent { let meows: uint; new(in_x : uint) { self.meows = in_x; } } diff --git a/src/test/compile-fail/class-implements-int.rs b/src/test/compile-fail/class-implements-int.rs index 7a2a7ad4f94..1768b8c4bf0 100644 --- a/src/test/compile-fail/class-implements-int.rs +++ b/src/test/compile-fail/class-implements-int.rs @@ -1,4 +1,4 @@ -class cat implements int { //! ERROR can only implement interface types +class cat : int { //! ERROR can only implement interface types let meows: uint; new(in_x : uint) { self.meows = in_x; } } diff --git a/src/test/compile-fail/class-method-missing.rs b/src/test/compile-fail/class-method-missing.rs index 6e6092fceab..788baa73c34 100644 --- a/src/test/compile-fail/class-method-missing.rs +++ b/src/test/compile-fail/class-method-missing.rs @@ -3,7 +3,7 @@ iface animal { fn eat(); } -class cat implements animal { +class cat : animal { let meows: uint; new(in_x : uint) { self.meows = in_x; } } diff --git a/src/test/compile-fail/fail-type-err.rs b/src/test/compile-fail/fail-type-err.rs index 29bdc877a04..e0d3680a381 100644 --- a/src/test/compile-fail/fail-type-err.rs +++ b/src/test/compile-fail/fail-type-err.rs @@ -1,2 +1,2 @@ -// error-pattern:expected `str` but found `[int]` +// error-pattern:expected `str` but found `[int]/~` fn main() { fail [0i]; } diff --git a/src/test/compile-fail/issue-1763.rs b/src/test/compile-fail/issue-1763.rs index 678e3cc57ea..17510164a5f 100644 --- a/src/test/compile-fail/issue-1763.rs +++ b/src/test/compile-fail/issue-1763.rs @@ -1,6 +1,6 @@ // Issue #1763 - infer types correctly -type actor = { //! ERROR Type parameter T is unused. +type actor = { //! ERROR type parameter `T` is unused unused: bool }; diff --git a/src/test/compile-fail/issue-2509-a.rs b/src/test/compile-fail/issue-2509-a.rs index a500d249c07..69970f8dc95 100644 --- a/src/test/compile-fail/issue-2509-a.rs +++ b/src/test/compile-fail/issue-2509-a.rs @@ -1,4 +1,4 @@ -class c { //! ERROR A class must have at least one field +class c { //! ERROR a class must have at least one field new() { } } diff --git a/src/test/compile-fail/private-method-cross-crate.rs b/src/test/compile-fail/private-method-cross-crate.rs index 279c61db26c..f54a0ffc068 100644 --- a/src/test/compile-fail/private-method-cross-crate.rs +++ b/src/test/compile-fail/private-method-cross-crate.rs @@ -1,4 +1,4 @@ -// error-pattern:attempted access of field nap on type +// error-pattern:attempted access of field `nap` on type // xfail-fast // aux-build:cci_class_5.rs use cci_class_5; diff --git a/src/test/compile-fail/ret-non-nil.rs b/src/test/compile-fail/ret-non-nil.rs index 71db7e4192f..4153f413dc0 100644 --- a/src/test/compile-fail/ret-non-nil.rs +++ b/src/test/compile-fail/ret-non-nil.rs @@ -1,4 +1,4 @@ -// error-pattern: ret; in function returning non-nil +// error-pattern: `ret;` in function returning non-nil fn f() { ret; } diff --git a/src/test/compile-fail/unsafe-fn-autoderef.rs b/src/test/compile-fail/unsafe-fn-autoderef.rs index 56d0f96fb3e..cc6faa07557 100644 --- a/src/test/compile-fail/unsafe-fn-autoderef.rs +++ b/src/test/compile-fail/unsafe-fn-autoderef.rs @@ -15,7 +15,7 @@ fn f(p: *rec) -> int { // are prohibited by various checks, such as that the enum is // instantiable and so forth). - ret p.f; //! ERROR attempted access of field f on type *rec + ret p.f; //! ERROR attempted access of field `f` on type `*rec` } fn main() { diff --git a/src/test/compile-fail/vec-add.rs b/src/test/compile-fail/vec-add.rs index 6d18bf9e2f8..6642112d998 100644 --- a/src/test/compile-fail/vec-add.rs +++ b/src/test/compile-fail/vec-add.rs @@ -1,8 +1,8 @@ // xfail-test -// FIXME: + should allow immutable or mutable vectors on the right -// hand side in all cases. We are getting compiler errors about this -// now, so I'm xfailing the test for now. -eholk +// FIXME (Issue #2711): + should allow immutable or mutable vectors on +// the right hand side in all cases. We are getting compiler errors +// about this now, so I'm xfailing the test for now. -eholk fn add(i: [int], m: [mut int], c: [const int]) { diff --git a/src/test/compile-fail/vec-field.rs b/src/test/compile-fail/vec-field.rs index 56d24a38713..7eb7e118b39 100644 --- a/src/test/compile-fail/vec-field.rs +++ b/src/test/compile-fail/vec-field.rs @@ -1,4 +1,4 @@ -// error-pattern:attempted access of field some_field_name on type [int] +// error-pattern:attempted access of field `some_field_name` on type `[int]/~` // issue #367 fn f() { diff --git a/src/test/run-pass/class-cast-to-iface-cross-crate.rs b/src/test/run-pass/class-cast-to-iface-cross-crate.rs index 14722b71794..13c0e60c427 100644 --- a/src/test/run-pass/class-cast-to-iface-cross-crate.rs +++ b/src/test/run-pass/class-cast-to-iface-cross-crate.rs @@ -1,7 +1,7 @@ import to_str::*; import to_str::to_str; -class cat implements to_str { +class cat : to_str { priv { let mut meows : uint; fn meow() { diff --git a/src/test/run-pass/class-cast-to-iface-multiple-types.rs b/src/test/run-pass/class-cast-to-iface-multiple-types.rs index 84bc53ac807..e2dc7b732a8 100644 --- a/src/test/run-pass/class-cast-to-iface-multiple-types.rs +++ b/src/test/run-pass/class-cast-to-iface-multiple-types.rs @@ -2,7 +2,7 @@ iface noisy { fn speak() -> int; } -class dog implements noisy { +class dog : noisy { priv { let barks : @mut uint; fn bark() -> int { @@ -26,7 +26,7 @@ class dog implements noisy { fn speak() -> int { self.bark() } } -class cat implements noisy { +class cat : noisy { priv { let meows : @mut uint; fn meow() -> uint { diff --git a/src/test/run-pass/class-cast-to-iface.rs b/src/test/run-pass/class-cast-to-iface.rs index 90b3d67cb59..10222acc45a 100644 --- a/src/test/run-pass/class-cast-to-iface.rs +++ b/src/test/run-pass/class-cast-to-iface.rs @@ -2,7 +2,7 @@ iface noisy { fn speak(); } -class cat implements noisy { +class cat : noisy { priv { let mut meows : uint; fn meow() { diff --git a/src/test/run-pass/class-iface-bounded-param.rs b/src/test/run-pass/class-iface-bounded-param.rs index fd0ea20b5fb..4da75037421 100644 --- a/src/test/run-pass/class-iface-bounded-param.rs +++ b/src/test/run-pass/class-iface-bounded-param.rs @@ -2,7 +2,7 @@ use std; import std::map::{map, hashmap, int_hash}; class keys> - implements iter::base_iter { + : iter::base_iter { let map: M; diff --git a/src/test/run-pass/class-impl-parameterized-iface.rs b/src/test/run-pass/class-impl-parameterized-iface.rs index b7533bfe426..dc76b57c2d2 100644 --- a/src/test/run-pass/class-impl-parameterized-iface.rs +++ b/src/test/run-pass/class-impl-parameterized-iface.rs @@ -2,7 +2,7 @@ use std; import std::map::*; -class cat implements map { +class cat : map { priv { // Yes, you can have negative meows let mut meows : int; diff --git a/src/test/run-pass/class-impl-very-parameterized-iface.rs b/src/test/run-pass/class-impl-very-parameterized-iface.rs index 89674fecfa4..30c4be25c60 100644 --- a/src/test/run-pass/class-impl-very-parameterized-iface.rs +++ b/src/test/run-pass/class-impl-very-parameterized-iface.rs @@ -7,7 +7,7 @@ enum cat_type { tuxedo, tabby, tortoiseshell } // for any int value that's less than the meows field // ok: T should be in scope when resolving the iface ref for map -class cat implements map { +class cat : map { priv { // Yes, you can have negative meows let mut meows : int; diff --git a/src/test/run-pass/class-implement-iface-cross-crate.rs b/src/test/run-pass/class-implement-iface-cross-crate.rs index 62f8cdb39f8..5add42fb263 100644 --- a/src/test/run-pass/class-implement-iface-cross-crate.rs +++ b/src/test/run-pass/class-implement-iface-cross-crate.rs @@ -3,7 +3,7 @@ use cci_class_iface; import cci_class_iface::animals::*; -class cat implements noisy { +class cat : noisy { priv { let mut meows : uint; fn meow() { diff --git a/src/test/run-pass/class-implement-ifaces.rs b/src/test/run-pass/class-implement-ifaces.rs index 0dcf3c8104a..f772ef957d7 100644 --- a/src/test/run-pass/class-implement-ifaces.rs +++ b/src/test/run-pass/class-implement-ifaces.rs @@ -2,7 +2,7 @@ iface noisy { fn speak(); } -class cat implements noisy { +class cat : noisy { priv { let mut meows : uint; fn meow() { diff --git a/src/test/run-pass/class-implements-multiple-ifaces.rs b/src/test/run-pass/class-implements-multiple-ifaces.rs index 1a8f7777672..fe3f160c1f8 100644 --- a/src/test/run-pass/class-implements-multiple-ifaces.rs +++ b/src/test/run-pass/class-implements-multiple-ifaces.rs @@ -24,7 +24,7 @@ fn vec_includes(xs: [T], x: T) -> bool { } // vtables other than the 1st one don't seem to work -class cat implements noisy, scratchy, bitey { +class cat : noisy, scratchy, bitey { priv { let meows : @mut uint; let scratched : dvec; diff --git a/src/test/run-pass/cleanup-copy-mode.rs b/src/test/run-pass/cleanup-copy-mode.rs index 0bcd7e65b72..3f5e92cdb75 100644 --- a/src/test/run-pass/cleanup-copy-mode.rs +++ b/src/test/run-pass/cleanup-copy-mode.rs @@ -2,7 +2,7 @@ fn adder(+x: @int, +y: @int) -> int { ret *x + *y; } fn failer() -> @int { fail; } fn main() { - assert(result::is_failure(task::try {|| + assert(result::is_err(task::try {|| adder(@2, failer()); () })); } diff --git a/src/test/run-pass/do-stack.rs b/src/test/run-pass/do-stack.rs new file mode 100644 index 00000000000..c7fec67542d --- /dev/null +++ b/src/test/run-pass/do-stack.rs @@ -0,0 +1,5 @@ +fn f(f: fn&(int)) { f(10) } + +fn main() { + do f() { |i| assert i == 10 } +} diff --git a/src/test/run-pass/issue-506.rs b/src/test/run-pass/issue-506.rs index 6fc5b5ea6eb..458a0b12698 100644 --- a/src/test/run-pass/issue-506.rs +++ b/src/test/run-pass/issue-506.rs @@ -1,9 +1,3 @@ -// xfail-test -// FIXME: This test is no longer testing what it was intended to. It should -// be testing spawning of a native function, but is actually testing -// spawning some other function, then executing a native function. -// #2602 - /* A reduced test case for Issue #506, provided by Rob Arnold. */ @@ -13,9 +7,7 @@ import task; #[abi = "cdecl"] native mod rustrt { - fn task_yield(); + fn rust_task_allow_kill(); } -fn yield_wrap(&&_arg: ()) { rustrt::task_yield(); } - -fn main() { task::spawn((), yield_wrap); } +fn main() { task::spawn(rustrt::rust_task_allow_kill); } diff --git a/src/test/run-pass/task-comm-16.rs b/src/test/run-pass/task-comm-16.rs index 40936ce3a06..d250b311ccc 100644 --- a/src/test/run-pass/task-comm-16.rs +++ b/src/test/run-pass/task-comm-16.rs @@ -52,8 +52,6 @@ fn test_tag() { send(ch, tag1); send(ch, tag2(10)); send(ch, tag3(10, 11u8, 'A')); - // FIXME: Do port semantics really guarantee these happen in order? - // (#2605) let mut t1: t; t1 = recv(po); assert (t1 == tag1);