Skip to content

Commit 6d369a8

Browse files
committed
Auto merge of #33501 - Manishearth:rollup, r=Manishearth
Rollup of 9 pull requests - Successful merges: #32900, #33129, #33365, #33383, #33474, #33478, #33480, #33484, #33493 - Failed merges: #33360
2 parents ebe6da3 + 24ff1e0 commit 6d369a8

File tree

105 files changed

+2657
-1039
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+2657
-1039
lines changed

Makefile.in

+2-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@
5959
# * check-stage$(stage)-$(crate) - Test a crate in a specific stage
6060
# * check-stage$(stage)-{rpass,rfail,cfail,rmake,...} - Run tests in src/test/
6161
# * check-stage1-T-$(target)-H-$(host) - Run cross-compiled-tests
62-
# * tidy-basic - show file / line stats
63-
# * tidy-errors - show the highest rustc error code
64-
# * tidy-features - show the status of language and lib features
62+
# * tidy - Basic style check, show highest rustc error code and
63+
# the status of language and lib features
6564
# * rustc-stage$(stage) - Only build up to a specific stage
6665
#
6766
# Then mix in some of these environment variables to harness the

mk/crates.mk

+14-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ TARGET_CRATES := libc std term \
5353
getopts collections test rand \
5454
core alloc \
5555
rustc_unicode rustc_bitflags \
56-
alloc_system alloc_jemalloc
56+
alloc_system alloc_jemalloc \
57+
panic_abort panic_unwind unwind
5758
RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \
5859
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
5960
rustc_data_structures rustc_platform_intrinsics \
@@ -72,10 +73,18 @@ DEPS_libc := core
7273
DEPS_rand := core
7374
DEPS_rustc_bitflags := core
7475
DEPS_rustc_unicode := core
76+
DEPS_panic_abort := libc alloc
77+
DEPS_panic_unwind := libc alloc unwind
78+
DEPS_unwind := libc
79+
80+
# FIXME(stage0): change this to just `RUSTFLAGS_panic_abort := ...`
81+
RUSTFLAGS1_panic_abort := -C panic=abort
82+
RUSTFLAGS2_panic_abort := -C panic=abort
83+
RUSTFLAGS3_panic_abort := -C panic=abort
7584

7685
DEPS_std := core libc rand alloc collections rustc_unicode \
7786
native:backtrace \
78-
alloc_system
87+
alloc_system panic_abort panic_unwind unwind
7988
DEPS_arena := std
8089
DEPS_glob := std
8190
DEPS_flate := std native:miniz
@@ -148,6 +157,9 @@ ONLY_RLIB_rustc_unicode := 1
148157
ONLY_RLIB_rustc_bitflags := 1
149158
ONLY_RLIB_alloc_system := 1
150159
ONLY_RLIB_alloc_jemalloc := 1
160+
ONLY_RLIB_panic_unwind := 1
161+
ONLY_RLIB_panic_abort := 1
162+
ONLY_RLIB_unwind := 1
151163

152164
TARGET_SPECIFIC_alloc_jemalloc := 1
153165

mk/tests.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ DEPS_collectionstest :=
2323
$(eval $(call RUST_CRATE,collectionstest))
2424

2525
TEST_TARGET_CRATES = $(filter-out core rustc_unicode alloc_system libc \
26-
alloc_jemalloc,$(TARGET_CRATES)) \
26+
alloc_jemalloc panic_unwind \
27+
panic_abort,$(TARGET_CRATES)) \
2728
collectionstest coretest
2829
TEST_DOC_CRATES = $(DOC_CRATES) arena flate fmt_macros getopts graphviz \
2930
log rand rbml serialize syntax term test

src/bootstrap/rustc.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ fn main() {
4949
} else {
5050
env::var_os("RUSTC_REAL").unwrap()
5151
};
52+
let stage = env::var("RUSTC_STAGE").unwrap();
5253

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

5758
if target.is_none() {
5859
// Build scripts are always built with the snapshot compiler, so we need
@@ -82,6 +83,22 @@ fn main() {
8283
}
8384
}
8485

