Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 17 pull requests #40080

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6ba7065
enable tools to use test runners programmatically
oli-obk Feb 14, 2017
80ac323
make more types public
oli-obk Feb 14, 2017
5189c4f
custom attributes and error reporting docs for procedural macros
JDemler Feb 15, 2017
9a39994
add bash to error-messages
JDemler Feb 15, 2017
8685adb
book: binary prefixed are defined by IEC and not in SI
mina86 Feb 13, 2017
9745199
fixed whitespace issues
JDemler Feb 15, 2017
b2ac1c9
Additional docs for Vec, String, and slice trait impls
mbrubeck Feb 16, 2017
2e756e2
add solaris sparcv9 support
binarycrusader Feb 17, 2017
038a166
Properly display note/expected details
estebank Feb 17, 2017
6091330
Follow rename of mx_handle_wait Magenta syscalls
raphlinus Feb 17, 2017
22f91ca
move the `FreeRegionMap` into `TypeckTables`
nikomatsakis Feb 16, 2017
5c391d7
add `visit_all_bodies_in_krate` helper
nikomatsakis Feb 15, 2017
252c8d7
rewrite `borrowck_fn` to only use the body-id
nikomatsakis Feb 18, 2017
5f5946a
remove the borrowck stats
nikomatsakis Feb 18, 2017
b347a23
make `borrowck_fn` and friends create `bccx`
nikomatsakis Feb 18, 2017
0c4c6fd
Rebuild mingw startup objects only when necessary
petrochenkov Feb 18, 2017
ec648a1
Fix indentation of error message
sgrif Feb 18, 2017
9334c39
remove special-case code for statics and just use `borrowck_fn`
nikomatsakis Feb 18, 2017
cde3c15
use `visit_all_bodies_in_krate` for borrowck instead of item-likes
nikomatsakis Feb 18, 2017
e49e43a
remove `Option` from the `tables` field
nikomatsakis Feb 18, 2017
198208b
Fixed some small issues
JDemler Feb 19, 2017
7770e9a
fix run-pass test that tried to move in const
nikomatsakis Feb 20, 2017
deb53a3
walk the bodies "in order" by traversing the crate
nikomatsakis Feb 21, 2017
538556d
kill the code path for E0388
nikomatsakis Feb 21, 2017
f69ce16
switch bodies to a btreemap
nikomatsakis Feb 21, 2017
fed58f3
store the visit order in the Crate
nikomatsakis Feb 21, 2017
58a9dd3
Add missing urls and examples into Barrier structs
GuillaumeGomez Feb 21, 2017
689dc26
Clarify thread::Builder::stack_size
matklad Feb 22, 2017
6b8e175
Update std::fmt module docs for landing of #33642.
jimblandy Feb 23, 2017
84ca464
Update exception-safety.md
DaseinPhaos Feb 23, 2017
729948f
Update exception-safety.md
DaseinPhaos Feb 23, 2017
088b727
Add missing urls in MutexGuard docs
GuillaumeGomez Feb 23, 2017
30b0ed0
rustbuild: Retry downloads by default
alexcrichton Feb 23, 2017
7c52cad
Correct another typo in procedural macros chapter of the Book.
tomwhoiscontrary Feb 24, 2017
dd44d31
Rollup merge of #39777 - mina86:gib, r=steveklabnik
frewsxcv Feb 24, 2017
c341a65
Rollup merge of #39815 - oli-obk:patch-3, r=aturon
frewsxcv Feb 24, 2017
a39632c
Rollup merge of #39845 - JDemler:master, r=steveklabnik
frewsxcv Feb 24, 2017
24e1dfb
Rollup merge of #39886 - mbrubeck:doc-edit, r=steveklabnik
frewsxcv Feb 24, 2017
f1af7ef
Rollup merge of #39892 - petrochenkov:rt, r=alexcrichton
frewsxcv Feb 24, 2017
1e7f5b1
Rollup merge of #39903 - binarycrusader:issue-39901, r=alexcrichton
frewsxcv Feb 24, 2017
7362098
Rollup merge of #39905 - estebank:useless-error, r=arielb1
frewsxcv Feb 24, 2017
3b379c7
Rollup merge of #39914 - raphlinus:mx_handle_wait, r=alexcrichton
frewsxcv Feb 24, 2017
32cc287
Rollup merge of #39927 - nikomatsakis:incr-comp-skip-borrowck-2, r=eddyb
frewsxcv Feb 24, 2017
9eebcf1
Rollup merge of #39940 - sgrif:sg-indentation, r=alexcrichton
frewsxcv Feb 24, 2017
8f4f474
Rollup merge of #40010 - GuillaumeGomez:barrier-docs, r=frewsxcv
frewsxcv Feb 24, 2017
26643dd
Rollup merge of #40030 - matklad:stack-docs, r=alexcrichton
frewsxcv Feb 24, 2017
837cc4f
Rollup merge of #40048 - jimblandy:fmt-arg-types-doc, r=alexcrichton
frewsxcv Feb 24, 2017
609ae8a
Rollup merge of #40050 - DaseinPhaos:patch-3, r=steveklabnik
frewsxcv Feb 24, 2017
4c176d4
Rollup merge of #40052 - GuillaumeGomez:sunc_docs, r=frewsxcv
frewsxcv Feb 24, 2017
1166995
Rollup merge of #40060 - alexcrichton:retry-downloads, r=aturon
frewsxcv Feb 24, 2017
c7a78c7
Rollup merge of #40071 - tomwhoiscontrary:pr-lets-apostrophes, r=Guil…
frewsxcv Feb 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,33 @@ def delete_if_present(path, verbose):


