Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 278276
b: refs/heads/master
c: 5606b42
h: refs/heads/master
  • Loading branch information
birkenfeld committed May 9, 2016
1 parent 6af0ab5 commit ed31211
Show file tree
Hide file tree
Showing 210 changed files with 3,551 additions and 5,513 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
refs/heads/master: 5606b42981e5714b22ff61ec2dcd37414d569287
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
refs/heads/try: e23a651d5cef973ea47d380e8adac86bfcf728db
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Expand Down
16 changes: 2 additions & 14 deletions trunk/mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ TARGET_CRATES := libc std term \
getopts collections test rand \
core alloc \
rustc_unicode rustc_bitflags \
alloc_system alloc_jemalloc \
panic_abort panic_unwind unwind
alloc_system alloc_jemalloc
RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
rustc_data_structures rustc_platform_intrinsics \
Expand All @@ -73,18 +72,10 @@ DEPS_libc := core
DEPS_rand := core
DEPS_rustc_bitflags := core
DEPS_rustc_unicode := core
DEPS_panic_abort := libc alloc
DEPS_panic_unwind := libc alloc unwind
DEPS_unwind := libc

# FIXME(stage0): change this to just `RUSTFLAGS_panic_abort := ...`
RUSTFLAGS1_panic_abort := -C panic=abort
RUSTFLAGS2_panic_abort := -C panic=abort
RUSTFLAGS3_panic_abort := -C panic=abort

DEPS_std := core libc rand alloc collections rustc_unicode \
native:backtrace \
alloc_system panic_abort panic_unwind unwind
alloc_system
DEPS_arena := std
DEPS_glob := std
DEPS_flate := std native:miniz
Expand Down Expand Up @@ -157,9 +148,6 @@ ONLY_RLIB_rustc_unicode := 1
ONLY_RLIB_rustc_bitflags := 1
ONLY_RLIB_alloc_system := 1
ONLY_RLIB_alloc_jemalloc := 1
ONLY_RLIB_panic_unwind := 1
ONLY_RLIB_panic_abort := 1
ONLY_RLIB_unwind := 1

TARGET_SPECIFIC_alloc_jemalloc := 1

Expand Down
3 changes: 1 addition & 2 deletions trunk/mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ DEPS_collectionstest :=
$(eval $(call RUST_CRATE,collectionstest))

TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \
alloc_jemalloc panic_unwind \
panic_abort,$(TARGET_CRATES)) \
alloc_jemalloc,$(TARGET_CRATES)) \
collectionstest coretest
TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \
log rand rbml serialize syntax term test
Expand Down
19 changes: 1 addition & 18 deletions trunk/src/bootstrap/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ fn main() {
} else {
env::var_os("RUSTC_REAL").unwrap()
};
let stage = env::var("RUSTC_STAGE").unwrap();

let mut cmd = Command::new(rustc);
cmd.args(&args)
.arg("--cfg").arg(format!("stage{}", stage));
.arg("--cfg").arg(format!("stage{}", env::var("RUSTC_STAGE").unwrap()));

