diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs
index 2f162db325cd..115ae566c24b 100644
--- a/src/cargo/cargo.rs
+++ b/src/cargo/cargo.rs
@@ -8,7 +8,7 @@ import rustc::metadata::filesearch::{get_cargo_root, get_cargo_root_nearest,
import syntax::diagnostic;
import result::{ok, err};
-import io::writer_util;
+import io::WriterUtil;
import std::{map, json, tempfile, term, sort, getopts};
import map::hashmap;
import to_str::to_str;
diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs
index a37741c2996e..d5cddf0a4e0d 100644
--- a/src/compiletest/procsrv.rs
+++ b/src/compiletest/procsrv.rs
@@ -1,5 +1,5 @@
import run::spawn_process;
-import io::writer_util;
+import io::WriterUtil;
import libc::{c_int, pid_t};
import pipes::chan;
@@ -45,8 +45,8 @@ fn run(lib_path: ~str,
let pipe_out = os::pipe();
let pipe_err = os::pipe();
let pid = spawn_process(prog, args,
- some(env + target_env(lib_path, prog)),
- none, pipe_in.in, pipe_out.out, pipe_err.out);
+ &some(env + target_env(lib_path, prog)),
+ &none, pipe_in.in, pipe_out.out, pipe_err.out);
os::close(pipe_in.in);
os::close(pipe_out.out);
diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs
index 7a2d3456ed68..a6800053966c 100644
--- a/src/compiletest/runtest.rs
+++ b/src/compiletest/runtest.rs
@@ -1,4 +1,4 @@
-import io::writer_util;
+import io::WriterUtil;
import common::mode_run_pass;
import common::mode_run_fail;
@@ -339,7 +339,7 @@ fn compose_and_run_compiler(
config.compile_lib_path, input)
}
-fn ensure_dir(path: path) {
+fn ensure_dir(path: Path) {
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
fail fmt!{"can't make dir %s", path};
@@ -455,7 +455,7 @@ fn dump_output_file(config: config, testfile: ~str,
out: ~str, extension: ~str) {
let outfile = make_out_name(config, testfile, extension);
let writer = result::get(
- io::file_writer(outfile, ~[io::create, io::truncate]));
+ io::file_writer(outfile, ~[io::Create, io::Truncate]));
writer.write_str(out);
}
diff --git a/src/etc/combine-tests.py b/src/etc/combine-tests.py
index 38c69bf6af0e..028fc4732e0d 100755
--- a/src/etc/combine-tests.py
+++ b/src/etc/combine-tests.py
@@ -54,7 +54,7 @@ d.write("// AUTO-GENERATED FILE: DO NOT EDIT\n")
d.write("use std;\n")
d.write("use run_pass_stage2;\n")
d.write("import run_pass_stage2::*;\n")
-d.write("import io::writer_util;\n");
+d.write("import io::WriterUtil;\n");
d.write("fn main() {\n");
d.write(" let out = io::stdout();\n");
i = 0
diff --git a/src/etc/emacs/README.md b/src/etc/emacs/README.md
index 7bfeebeef6ba..b9f11d881ab2 100644
--- a/src/etc/emacs/README.md
+++ b/src/etc/emacs/README.md
@@ -4,7 +4,10 @@ rust-mode: A major emacs mode for editing Rust source code
`rust-mode` makes editing [Rust](http://rust-lang.org) code with emacs
enjoyable.
-To install, check out this repository and add this to your .emacs
+
+### Manual Installation
+
+To install manually, check out this repository and add this to your .emacs
file:
(add-to-list 'load-path "/path/to/rust-mode/")
@@ -25,3 +28,60 @@ it, and pressing `C-j`:
Rust mode will automatically be associated with .rs and .rc files. To
enable it explicitly, do `M-x rust-mode`.
+
+### package.el installation via Marmalade
+
+It can be more convenient to use Emacs's package manager to handle
+installation for you if you use many elisp libraries. If you have
+package.el but haven't added Marmalade, the community package source,
+yet, add this to ~/.emacs.d/init.el:
+
+```lisp
+(require 'package)
+(add-to-list 'package-archives
+ '("marmalade" . "http://marmalade-repo.org/packages/"))
+(package-initialize)
+```
+
+Then do this to load the package listing:
+
+* M-x eval-buffer
+* M-x package-refresh-contents
+
+If you use a version of Emacs prior to 24 that doesn't include
+package.el, you can get it from http://bit.ly/pkg-el23.
+
+If you have an older ELPA package.el installed from tromey.com, you
+should upgrade in order to support installation from multiple sources.
+The ELPA archive is deprecated and no longer accepting new packages,
+so the version there (1.7.1) is very outdated.
+
+From there you can install rust-mode or any other modes by choosing
+them from a list:
+
+* M-x package-list-packages
+
+Now, to install packages, move your cursor to them and press i. This
+will mark the packages for installation. When you're done with
+marking, press x, and ELPA will install the packages for you (under
+~/.emacs.d/elpa/).
+
+* or using M-x package-install rust-mode
+
+#### Important
+
+In order to have cm-mode properly initialized after compilation prior
+to rust-mode.el compilation you will need to add these `advices` to
+your init file or if you are a melpa user install the `melpa` package.
+
+```lisp
+(defadvice package-download-tar
+ (after package-download-tar-initialize activate compile)
+ "initialize the package after compilation"
+ (package-initialize))
+
+(defadvice package-download-single
+ (after package-download-single-initialize activate compile)
+ "initialize the package after compilation"
+ (package-initialize))
+```
diff --git a/src/etc/emacs/cm-mode.el b/src/etc/emacs/cm-mode.el
index f1dcfea28fc1..0303f994172c 100644
--- a/src/etc/emacs/cm-mode.el
+++ b/src/etc/emacs/cm-mode.el
@@ -1,8 +1,8 @@
;;; cm-mode.el --- Wrapper for CodeMirror-style Emacs modes
;; Version: 0.1.0
+;; Author: Mozilla
;; Url: https://github.com/mozilla/rust
-
;; Highlighting is done by running a stateful parser (with first-class
;; state object) over the buffer, line by line, using the output to
;; add 'face properties, and storing the parser state at the end of
diff --git a/src/etc/emacs/rust-mode.el b/src/etc/emacs/rust-mode.el
index b340c39dbd31..6c118da40e0b 100644
--- a/src/etc/emacs/rust-mode.el
+++ b/src/etc/emacs/rust-mode.el
@@ -1,6 +1,7 @@
;;; rust-mode.el --- A major emacs mode for editing Rust source code
;; Version: 0.1.0
+;; Author: Mozilla
;; Package-Requires: ((cm-mode "0.1.0"))
;; Url: https://github.com/mozilla/rust
diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs
index 956e48396fcb..352831c86e62 100644
--- a/src/fuzzer/fuzzer.rs
+++ b/src/fuzzer/fuzzer.rs
@@ -1,4 +1,4 @@
-import io::writer_util;
+import io::WriterUtil;
import syntax::{ast, ast_util, fold, visit, codemap};
import syntax::parse;
@@ -10,7 +10,7 @@ type context = { mode: test_mode }; // + rng
fn write_file(filename: ~str, content: ~str) {
result::get(
- io::file_writer(filename, ~[io::create, io::truncate]))
+ io::file_writer(filename, ~[io::Create, io::Truncate]))
.write_str(content);
}
@@ -216,9 +216,9 @@ fn under(n: uint, it: fn(uint)) {
while i < n { it(i); i += 1u; }
}
-fn devnull() -> io::writer { io::mem_buffer_writer(io::mem_buffer()) }
+fn devnull() -> io::Writer { io::mem_buffer_writer(io::mem_buffer()) }
-fn as_str(f: fn@(io::writer)) -> ~str {
+fn as_str(f: fn@(io::Writer)) -> ~str {
let buf = io::mem_buffer();
f(io::mem_buffer_writer(buf));
io::mem_buffer_str(buf)
diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs
index 4fcdad60146c..38bdc4075477 100644
--- a/src/libcore/comm.rs
+++ b/src/libcore/comm.rs
@@ -1,3 +1,6 @@
+// NB: transitionary, de-mode-ing.
+#[forbid(deprecated_mode)];
+#[forbid(deprecated_pattern)];
/*!
* Communication between tasks
*
@@ -162,7 +165,7 @@ fn chan(p: port) -> chan {
* Sends data over a channel. The sent data is moved into the channel,
* whereupon the caller loses access to it.
*/
-fn send(ch: chan, -data: T) {
+fn send(ch: chan, +data: T) {
let chan_t(p) = ch;
let data_ptr = ptr::addr_of(data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr);
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index 96324c1b2974..f5c9039ad25c 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -54,6 +54,7 @@ export send_map;
export hash;
export cmp;
export num;
+export path;
// NDM seems to be necessary for resolve to work
export option_iter;
@@ -214,11 +215,16 @@ mod pipes;
// Runtime and language-primitive support
+#[warn(non_camel_case_types)]
mod io;
mod libc;
+#[warn(non_camel_case_types)]
mod os;
+#[warn(non_camel_case_types)]
mod path;
+#[warn(non_camel_case_types)]
mod rand;
+#[warn(non_camel_case_types)]
mod run;
#[warn(non_camel_case_types)]
mod sys;
diff --git a/src/libcore/core.rs b/src/libcore/core.rs
index 2f5e2cf6e0be..f6a721d102ab 100644
--- a/src/libcore/core.rs
+++ b/src/libcore/core.rs
@@ -4,7 +4,7 @@
import option::{some, none};
import option = option::option;
-import path = path::path;
+import Path = path::Path;
import tuple::{TupleOps, ExtendedTupleOps};
import str::{str_slice, unique_str};
import vec::{const_vector, copyable_vector, immutable_vector};
@@ -14,7 +14,7 @@ import num::Num;
import ptr::ptr;
import to_str::ToStr;
-export path, option, some, none, unreachable;
+export Path, option, some, none, unreachable;
export extensions;
// The following exports are the extension impls for numeric types
export Num, times, timesi;
diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs
index d261d537235d..2237dad299fe 100644
--- a/src/libcore/hash.rs
+++ b/src/libcore/hash.rs
@@ -1,3 +1,7 @@
+// NB: transitionary, de-mode-ing.
+#[forbid(deprecated_mode)];
+#[forbid(deprecated_pattern)];
+
/*!
* Implementation of SipHash 2-4
*
@@ -9,8 +13,8 @@
* CPRNG like rand::rng.
*/
-import io::writer;
-import io::writer_util;
+import io::Writer;
+import io::WriterUtil;
export Streaming, State;
export default_state;
@@ -122,7 +126,7 @@ fn SipState(key0: u64, key1: u64) -> SipState {
}
-impl &SipState : io::writer {
+impl &SipState : io::Writer {
// Methods for io::writer
fn write(msg: &[const u8]) {
@@ -205,7 +209,7 @@ impl &SipState : io::writer {
self.ntail = left;
}
- fn seek(_x: int, _s: io::seek_style) {
+ fn seek(_x: int, _s: io::SeekStyle) {
fail;
}
fn tell() -> uint {
@@ -214,8 +218,8 @@ impl &SipState : io::writer {
fn flush() -> int {
0
}
- fn get_type() -> io::writer_type {
- io::file
+ fn get_type() -> io::WriterType {
+ io::File
}
}
@@ -362,9 +366,9 @@ fn test_siphash() {
let stream_inc = &State(k0,k1);
let stream_full = &State(k0,k1);
- fn to_hex_str(r:[u8]/8) -> ~str {
+ fn to_hex_str(r: &[u8]/8) -> ~str {
let mut s = ~"";
- for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); }
+ for vec::each(*r) |b| { s += uint::to_str(b as uint, 16u); }
return s;
}
@@ -379,7 +383,7 @@ fn test_siphash() {
stream_full.input(buf);
let f = stream_full.result_str();
let i = stream_inc.result_str();
- let v = to_hex_str(vecs[t]);
+ let v = to_hex_str(&vecs[t]);
debug!{"%d: (%s) => inc=%s full=%s", t, v, i, f};
assert f == i && f == v;
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 571fc8587ef8..c01672b5c738 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -11,6 +11,7 @@ import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
import libc::consts::os::posix88::*;
import libc::consts::os::extra::*;
+#[allow(non_camel_case_types)] // not sure what to do about this
type fd_t = c_int;
#[abi = "cdecl"]
@@ -24,11 +25,11 @@ extern mod rustrt {
// FIXME (#2004): This is all buffered. We might need an unbuffered variant
// as well
-enum seek_style { seek_set, seek_end, seek_cur, }
+enum SeekStyle { SeekSet, SeekEnd, SeekCur, }
// The raw underlying reader trait. All readers must implement this.
-trait reader {
+trait Reader {
// FIXME (#2004): Seekable really should be orthogonal.
// FIXME (#2982): This should probably return an error.
@@ -36,13 +37,13 @@ trait reader {
fn read_byte() -> int;
fn unread_byte(int);
fn eof() -> bool;
- fn seek(int, seek_style);
+ fn seek(int, SeekStyle);
fn tell() -> uint;
}
// Generic utility functions defined on readers
-impl reader {
+impl Reader {
fn read_bytes(len: uint) -> ~[u8] {
let mut buf = ~[mut];
vec::reserve(buf, len);
@@ -195,15 +196,15 @@ impl reader {
// Reader implementations
-fn convert_whence(whence: seek_style) -> i32 {
+fn convert_whence(whence: SeekStyle) -> i32 {
return match whence {
- seek_set => 0i32,
- seek_cur => 1i32,
- seek_end => 2i32
+ SeekSet => 0i32,
+ SeekCur => 1i32,
+ SeekEnd => 2i32
};
}
-impl *libc::FILE: reader {
+impl *libc::FILE: Reader {
fn read(buf: &[mut u8], len: uint) -> uint {
do vec::as_buf(buf) |buf_p, buf_len| {
assert buf_len <= len;
@@ -217,7 +218,7 @@ impl *libc::FILE: reader {
fn read_byte() -> int { return libc::fgetc(self) as int; }
fn unread_byte(byte: int) { libc::ungetc(byte as c_int, self); }
fn eof() -> bool { return libc::feof(self) != 0 as c_int; }
- fn seek(offset: int, whence: seek_style) {
+ fn seek(offset: int, whence: SeekStyle) {
assert libc::fseek(self, offset as c_long, convert_whence(whence))
== 0 as c_int;
}
@@ -227,26 +228,26 @@ impl *libc::FILE: reader {
// A forwarding impl of reader that also holds on to a resource for the
// duration of its lifetime.
// FIXME there really should be a better way to do this // #2004
-impl {base: T, cleanup: C}: reader {
+impl {base: T, cleanup: C}: Reader {
fn read(buf: &[mut u8], len: uint) -> uint { self.base.read(buf, len) }
fn read_byte() -> int { self.base.read_byte() }
fn unread_byte(byte: int) { self.base.unread_byte(byte); }
fn eof() -> bool { self.base.eof() }
- fn seek(off: int, whence: seek_style) { self.base.seek(off, whence) }
+ fn seek(off: int, whence: SeekStyle) { self.base.seek(off, whence) }
fn tell() -> uint { self.base.tell() }
}
-class FILE_res {
+class FILERes {
let f: *libc::FILE;
new(f: *libc::FILE) { self.f = f; }
drop { libc::fclose(self.f); }
}
-fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
+fn FILE_reader(f: *libc::FILE, cleanup: bool) -> Reader {
if cleanup {
- {base: f, cleanup: FILE_res(f)} as reader
+ {base: f, cleanup: FILERes(f)} as Reader
} else {
- f as reader
+ f as Reader
}
}
@@ -254,9 +255,9 @@ fn FILE_reader(f: *libc::FILE, cleanup: bool) -> reader {
// top-level functions that take a reader, or a set of default methods on
// reader (which can then be called reader)
-fn stdin() -> reader { rustrt::rust_get_stdin() as reader }
+fn stdin() -> Reader { rustrt::rust_get_stdin() as Reader }
-fn file_reader(path: ~str) -> result {
+fn file_reader(path: ~str) -> result {
let f = os::as_c_charp(path, |pathbuf| {
os::as_c_charp(~"r", |modebuf|
libc::fopen(pathbuf, modebuf)
@@ -271,9 +272,9 @@ fn file_reader(path: ~str) -> result {
// Byte buffer readers
-type byte_buf = {buf: ~[const u8], mut pos: uint, len: uint};
+type ByteBuf = {buf: ~[const u8], mut pos: uint, len: uint};
-impl byte_buf: reader {
+impl ByteBuf: Reader {
fn read(buf: &[mut u8], len: uint) -> uint {
let count = uint::min(len, self.len - self.pos);
@@ -293,65 +294,65 @@ impl byte_buf: reader {
// FIXME (#2738): implement this
fn unread_byte(_byte: int) { error!{"Unimplemented: unread_byte"}; fail; }
fn eof() -> bool { self.pos == self.len }
- fn seek(offset: int, whence: seek_style) {
+ fn seek(offset: int, whence: SeekStyle) {
let pos = self.pos;
self.pos = seek_in_buf(offset, pos, self.len, whence);
}
fn tell() -> uint { self.pos }
}
-fn bytes_reader(bytes: ~[u8]) -> reader {
+fn bytes_reader(bytes: ~[u8]) -> Reader {
bytes_reader_between(bytes, 0u, vec::len(bytes))
}
-fn bytes_reader_between(bytes: ~[u8], start: uint, end: uint) -> reader {
- {buf: bytes, mut pos: start, len: end} as reader
+fn bytes_reader_between(bytes: ~[u8], start: uint, end: uint) -> Reader {
+ {buf: bytes, mut pos: start, len: end} as Reader
}
-fn with_bytes_reader(bytes: ~[u8], f: fn(reader) -> t) -> t {
+fn with_bytes_reader(bytes: ~[u8], f: fn(Reader) -> t) -> t {
f(bytes_reader(bytes))
}
fn with_bytes_reader_between(bytes: ~[u8], start: uint, end: uint,
- f: fn(reader) -> t) -> t {
+ f: fn(Reader) -> t) -> t {
f(bytes_reader_between(bytes, start, end))
}
-fn str_reader(s: ~str) -> reader {
+fn str_reader(s: ~str) -> Reader {
bytes_reader(str::bytes(s))
}
-fn with_str_reader(s: ~str, f: fn(reader) -> T) -> T {
+fn with_str_reader(s: ~str, f: fn(Reader) -> T) -> T {
do str::as_bytes(s) |bytes| {
with_bytes_reader_between(bytes, 0u, str::len(s), f)
}
}
// Writing
-enum fileflag { append, create, truncate, no_flag, }
+enum FileFlag { Append, Create, Truncate, NoFlag, }
// What type of writer are we?
-enum writer_type { screen, file }
+enum WriterType { Screen, File }
// FIXME (#2004): Seekable really should be orthogonal.
// FIXME (#2004): eventually u64
-trait writer {
+trait Writer {
fn write(v: &[const u8]);
- fn seek(int, seek_style);
+ fn seek(int, SeekStyle);
fn tell() -> uint;
fn flush() -> int;
- fn get_type() -> writer_type;
+ fn get_type() -> WriterType;
}
-impl {base: T, cleanup: C}: writer {
+impl {base: T, cleanup: C}: Writer {
fn write(bs: &[const u8]) { self.base.write(bs); }
- fn seek(off: int, style: seek_style) { self.base.seek(off, style); }
+ fn seek(off: int, style: SeekStyle) { self.base.seek(off, style); }
fn tell() -> uint { self.base.tell() }
fn flush() -> int { self.base.flush() }
- fn get_type() -> writer_type { file }
+ fn get_type() -> WriterType { File }
}
-impl *libc::FILE: writer {
+impl *libc::FILE: Writer {
fn write(v: &[const u8]) {
do vec::as_const_buf(v) |vbuf, len| {
let nout = libc::fwrite(vbuf as *c_void, len as size_t,
@@ -363,28 +364,28 @@ impl *libc::FILE: writer {
}
}
}
- fn seek(offset: int, whence: seek_style) {
+ fn seek(offset: int, whence: SeekStyle) {
assert libc::fseek(self, offset as c_long, convert_whence(whence))
== 0 as c_int;
}
fn tell() -> uint { libc::ftell(self) as uint }
fn flush() -> int { libc::fflush(self) as int }
- fn get_type() -> writer_type {
+ fn get_type() -> WriterType {
let fd = libc::fileno(self);
- if libc::isatty(fd) == 0 { file }
- else { screen }
+ if libc::isatty(fd) == 0 { File }
+ else { Screen }
}
}
-fn FILE_writer(f: *libc::FILE, cleanup: bool) -> writer {
+fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer {
if cleanup {
- {base: f, cleanup: FILE_res(f)} as writer
+ {base: f, cleanup: FILERes(f)} as Writer
} else {
- f as writer
+ f as Writer
}
}
-impl fd_t: writer {
+impl fd_t: Writer {
fn write(v: &[const u8]) {
let mut count = 0u;
do vec::as_const_buf(v) |vbuf, len| {
@@ -400,7 +401,7 @@ impl fd_t: writer {
}
}
}
- fn seek(_offset: int, _whence: seek_style) {
+ fn seek(_offset: int, _whence: SeekStyle) {
error!{"need 64-bit foreign calls for seek, sorry"};
fail;
}
@@ -409,28 +410,28 @@ impl fd_t: writer {
fail;
}
fn flush() -> int { 0 }
- fn get_type() -> writer_type {
- if libc::isatty(self) == 0 { file } else { screen }
+ fn get_type() -> WriterType {
+ if libc::isatty(self) == 0 { File } else { Screen }
}
}
-class fd_res {
+class FdRes {
let fd: fd_t;
new(fd: fd_t) { self.fd = fd; }
drop { libc::close(self.fd); }
}
-fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
+fn fd_writer(fd: fd_t, cleanup: bool) -> Writer {
if cleanup {
- {base: fd, cleanup: fd_res(fd)} as writer
+ {base: fd, cleanup: FdRes(fd)} as Writer
} else {
- fd as writer
+ fd as Writer
}
}
-fn mk_file_writer(path: ~str, flags: ~[fileflag])
- -> result {
+fn mk_file_writer(path: ~str, flags: ~[FileFlag])
+ -> result {
#[cfg(windows)]
fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
@@ -441,10 +442,10 @@ fn mk_file_writer(path: ~str, flags: ~[fileflag])
let mut fflags: c_int = wb();
for vec::each(flags) |f| {
match f {
- append => fflags |= O_APPEND as c_int,
- create => fflags |= O_CREAT as c_int,
- truncate => fflags |= O_TRUNC as c_int,
- no_flag => ()
+ Append => fflags |= O_APPEND as c_int,
+ Create => fflags |= O_CREAT as c_int,
+ Truncate => fflags |= O_TRUNC as c_int,
+ NoFlag => ()
}
}
let fd = do os::as_c_charp(path) |pathbuf| {
@@ -535,7 +536,7 @@ fn u64_from_be_bytes(data: ~[u8], start: uint, size: uint) -> u64 {
// FIXME: #3048 combine trait+impl (or just move these to
// default methods on writer)
-trait writer_util {
+trait WriterUtil {
fn write_char(ch: char);
fn write_str(s: &str);
fn write_line(s: &str);
@@ -560,7 +561,7 @@ trait writer_util {
fn write_u8(n: u8);
}
-impl T : writer_util {
+impl T : WriterUtil {
fn write_char(ch: char) {
if ch as uint < 128u {
self.write(&[ch as u8]);
@@ -631,13 +632,13 @@ impl T : writer_util {
fn write_u8(n: u8) { self.write(&[n]) }
}
-fn file_writer(path: ~str, flags: ~[fileflag]) -> result {
+fn file_writer(path: ~str, flags: ~[FileFlag]) -> result {
result::chain(mk_file_writer(path, flags), |w| result::ok(w))
}
// FIXME: fileflags // #2004
-fn buffered_file_writer(path: ~str) -> result {
+fn buffered_file_writer(path: ~str) -> result {
let f = do os::as_c_charp(path) |pathbuf| {
do os::as_c_charp(~"w") |modebuf| {
libc::fopen(pathbuf, modebuf)
@@ -650,15 +651,15 @@ fn buffered_file_writer(path: ~str) -> result {
// FIXME (#2004) it would be great if this could be a const
// FIXME (#2004) why are these different from the way stdin() is
// implemented?
-fn stdout() -> writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
-fn stderr() -> writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
+fn stdout() -> Writer { fd_writer(libc::STDOUT_FILENO as c_int, false) }
+fn stderr() -> Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
fn print(s: &str) { stdout().write_str(s); }
fn println(s: &str) { stdout().write_line(s); }
-type mem_buffer = @{buf: dvec, mut pos: uint};
+type MemBuffer = @{buf: dvec, mut pos: uint};
-impl mem_buffer: writer {
+impl MemBuffer: Writer {
fn write(v: &[const u8]) {
// Fast path.
let vlen = vec::len(v);
@@ -679,33 +680,33 @@ impl mem_buffer: writer {
self.buf.push_slice(v, vpos, vlen);
self.pos += vlen;
}
- fn seek(offset: int, whence: seek_style) {
+ fn seek(offset: int, whence: SeekStyle) {
let pos = self.pos;
let len = self.buf.len();
self.pos = seek_in_buf(offset, pos, len, whence);
}
fn tell() -> uint { self.pos }
fn flush() -> int { 0 }
- fn get_type() -> writer_type { file }
+ fn get_type() -> WriterType { File }
}
-fn mem_buffer() -> mem_buffer {
+fn mem_buffer() -> MemBuffer {
@{buf: dvec(), mut pos: 0u}
}
-fn mem_buffer_writer(b: mem_buffer) -> writer { b as writer }
-fn mem_buffer_buf(b: mem_buffer) -> ~[u8] { b.buf.get() }
-fn mem_buffer_str(b: mem_buffer) -> ~str {
+fn mem_buffer_writer(b: MemBuffer) -> Writer { b as Writer }
+fn mem_buffer_buf(b: MemBuffer) -> ~[u8] { b.buf.get() }
+fn mem_buffer_str(b: MemBuffer) -> ~str {
str::from_bytes(b.buf.get())
}
-fn with_str_writer(f: fn(writer)) -> ~str {
+fn with_str_writer(f: fn(Writer)) -> ~str {
let buf = mem_buffer();
let wr = mem_buffer_writer(buf);
f(wr);
io::mem_buffer_str(buf)
}
-fn with_buf_writer(f: fn(writer)) -> ~[u8] {
+fn with_buf_writer(f: fn(Writer)) -> ~[u8] {
let buf = mem_buffer();
let wr = mem_buffer_writer(buf);
f(wr);
@@ -713,14 +714,14 @@ fn with_buf_writer(f: fn(writer)) -> ~[u8] {
}
// Utility functions
-fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) ->
+fn seek_in_buf(offset: int, pos: uint, len: uint, whence: SeekStyle) ->
uint {
let mut bpos = pos as int;
let blen = len as int;
match whence {
- seek_set => bpos = offset,
- seek_cur => bpos += offset,
- seek_end => bpos = blen + offset
+ SeekSet => bpos = offset,
+ SeekCur => bpos += offset,
+ SeekEnd => bpos = blen + offset
}
if bpos < 0 { bpos = 0; } else if bpos > blen { bpos = blen; }
return bpos as uint;
@@ -748,24 +749,24 @@ fn read_whole_file(file: ~str) -> result<~[u8], ~str> {
mod fsync {
- enum level {
+ enum Level {
// whatever fsync does on that platform
- fsync,
+ FSync,
// fdatasync on linux, similiar or more on other platforms
- fdatasync,
+ FDataSync,
// full fsync
//
// You must additionally sync the parent directory as well!
- fullfsync,
+ FullFSync,
}
// Artifacts that need to fsync on destruction
- class res {
- let arg: arg;
- new(-arg: arg) { self.arg <- arg; }
+ class Res {
+ let arg: Arg;
+ new(-arg: Arg) { self.arg <- arg; }
drop {
match self.arg.opt_level {
option::none => (),
@@ -777,44 +778,47 @@ mod fsync {
}
}
- type arg = {
+ type Arg = {
val: t,
- opt_level: option,
- fsync_fn: fn@(t, level) -> int
+ opt_level: option,
+ fsync_fn: fn@(t, Level) -> int
};
// fsync file after executing blk
// FIXME (#2004) find better way to create resources within lifetime of
// outer res
- fn FILE_res_sync(&&file: FILE_res, opt_level: option,
- blk: fn(&&res<*libc::FILE>)) {
- blk(res({
+ fn FILE_res_sync(&&file: FILERes, opt_level: option,
+ blk: fn(&&Res<*libc::FILE>)) {
+ blk(Res({
val: file.f, opt_level: opt_level,
- fsync_fn: fn@(&&file: *libc::FILE, l: level) -> int {
+ fsync_fn: fn@(&&file: *libc::FILE, l: Level) -> int {
return os::fsync_fd(libc::fileno(file), l) as int;
}
}));
}
// fsync fd after executing blk
- fn fd_res_sync(&&fd: fd_res, opt_level: option,
- blk: fn(&&res)) {
- blk(res({
+ fn fd_res_sync(&&fd: FdRes, opt_level: option,
+ blk: fn(&&Res)) {
+ blk(Res({
val: fd.fd, opt_level: opt_level,
- fsync_fn: fn@(&&fd: fd_t, l: level) -> int {
+ fsync_fn: fn@(&&fd: fd_t, l: Level) -> int {
return os::fsync_fd(fd, l) as int;
}
}));
}
// Type of objects that may want to fsync
- trait t { fn fsync(l: level) -> int; }
+ trait FSyncable { fn fsync(l: Level) -> int; }
// Call o.fsync after executing blk
- fn obj_sync(&&o: t, opt_level: option, blk: fn(&&res)) {
- blk(res({
+ fn obj_sync(&&o: FSyncable, opt_level: option,
+ blk: fn(&&Res)) {
+ blk(Res({
val: o, opt_level: opt_level,
- fsync_fn: fn@(&&o: t, l: level) -> int { return o.fsync(l); }
+ fsync_fn: fn@(&&o: FSyncable, l: Level) -> int {
+ return o.fsync(l);
+ }
}));
}
}
@@ -830,12 +834,12 @@ mod tests {
~"A hoopy frood who really knows where his towel is.";
log(debug, frood);
{
- let out: io::writer =
+ let out: io::Writer =
result::get(
- io::file_writer(tmpfile, ~[io::create, io::truncate]));
+ io::file_writer(tmpfile, ~[io::Create, io::Truncate]));
out.write_str(frood);
}
- let inp: io::reader = result::get(io::file_reader(tmpfile));
+ let inp: io::Reader = result::get(io::file_reader(tmpfile));
let frood2: ~str = inp.read_c_str();
log(debug, frood2);
assert frood == frood2;
@@ -843,7 +847,7 @@ mod tests {
#[test]
fn test_readchars_empty() {
- let inp : io::reader = io::str_reader(~"");
+ let inp : io::Reader = io::str_reader(~"");
let res : ~[char] = inp.read_chars(128u);
assert(vec::len(res) == 0u);
}
@@ -858,7 +862,7 @@ mod tests {
29983, 38152, 30340, 27748,
21273, 20999, 32905, 27748];
fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) {
- let inp : io::reader = io::str_reader(s);
+ let inp : io::Reader = io::str_reader(s);
let res : ~[char] = inp.read_chars(len);
if (len <= vec::len(ivals)) {
assert(vec::len(res) == len);
@@ -877,14 +881,14 @@ mod tests {
#[test]
fn test_readchar() {
- let inp : io::reader = io::str_reader(~"生");
+ let inp : io::Reader = io::str_reader(~"生");
let res : char = inp.read_char();
assert(res as int == 29983);
}
#[test]
fn test_readchar_empty() {
- let inp : io::reader = io::str_reader(~"");
+ let inp : io::Reader = io::str_reader(~"");
let res : char = inp.read_char();
assert(res as int == -1);
}
@@ -924,12 +928,12 @@ mod tests {
let mbuf = mem_buffer();
mbuf.write(~[0u8, 1u8, 2u8, 3u8]);
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 2u8, 3u8];
- mbuf.seek(-2, seek_cur);
+ mbuf.seek(-2, SeekCur);
mbuf.write(~[4u8, 5u8, 6u8, 7u8]);
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8];
- mbuf.seek(-2, seek_end);
+ mbuf.seek(-2, SeekEnd);
mbuf.write(~[8u8]);
- mbuf.seek(1, seek_set);
+ mbuf.seek(1, SeekSet);
mbuf.write(~[9u8]);
assert mem_buffer_buf(mbuf) == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8];
}
diff --git a/src/libcore/libc.rs b/src/libcore/libc.rs
index 740a78a6d9ce..09dd614525ed 100644
--- a/src/libcore/libc.rs
+++ b/src/libcore/libc.rs
@@ -1,3 +1,6 @@
+// NB: transitionary, de-mode-ing.
+#[forbid(deprecated_mode)];
+#[forbid(deprecated_pattern)];
/*!
* Bindings for libc.
*
@@ -34,6 +37,8 @@
* dissolved.
*/
+#[allow(non_camel_case_types)];
+
// Initial glob-exports mean that all the contents of all the modules
// wind up exported, if you're interested in writing platform-specific code.
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index d68401fadbe9..2f86e1be4957 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -46,7 +46,13 @@ pure fn map(opt: option, f: fn(T) -> U) -> option {
match opt { some(x) => some(f(x)), none => none }
}
-pure fn map_consume(-opt: option, f: fn(-T) -> U) -> option {
+pure fn map_ref(opt: &option, f: fn(x: &T) -> U) -> option {
+ //! Maps a `some` value by reference from one type to another
+
+ match *opt { some(ref x) => some(f(x)), none => none }
+}
+
+pure fn map_consume(+opt: option, f: fn(+T) -> U) -> option {
/*!
* As `map`, but consumes the option and gives `f` ownership to avoid
* copying.
@@ -63,6 +69,16 @@ pure fn chain(opt: option, f: fn(T) -> option) -> option {
match opt { some(x) => f(x), none => none }
}
+pure fn chain_ref(opt: &option,
+ f: fn(x: &T) -> option) -> option {
+ /*!
+ * Update an optional value by optionally running its content by reference
+ * through a function that returns an option.
+ */
+
+ match *opt { some(ref x) => f(x), none => none }
+}
+
#[inline(always)]
pure fn while_some(+x: option, blk: fn(+T) -> option) {
//! Applies a function zero or more times until the result is none.
@@ -97,14 +113,28 @@ pure fn map_default(opt: option, +def: U, f: fn(T) -> U) -> U {
match opt { none => def, some(t) => f(t) }
}
+// This should replace map_default.
+pure fn map_default_ref(opt: &option, +def: U,
+ f: fn(x: &T) -> U) -> U {
+ //! Applies a function to the contained value or returns a default
+
+ match *opt { none => def, some(ref t) => f(t) }
+}
+
+// This should change to by-copy mode; use iter_ref below for by reference
pure fn iter(opt: option, f: fn(T)) {
//! Performs an operation on the contained value or does nothing
match opt { none => (), some(t) => f(t) }
}
+pure fn iter_ref(opt: &option, f: fn(x: &T)) {
+ //! Performs an operation on the contained value by reference
+ match *opt { none => (), some(ref t) => f(t) }
+}
+
#[inline(always)]
-pure fn unwrap(-opt: option) -> T {
+pure fn unwrap(+opt: option) -> T {
/*!
* Moves a value out of an option type and returns it.
*
@@ -130,12 +160,13 @@ fn swap_unwrap(opt: &mut option) -> T {
unwrap(util::replace(opt, none))
}
-pure fn unwrap_expect(-opt: option, reason: &str) -> T {
+pure fn unwrap_expect(+opt: option, reason: &str) -> T {
//! As unwrap, but with a specified failure message.
if opt.is_none() { fail reason.to_unique(); }
unwrap(opt)
}
+// Some of these should change to be &option, some should not. See below.
impl option {
/**
* Update an optional value by optionally running its content through a
@@ -155,6 +186,23 @@ impl option {
pure fn map(f: fn(T) -> U) -> option { map(self, f) }
}
+impl &option {
+ /**
+ * Update an optional value by optionally running its content by reference
+ * through a function that returns an option.
+ */
+ pure fn chain_ref(f: fn(x: &T) -> option) -> option {
+ chain_ref(self, f)
+ }
+ /// Applies a function to the contained value or returns a default
+ pure fn map_default_ref(+def: U, f: fn(x: &T) -> U) -> U
+ { map_default_ref(self, def, f) }
+ /// Performs an operation on the contained value by reference
+ pure fn iter_ref(f: fn(x: &T)) { iter_ref(self, f) }
+ /// Maps a `some` value from one type to another by reference
+ pure fn map_ref(f: fn(x: &T) -> U) -> option { map_ref(self, f) }
+}
+
impl option {
/**
* Gets the value out of an option
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index c080088674a8..ec4485bb1233 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -134,34 +134,34 @@ mod global_env {
fn rust_global_env_chan_ptr() -> *libc::uintptr_t;
}
- enum msg {
- msg_getenv(~str, comm::chan