def download(path, url, probably_big, verbose):
for x in range(0, 4):
try:
_download(path, url, probably_big, verbose, True)
return
except RuntimeError:
print("\nspurious failure, trying again")
_download(path, url, probably_big, verbose, False)


def _download(path, url, probably_big, verbose, exception):
if probably_big or verbose:
print("downloading {}".format(url))
# see http://serverfault.com/questions/301128/how-to-download
if sys.platform == 'win32':
run(["PowerShell.exe", "/nologo", "-Command",
"(New-Object System.Net.WebClient)"
".DownloadFile('{}', '{}')".format(url, path)],
verbose=verbose)
verbose=verbose,
exception=exception)
else:
if probably_big or verbose:
option = "-#"
else:
option = "-s"
run(["curl", option, "--retry", "3", "-Sf", "-o", path, url], verbose=verbose)
run(["curl", option, "--retry", "3", "-Sf", "-o", path, url],
verbose=verbose,
exception=exception)


def verify(path, sha_path, verbose):
Expand Down Expand Up @@ -112,7 +125,7 @@ def unpack(tarball, dst, verbose=False, match=None):
shutil.move(tp, fp)
shutil.rmtree(os.path.join(dst, fname))

def run(args, verbose=False):
def run(args, verbose=False, exception=False):
if verbose:
print("running: " + ' '.join(args))
sys.stdout.flush()
Expand All @@ -122,7 +135,7 @@ def run(args, verbose=False):
code = ret.wait()
if code != 0:
err = "failed to run: " + ' '.join(args)
if verbose:
if verbose or exception:
raise RuntimeError(err)
sys.exit(err)

Expand Down Expand Up @@ -472,6 +485,8 @@ def build_triple(self):
ostype += 'abi64'
elif cputype in {'powerpc', 'ppc', 'ppc64'}:
cputype = 'powerpc'
elif cputype == 'sparcv9':
pass
elif cputype in {'amd64', 'x86_64', 'x86-64', 'x64'}:
cputype = 'x86_64'
else:
Expand Down
34 changes: 21 additions & 13 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::fs::{self, File};
use std::path::{Path, PathBuf};
use std::process::Command;

use build_helper::{output, mtime};
use build_helper::{output, mtime, up_to_date};
use filetime::FileTime;

use util::{exe, libdir, is_dylib, copy};
Expand Down Expand Up @@ -132,21 +132,29 @@ pub fn build_startup_objects(build: &Build, for_compiler: &Compiler, target: &st

let compiler = Compiler::new(0, &build.config.build);
let compiler_path = build.compiler_path(&compiler);
let into = build.sysroot_libdir(for_compiler, target);
t!(fs::create_dir_all(&into));

for file in t!(fs::read_dir(build.src.join("src/rtstartup"))) {
let file = t!(file);
let mut cmd = Command::new(&compiler_path);
build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
.arg("--target").arg(target)
.arg("--emit=obj")
.arg("--out-dir").arg(&into)
.arg(file.path()));
let src_dir = &build.src.join("src/rtstartup");
let dst_dir = &build.native_dir(target).join("rtstartup");
let sysroot_dir = &build.sysroot_libdir(for_compiler, target);
t!(fs::create_dir_all(dst_dir));
t!(fs::create_dir_all(sysroot_dir));

for file in &["rsbegin", "rsend"] {
let src_file = &src_dir.join(file.to_string() + ".rs");
let dst_file = &dst_dir.join(file.to_string() + ".o");
if !up_to_date(src_file, dst_file) {
let mut cmd = Command::new(&compiler_path);
build.run(cmd.env("RUSTC_BOOTSTRAP", "1")
.arg("--target").arg(target)
.arg("--emit=obj")
.arg("--out-dir").arg(dst_dir)
.arg(src_file));
}

copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
}

for obj in ["crt2.o", "dllcrt2.o"].iter() {
copy(&compiler_file(build.cc(target), obj), &into.join(obj));
copy(&compiler_file(build.cc(target), obj), &sysroot_dir.join(obj));
}
}