86+
// If we're compiling specifically the `panic_abort` crate then we pass the
87+
// `-C panic=abort` option. Note that we do not do this for any other crate
88+
// intentionally as this is the only crate for now that we ship with
89+
// panic=abort.
90+
//
91+
// This... is a bit of a hack how we detect this. Ideally this information
92+
// should be encoded in the crate I guess? Would likely require an RFC
93+
// amendment to RFC 1513, however.
94+
let is_panic_abort = args.windows(2).any(|a| {
95+
&*a[0] == "--crate-name" && &*a[1] == "panic_abort"
96+
});
97+
// FIXME(stage0): remove this `stage != "0"` condition
98+
if is_panic_abort && stage != "0" {
99+
cmd.arg("-C").arg("panic=abort");
100+
}
101+
85102
// Set various options from config.toml to configure how we're building
86103
// code.
87104
if let Some(target) = target {

src/doc/book/error-handling.md

+61-59
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,9 @@ detail on Getopts, but there is [some good documentation][15]
15731573
describing it. The short story is that Getopts generates an argument
15741574
parser and a help message from a vector of options (The fact that it
15751575
is a vector is hidden behind a struct and a set of methods). Once the
1576-
parsing is done, we can decode the program arguments into a Rust
1577-
struct. From there, we can get information about the flags, for
1576+
parsing is done, the parser returns a struct that records matches
1577+
for defined options, and remaining "free" arguments.
1578+
From there, we can get information about the flags, for
15781579
instance, whether they were passed in, and what arguments they
15791580
had. Here's our program with the appropriate `extern crate`
15801581
statements, and the basic argument setup for Getopts:
@@ -1605,8 +1606,8 @@ fn main() {
16051606
print_usage(&program, opts);
16061607
return;
16071608
}
1608-
let data_path = &args[1];
1609-
let city = &args[2];
1609+
let data_path = &matches.free[0];
1610+
let city: &str = &matches.free[1];
16101611
16111612
// Do stuff with information
16121613
}
@@ -1680,8 +1681,8 @@ fn main() {
16801681
return;
16811682
}
16821683
1683-
let data_path = &args[1];
1684-
let city: &str = &args[2];
1684+
let data_path = &matches.free[0];
1685+
let city: &str = &matches.free[1];
16851686
16861687
let file = File::open(data_path).unwrap();
16871688
let mut rdr = csv::Reader::from_reader(file);
@@ -1792,13 +1793,15 @@ fn main() {
17921793
Ok(m) => { m }
17931794
Err(e) => { panic!(e.to_string()) }
17941795
};
1796+
17951797
if matches.opt_present("h") {
17961798
print_usage(&program, opts);
17971799
return;
17981800
}
17991801
1800-
let data_path = &args[1];
1801-
let city = &args[2];
1802+
let data_path = &matches.free[0];
1803+
let city: &str = &matches.free[1];
1804+
18021805
for pop in search(data_path, city) {
18031806
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
18041807
}
@@ -1876,14 +1879,14 @@ when calling `search`:
18761879

18771880
```rust,ignore
18781881
...
1879-
match search(&data_file, &city) {
1880-
Ok(pops) => {
1881-
for pop in pops {
1882-
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
1882+
match search(data_path, city) {
1883+
Ok(pops) => {
1884+
for pop in pops {
1885+
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
1886+
}
18831887
}
1888+
Err(err) => println!("{}", err)
18841889
}
1885-
Err(err) => println!("{}", err)
1886-
}
18871890
...
18881891
```
18891892

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

19191922
```rust,ignore
19201923
...
1921-
let mut opts = Options::new();
1922-
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
1923-
opts.optflag("h", "help", "Show this usage message.");
1924-
...
1925-
let file = matches.opt_str("f");
1926-
let data_file = &file.as_ref().map(Path::new);
1927-
1928-
let city = if !matches.free.is_empty() {
1929-
&matches.free[0]
1930-
} else {
1931-
print_usage(&program, opts);
1932-
return;
1933-
};
1934-
1935-
match search(data_file, city) {
1936-
Ok(pops) => {
1937-
for pop in pops {
1938-
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
1924+
let mut opts = Options::new();
1925+
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
1926+
opts.optflag("h", "help", "Show this usage message.");
1927+
...
1928+
let data_path = matches.opt_str("f");
1929+
1930+
let city = if !matches.free.is_empty() {
1931+
&matches.free[0]
1932+
} else {
1933+
print_usage(&program, opts);
1934+
return;
1935+
};
1936+
1937+
match search(&data_path, city) {
1938+
Ok(pops) => {
1939+
for pop in pops {
1940+
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
1941+
}
19391942
}
1943+
Err(err) => println!("{}", err)
19401944
}
1941-
Err(err) => println!("{}", err)
1942-
}
19431945
...
19441946
```
19451947

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

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