if let Some(target) = target {
// The stage0 compiler has a special sysroot distinct from what we
Expand All @@ -79,22 +78,6 @@ fn main() {
cmd.args(&s.split(" ").filter(|s| !s.is_empty()).collect::<Vec<_>>());
}

// If we're compiling specifically the `panic_abort` crate then we pass
// the `-C panic=abort` option. Note that we do not do this for any
// other crate intentionally as this is the only crate for now that we
// ship with panic=abort.
//
// This... is a bit of a hack how we detect this. Ideally this
// information should be encoded in the crate I guess? Would likely
// require an RFC amendment to RFC 1513, however.
let is_panic_abort = args.windows(2).any(|a| {
&*a[0] == "--crate-name" && &*a[1] == "panic_abort"
});
// FIXME(stage0): remove this `stage != "0"` condition
if is_panic_abort && stage != "0" {
cmd.arg("-C").arg("panic=abort");
}

// Set various options from config.toml to configure how we're building
// code.
if env::var("RUSTC_DEBUGINFO") == Ok("true".to_string()) {
Expand Down
120 changes: 59 additions & 61 deletions trunk/src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -1573,9 +1573,8 @@ detail on Getopts, but there is [some good documentation][15]
describing it. The short story is that Getopts generates an argument
parser and a help message from a vector of options (The fact that it
is a vector is hidden behind a struct and a set of methods). Once the
parsing is done, the parser returns a struct that records matches
for defined options, and remaining "free" arguments.
From there, we can get information about the flags, for
parsing is done, we can decode the program arguments into a Rust
struct. From there, we can get information about the flags, for
instance, whether they were passed in, and what arguments they
had. Here's our program with the appropriate `extern crate`
statements, and the basic argument setup for Getopts:
Expand Down Expand Up @@ -1606,8 +1605,8 @@ fn main() {
print_usage(&program, opts);
return;
}
let data_path = &matches.free[0];
let city: &str = &matches.free[1];
let data_path = &args[1];
let city = &args[2];
// Do stuff with information
}
Expand Down Expand Up @@ -1681,8 +1680,8 @@ fn main() {
return;
}
let data_path = &matches.free[0];
let city: &str = &matches.free[1];
let data_path = &args[1];
let city: &str = &args[2];
let file = File::open(data_path).unwrap();
let mut rdr = csv::Reader::from_reader(file);
Expand Down Expand Up @@ -1793,15 +1792,13 @@ fn main() {
Ok(m) => { m }
Err(e) => { panic!(e.to_string()) }
};
if matches.opt_present("h") {
print_usage(&program, opts);
return;
}
let data_path = &matches.free[0];
let city: &str = &matches.free[1];
let data_path = &args[1];
let city = &args[2];
for pop in search(data_path, city) {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
Expand Down Expand Up @@ -1879,14 +1876,14 @@ when calling `search`:

```rust,ignore
...
match search(data_path, city) {
Ok(pops) => {
for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
match search(&data_file, &city) {
Ok(pops) => {
for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
Err(err) => println!("{}", err)
}
Err(err) => println!("{}", err)
}
...
```

Expand Down Expand Up @@ -1917,37 +1914,43 @@ fn print_usage(program: &str, opts: Options) {
println!("{}", opts.usage(&format!("Usage: {} [options] <city>", program)));
}
```
Of course we need to adapt the argument handling code:
The next part is going to be only a little harder:

```rust,ignore
...
let mut opts = Options::new();
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
opts.optflag("h", "help", "Show this usage message.");
...
let data_path = matches.opt_str("f");
let city = if !matches.free.is_empty() {
&matches.free[0]
} else {
print_usage(&program, opts);
return;
};
match search(&data_path, city) {
Ok(pops) => {
for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
let mut opts = Options::new();
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
opts.optflag("h", "help", "Show this usage message.");
...
let file = matches.opt_str("f");
let data_file = &file.as_ref().map(Path::new);
let city = if !matches.free.is_empty() {
&matches.free[0]
} else {
print_usage(&program, opts);
return;
};
match search(data_file, city) {
Ok(pops) => {
for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
Err(err) => println!("{}", err)
}
Err(err) => println!("{}", err)
}
...
```

We've made the user experience a bit nicer by showing the usage message,
instead of a panic from an out-of-bounds index, when `city`, the
remaining free argument, is not present.
In this piece of code, we take `file` (which has the type
`Option<String>`), and convert it to a type that `search` can use, in
this case, `&Option<AsRef<Path>>`. To do this, we take a reference of
file, and map `Path::new` onto it. In this case, `as_ref()` converts
the `Option<String>` into an `Option<&str>`, and from there, we can
execute `Path::new` to the content of the optional, and return the
optional of the new value. Once we have that, it is a simple matter of
getting the `city` argument and executing `search`.

Modifying `search` is slightly trickier. The `csv` crate can build a
parser out of
Expand Down Expand Up @@ -1997,8 +2000,6 @@ enum CliError {
And now for impls on `Display` and `Error`:

```rust,ignore
use std::fmt;
impl fmt::Display for CliError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand All @@ -2019,13 +2020,13 @@ impl Error for CliError {
}
}
fn cause(&self) -> Option<&Error> {
match *self {
fn cause(&self) -> Option<&error::Error> {
match *self {
CliError::Io(ref err) => Some(err),
CliError::Csv(ref err) => Some(err),
// Our custom error doesn't have an underlying cause,
// but we could modify it so that it does.
CliError::NotFound => None,
CliError::Parse(ref err) => Some(err),
// Our custom error doesn't have an underlying cause, but we could
// modify it so that it does.
CliError::NotFound() => None,
}
}
}
Expand Down Expand Up @@ -2121,27 +2122,24 @@ string and add a flag to the Option variable. Once we've done that, Getopts does

```rust,ignore
...
let mut opts = Options::new();
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
opts.optflag("h", "help", "Show this usage message.");
opts.optflag("q", "quiet", "Silences errors and warnings.");
let mut opts = Options::new();
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
opts.optflag("h", "help", "Show this usage message.");
opts.optflag("q", "quiet", "Silences errors and warnings.");
...
```

Now we only need to implement our “quiet” functionality. This requires us to
tweak the case analysis in `main`:

```rust,ignore
use std::process;
...
match search(&data_path, city) {
Err(CliError::NotFound) if matches.opt_present("q") => process::exit(1),
Err(err) => panic!("{}", err),
Ok(pops) => for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
match search(&args.arg_data_path, &args.arg_city) {
Err(CliError::NotFound) if args.flag_quiet => process::exit(1),
Err(err) => panic!("{}", err),
Ok(pops) => for pop in pops {
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
}
...
}
```

Certainly, we don't want to be quiet if there was an IO error or if the data
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/doc/book/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ include the newline and the leading spaces:
let s = "foo
bar";

assert_eq!("foo\n bar", s);
assert_eq!("foo\n bar", s);
```

The second, with a `\`, trims the spaces and the newline:
Expand Down
5 changes: 0 additions & 5 deletions trunk/src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2091,8 +2091,6 @@ The following configurations must be defined by the implementation:
* `target_pointer_width = "..."` - Target pointer width in bits. This is set
to `"32"` for targets with 32-bit pointers, and likewise set to `"64"` for
64-bit pointers.
* `target_has_atomic = "..."` - Set of integer sizes on which the target can perform
atomic operations. Values are `"8"`, `"16"`, `"32"`, `"64"` and `"ptr"`.
* `target_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or
simply `"unknown"`.
* `test` - Enabled when compiling the test harness (using the `--test` flag).
Expand Down Expand Up @@ -2297,9 +2295,6 @@ The currently implemented features of the reference compiler are:
* `cfg_target_vendor` - Allows conditional compilation using the `target_vendor`
matcher which is subject to change.

* `cfg_target_has_atomic` - Allows conditional compilation using the `target_has_atomic`
matcher which is subject to change.

* `concat_idents` - Allows use of the `concat_idents` macro, which is in many
ways insufficient for concatenating identifiers, and may be
removed entirely for something more wholesome.
Expand Down
7 changes: 4 additions & 3 deletions trunk/src/liballoc_system/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
form or name",
issue = "27783")]
#![feature(allocator)]
#![feature(libc)]
#![feature(staged_api)]
#![cfg_attr(unix, feature(libc))]

extern crate libc;

// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. In practice, the alignment is a
Expand Down Expand Up @@ -70,10 +72,9 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize {

#[cfg(unix)]
mod imp {
extern crate libc;

use core::cmp;
use core::ptr;
use libc;
use MIN_ALIGN;

pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/libcollectionstest/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_from_utf8() {
String::from("ศไทย中华Việt Nam"));

let xs = b"hello\xFF".to_vec();
let err = String::from_utf8(xs).unwrap_err();
let err = String::from_utf8(xs).err().unwrap();
assert_eq!(err.into_bytes(), b"hello\xff".to_vec());
}

Expand Down
1 change: 0 additions & 1 deletion trunk/src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#![feature(associated_type_defaults)]
#![feature(concat_idents)]
#![feature(const_fn)]
#![feature(cfg_target_has_atomic)]
#![feature(custom_attribute)]
#![feature(fundamental)]
#![feature(inclusive_range_syntax)]
Expand Down
Loading

0 comments on commit ed31211

Please sign in to comment.