Expand Down
75 changes: 74 additions & 1 deletion src/doc/book/src/procedural-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ a representation of our type (which can be either a `struct` or an `enum`).
Check out the [docs](https://docs.rs/syn/0.10.5/syn/struct.MacroInput.html),
there is some useful information there. We are able to get the name of the
type using `ast.ident`. The `quote!` macro lets us write up the Rust code
that we wish to return and convert it into `Tokens`. `quote!` let's us use some
that we wish to return and convert it into `Tokens`. `quote!` lets us use some
really cool templating mechanics; we simply write `#name` and `quote!` will
replace it with the variable named `name`. You can even do some repetition
similar to regular macros work. You should check out the
Expand Down Expand Up @@ -211,3 +211,76 @@ Hello, World! My name is Waffles
```

We've done it!

## Custom Attributes

In some cases it might make sense to allow users some kind of configuration.
For example, the user might want to overwrite the name that is printed in the `hello_world()` method.

This can be achieved with custom attributes:

```rust,ignore
#[derive(HelloWorld)]
#[HelloWorldName = "the best Pancakes"]
struct Pancakes;

fn main() {
Pancakes::hello_world();
}
```

If we try to compile this though, the compiler will respond with an error:

```bash
error: The attribute `HelloWorldName` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
```

The compiler needs to know that we're handling this attribute and to not respond with an error.
This is done in the `hello-world-derive` crate by adding `attributes` to the `proc_macro_derive` attribute:

```rust,ignore
#[proc_macro_derive(HelloWorld, attributes(HelloWorldName))]
pub fn hello_world(input: TokenStream) -> TokenStream
```

Multiple attributes can be specified that way.

## Raising Errors

Let's assume that we do not want to accept enums as input to our custom derive method.

This condition can be easily checked with the help of `syn`.
But how do we tell the user, that we do not accept enums?
The idiomatic way to report errors in procedural macros is to panic:

```rust,ignore
fn impl_hello_world(ast: &syn::MacroInput) -> quote::Tokens {
let name = &ast.ident;
// Check if derive(HelloWorld) was specified for a struct
if let syn::Body::Struct(_) = ast.body {
// Yes, this is a struct
quote! {
impl HelloWorld for #name {
fn hello_world() {
println!("Hello, World! My name is {}", stringify!(#name));
}
}
}
} else {
//Nope. This is an Enum. We cannot handle these!
panic!("#[derive(HelloWorld)] is only defined for structs, not for enums!");
}
}
```

If a user now tries to derive `HelloWorld` from an enum they will be greeted with following, hopefully helpful, error:

```bash
error: custom derive attribute panicked
--> src/main.rs
|
| #[derive(HelloWorld)]
| ^^^^^^^^^^
|
= help: message: #[derive(HelloWorld)] is only defined for structs, not for enums!
```
2 changes: 1 addition & 1 deletion src/doc/book/src/the-stack-and-the-heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ to a large number, representing how much RAM your computer has. For example, if
you have a gigabyte of RAM, your addresses go from `0` to `1,073,741,823`. That
number comes from 2<sup>30</sup>, the number of bytes in a gigabyte. [^gigabyte]

[^gigabyte]: ‘Gigabyte’ can mean two things: 10^9, or 2^30. The SI standard resolved this by stating that ‘gigabyte’ is 10^9, and ‘gibibyte’ is 2^30. However, very few people use this terminology, and rely on context to differentiate. We follow in that tradition here.
[^gigabyte]: ‘Gigabyte’ can mean two things: 10<sup>9</sup>, or 2<sup>30</sup>. The IEC standard resolved this by stating that ‘gigabyte’ is 10<sup>9</sup>, and ‘gibibyte’ is 2<sup>30</sup>. However, very few people use this terminology, and rely on context to differentiate. We follow in that tradition here.

This memory is kind of like a giant array: addresses start at zero and go
up to the final number. So here’s a diagram of our first stack frame:
Expand Down
4 changes: 2 additions & 2 deletions src/doc/nomicon/src/exception-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ uselessly. We would rather have the following:
```text
bubble_up(heap, index):
let elem = heap[index]
while index != 0 && element < heap[parent(index)]:
while index != 0 && elem < heap[parent(index)]:
heap[index] = heap[parent(index)]
index = parent(index)
heap[index] = elem
Expand Down Expand Up @@ -137,7 +137,7 @@ If Rust had `try` and `finally` like in Java, we could do the following:
bubble_up(heap, index):
let elem = heap[index]
try:
while index != 0 && element < heap[parent(index)]:
       while index != 0 && elem < heap[parent(index)]:
heap[index] = heap[parent(index)]
index = parent(index)
finally:
Expand Down
25 changes: 4 additions & 21 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
//!
//! A format string is required to use all of its arguments, otherwise it is a
//! compile-time error. You may refer to the same argument more than once in the
//! format string, although it must always be referred to with the same type.
//! format string.
//!
//! ## Named parameters
//!
Expand All @@ -89,19 +89,8 @@
//!
//! ## Argument types
//!
//! Each argument's type is dictated by the format string. It is a requirement
//! that every argument is only ever referred to by one type. For example, this
//! is an invalid format string:
//!
//! ```text
//! {0:x} {0:o}
//! ```
//!
//! This is invalid because the first argument is both referred to as a
//! hexadecimal as well as an
//! octal.
//!
//! There are various parameters which do require a particular type, however.
//! Each argument's type is dictated by the format string.
//! There are various parameters which require a particular type, however.
//! An example is the `{:.*}` syntax, which sets the number of decimal places
//! in floating-point types:
//!
Expand All @@ -113,13 +102,7 @@
//!
//! If this syntax is used, then the number of characters to print precedes the
//! actual object being formatted, and the number of characters must have the
//! type `usize`. Although a `usize` can be printed with `{}`, it is invalid to
//! reference an argument as such. For example this is another invalid format
//! string:
//!
//! ```text
//! {:.*} {0}
//! ```
//! type `usize`.
//!
//! ## Formatting traits
//!
Expand Down
42 changes: 42 additions & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,43 @@ impl hash::Hash for String {
}
}

/// Implements the `+` operator for concatenating two strings.
///
/// This consumes the `String` on the left-hand side and re-uses its buffer (growing it if
/// necessary). This is done to avoid allocating a new `String` and copying the entire contents on
/// every operation, which would lead to `O(n^2)` running time when building an `n`-byte string by
/// repeated concatenation.
///
/// The string on the right-hand side is only borrowed; its contents are copied into the returned
/// `String`.
///
/// # Examples
///
/// Concatenating two `String`s takes the first by value and borrows the second:
///
/// ```
/// let a = String::from("hello");
/// let b = String::from(" world");
/// let c = a + &b;
/// // `a` is moved and can no longer be used here.
/// ```
///
/// If you want to keep using the first `String`, you can clone it and append to the clone instead:
///
/// ```
/// let a = String::from("hello");
/// let b = String::from(" world");
/// let c = a.clone() + &b;
/// // `a` is still valid here.
/// ```
///
/// Concatenating `&str` slices can be done by converting the first to a `String`:
///
/// ```
/// let a = "hello";
/// let b = " world";
/// let c = a.to_string() + b;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Add<&'a str> for String {
type Output = String;
Expand All @@ -1640,6 +1677,11 @@ impl<'a> Add<&'a str> for String {
}
}