20021999
```rust,ignore
2000+
use std::fmt;
2001+
20032002
impl fmt::Display for CliError {
20042003
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20052004
match *self {
@@ -2020,13 +2019,13 @@ impl Error for CliError {
20202019
}
20212020
}
20222021
2023-
fn cause(&self) -> Option<&error::Error> {
2024-
match *self {
2022+
fn cause(&self) -> Option<&Error> {
2023+
match *self {
20252024
CliError::Io(ref err) => Some(err),
2026-
CliError::Parse(ref err) => Some(err),
2027-
// Our custom error doesn't have an underlying cause, but we could
2028-
// modify it so that it does.
2029-
CliError::NotFound() => None,
2025+
CliError::Csv(ref err) => Some(err),
2026+
// Our custom error doesn't have an underlying cause,
2027+
// but we could modify it so that it does.
2028+
CliError::NotFound => None,
20302029
}
20312030
}
20322031
}
@@ -2122,24 +2121,27 @@ string and add a flag to the Option variable. Once we've done that, Getopts does
21222121

21232122
```rust,ignore
21242123
...
2125-
let mut opts = Options::new();
2126-
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
2127-
opts.optflag("h", "help", "Show this usage message.");
2128-
opts.optflag("q", "quiet", "Silences errors and warnings.");
2124+
let mut opts = Options::new();
2125+
opts.optopt("f", "file", "Choose an input file, instead of using STDIN.", "NAME");
2126+
opts.optflag("h", "help", "Show this usage message.");
2127+
opts.optflag("q", "quiet", "Silences errors and warnings.");
21292128
...
21302129
```
21312130

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

21352134
```rust,ignore
2136-
match search(&args.arg_data_path, &args.arg_city) {
2137-
Err(CliError::NotFound) if args.flag_quiet => process::exit(1),
2138-
Err(err) => panic!("{}", err),
2139-
Ok(pops) => for pop in pops {
2140-
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
2135+
use std::process;
2136+
...
2137+
match search(&data_path, city) {
2138+
Err(CliError::NotFound) if matches.opt_present("q") => process::exit(1),
2139+
Err(err) => panic!("{}", err),
2140+
Ok(pops) => for pop in pops {
2141+
println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
2142+
}
21412143
}
2142-
}
2144+
...
21432145
```
21442146

21452147
Certainly, we don't want to be quiet if there was an IO error or if the data

src/liballoc_system/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
form or name",
1919
issue = "27783")]
2020
#![feature(allocator)]
21-
#![feature(libc)]
2221
#![feature(staged_api)]
23-
24-
extern crate libc;
22+
#![cfg_attr(unix, feature(libc))]
2523

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

7371
#[cfg(unix)]
7472
mod imp {
73+
extern crate libc;
74+
7575
use core::cmp;
7676
use core::ptr;
77-
use libc;
7877
use MIN_ALIGN;
7978

8079
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {

src/libcollections/fmt.rs

+12
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,24 @@ use string;
521521
///
522522
/// # Examples
523523
///
524+
/// Basic usage:
525+
///
524526
/// ```
525527
/// use std::fmt;
526528
///
527529
/// let s = fmt::format(format_args!("Hello, {}!", "world"));
528530
/// assert_eq!(s, "Hello, world!".to_string());
529531
/// ```
532+
///
533+
/// Please note that using [`format!`][format!] might be preferrable.
534+
/// Example:
535+
///
536+
/// ```
537+
/// let s = format!("Hello, {}!", "world");
538+
/// assert_eq!(s, "Hello, world!".to_string());
539+
/// ```
540+
///
541+
/// [format!]: ../macro.format!.html
530542
#[stable(feature = "rust1", since = "1.0.0")]
531543
pub fn format(args: Arguments) -> string::String {
532544
let mut output = string::String::new();

src/libcollectionstest/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn test_from_utf8() {
5252
String::from("ศไทย中华Việt Nam"));
5353

5454
let xs = b"hello\xFF".to_vec();
55-
let err = String::from_utf8(xs).err().unwrap();
55+
let err = String::from_utf8(xs).unwrap_err();
5656
assert_eq!(err.into_bytes(), b"hello\xff".to_vec());
5757
}
5858

src/libcore/fmt/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,32 @@ pub trait UpperExp {
776776
///
777777
/// * output - the buffer to write output to
778778
/// * args - the precompiled arguments generated by `format_args!`
779+
///
780+
/// # Examples
781+
///
782+
/// Basic usage:
783+
///
784+
/// ```
785+
/// use std::fmt;
786+
///
787+
/// let mut output = String::new();
788+
/// fmt::write(&mut output, format_args!("Hello {}!", "world"))
789+
/// .expect("Error occurred while trying to write in String");
790+
/// assert_eq!(output, "Hello world!");
791+
/// ```
792+
///
793+
/// Please note that using [`write!`][write_macro] might be preferrable. Example:
794+
///
795+
/// ```
796+
/// use std::fmt::Write;
797+
///
798+
/// let mut output = String::new();
799+
/// write!(&mut output, "Hello {}!", "world")
800+
/// .expect("Error occurred while trying to write in String");
801+
/// assert_eq!(output, "Hello world!");
802+
/// ```
803+
///
804+
/// [write_macro]: ../macro.write!.html
779805
#[stable(feature = "rust1", since = "1.0.0")]
780806
pub fn write(output: &mut Write, args: Arguments) -> Result {
781807
let mut formatter = Formatter {

0 commit comments

Comments
 (0)