/// Implements the `+=` operator for appending to a `String`.
///
/// This has the same behavior as the [`push_str()`] method.
///
/// [`push_str()`]: struct.String.html#method.push_str
#[stable(feature = "stringaddassign", since = "1.12.0")]
impl<'a> AddAssign<&'a str> for String {
#[inline]
Expand Down
2 changes: 2 additions & 0 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ array_impls! {
30 31 32
}

/// Implements comparison of vectors, lexicographically.
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd> PartialOrd for Vec<T> {
#[inline]
Expand All @@ -1787,6 +1788,7 @@ impl<T: PartialOrd> PartialOrd for Vec<T> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Eq> Eq for Vec<T> {}

/// Implements ordering of vectors, lexicographically.
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Ord for Vec<T> {
#[inline]
Expand Down
10 changes: 9 additions & 1 deletion src/libcompiler_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ fn main() {
// compiler-rt's build system already
cfg.flag("-fno-builtin");
cfg.flag("-fvisibility=hidden");
cfg.flag("-fomit-frame-pointer");
// Accepted practice on Solaris is to never omit frame pointer so that
// system observability tools work as expected. In addition, at least
// on Solaris, -fomit-frame-pointer on sparcv9 appears to generate
// references to data outside of the current stack frame. A search of
// the gcc bug database provides a variety of issues surrounding
// -fomit-frame-pointer on non-x86 platforms.
if !target.contains("solaris") && !target.contains("sparc") {
cfg.flag("-fomit-frame-pointer");
}
cfg.flag("-ffreestanding");
cfg.define("VISIBILITY_HIDDEN", None);
}
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,13 +2202,15 @@ impl<A, B> PartialEq<[B]> for [A] where A: PartialEq<B> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Eq> Eq for [T] {}

/// Implements comparison of vectors lexicographically.
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Ord> Ord for [T] {
fn cmp(&self, other: &[T]) -> Ordering {
SliceOrd::compare(self, other)
}
}

/// Implements comparison of vectors lexicographically.
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PartialOrd> PartialOrd for [T] {
fn partial_cmp(&self, other: &[T]) -> Option<Ordering> {
Expand Down
Loading