From f7e1421debb5bc32f60f6d7d50fc356db16800e7 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 28 Apr 2016 15:01:47 +0200 Subject: [PATCH 01/22] Add `TAGS.rustc.emacs`/`TAGS.rustc.vi` make targets, (re-)including rustc source. --- mk/ctags.mk | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mk/ctags.mk b/mk/ctags.mk index a116f2aba6437..1fcb0bb4debbc 100644 --- a/mk/ctags.mk +++ b/mk/ctags.mk @@ -15,14 +15,21 @@ .PHONY: TAGS.emacs TAGS.vi -CTAGS_LOCATIONS=$(wildcard ${CFG_SRC_DIR}src/lib*) +CTAGS_RUSTC_LOCATIONS=$(patsubst ${CFG_SRC_DIR}src/lib%test,, \ + $(wildcard ${CFG_SRC_DIR}src/lib*)) ${CFG_SRC_DIR}src/libtest CTAGS_LOCATIONS=$(patsubst ${CFG_SRC_DIR}src/librust%,, \ $(patsubst ${CFG_SRC_DIR}src/lib%test,, \ $(wildcard ${CFG_SRC_DIR}src/lib*))) ${CFG_SRC_DIR}src/libtest -CTAGS_OPTS=--options="${CFG_SRC_DIR}src/etc/ctags.rust" --languages=Rust --recurse ${CTAGS_LOCATIONS} +CTAGS_OPTS=--options="${CFG_SRC_DIR}src/etc/ctags.rust" --languages=Rust --recurse + +TAGS.rustc.emacs: + ctags -e -f $@ ${CTAGS_OPTS} ${CTAGS_RUSTC_LOCATIONS} TAGS.emacs: - ctags -e -f $@ ${CTAGS_OPTS} + ctags -e -f $@ ${CTAGS_OPTS} ${CTAGS_LOCATIONS} + +TAGS.rustc.vi: + ctags -f $@ ${CTAGS_OPTS} ${CTAGS_RUSTC_LOCATIONS} TAGS.vi: - ctags -f $@ ${CTAGS_OPTS} + ctags -f $@ ${CTAGS_OPTS} ${CTAGS_LOCATIONS} From 27c01cb4973a1728813f9668d34522c0c83076d5 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 28 Apr 2016 12:42:42 +0200 Subject: [PATCH 02/22] Add process types documentation --- src/libstd/process.rs | 200 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 196 insertions(+), 4 deletions(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 1d2516a4c4099..7a86e726b3a6a 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -215,12 +215,38 @@ impl Command { /// /// Builder methods are provided to change these defaults and /// otherwise configure the process. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("sh") + /// .spawn() + /// .expect("sh command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn new>(program: S) -> Command { Command { inner: imp::Command::new(program.as_ref()) } } /// Add an argument to pass to the program. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .arg("-l") + /// .arg("-a") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn arg>(&mut self, arg: S) -> &mut Command { self.inner.arg(arg.as_ref()); @@ -228,6 +254,19 @@ impl Command { } /// Add multiple arguments to pass to the program. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .args(&["-l", "-a"]) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn args>(&mut self, args: &[S]) -> &mut Command { for arg in args { @@ -240,6 +279,19 @@ impl Command { /// /// Note that environment variable names are case-insensitive (but case-preserving) on Windows, /// and case-sensitive on all other platforms. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .env("PATH", "/bin") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env(&mut self, key: K, val: V) -> &mut Command where K: AsRef, V: AsRef @@ -249,6 +301,19 @@ impl Command { } /// Removes an environment variable mapping. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .env_remove("PATH") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env_remove>(&mut self, key: K) -> &mut Command { self.inner.env_remove(key.as_ref()); @@ -256,6 +321,19 @@ impl Command { } /// Clears the entire environment map for the child process. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .env_clear() + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env_clear(&mut self) -> &mut Command { self.inner.env_clear(); @@ -263,6 +341,19 @@ impl Command { } /// Sets the working directory for the child process. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .current_dir("/bin") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn current_dir>(&mut self, dir: P) -> &mut Command { self.inner.cwd(dir.as_ref().as_ref()); @@ -270,6 +361,19 @@ impl Command { } /// Configuration for the child process's stdin handle (file descriptor 0). + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// Command::new("ls") + /// .stdin(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn stdin(&mut self, cfg: Stdio) -> &mut Command { self.inner.stdin(cfg.0); @@ -277,6 +381,19 @@ impl Command { } /// Configuration for the child process's stdout handle (file descriptor 1). + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// Command::new("ls") + /// .stdout(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn stdout(&mut self, cfg: Stdio) -> &mut Command { self.inner.stdout(cfg.0); @@ -284,6 +401,19 @@ impl Command { } /// Configuration for the child process's stderr handle (file descriptor 2). + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// Command::new("ls") + /// .stderr(Stdio::null()) + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn stderr(&mut self, cfg: Stdio) -> &mut Command { self.inner.stderr(cfg.0); @@ -293,6 +423,18 @@ impl Command { /// Executes the command as a child process, returning a handle to it. /// /// By default, stdin, stdout and stderr are inherited from the parent. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// Command::new("ls") + /// .spawn() + /// .expect("ls command failed to start"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn spawn(&mut self) -> io::Result { self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner) @@ -308,8 +450,10 @@ impl Command { /// /// ```should_panic /// use std::process::Command; - /// let output = Command::new("/bin/cat").arg("file.txt").output() - /// .expect("failed to execute process"); + /// let output = Command::new("/bin/cat") + /// .arg("file.txt") + /// .output() + /// .expect("failed to execute process"); /// /// println!("status: {}", output.status); /// println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); @@ -333,8 +477,10 @@ impl Command { /// ```should_panic /// use std::process::Command; /// - /// let status = Command::new("/bin/cat").arg("file.txt").status() - /// .expect("failed to execute process"); + /// let status = Command::new("/bin/cat") + /// .arg("file.txt") + /// .status() + /// .expect("failed to execute process"); /// /// println!("process exited with: {}", status); /// @@ -469,12 +615,42 @@ impl fmt::Display for ExitStatus { impl Child { /// Forces the child to exit. This is equivalent to sending a /// SIGKILL on unix platforms. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// let mut command = Command::new("yes"); + /// if let Ok(mut child) = command.spawn() { + /// child.kill().expect("command wasn't running"); + /// } else { + /// println!("yes command didn't start"); + /// } + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn kill(&mut self) -> io::Result<()> { self.handle.kill() } /// Returns the OS-assigned process identifier associated with this child. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// let mut command = Command::new("ls"); + /// if let Ok(child) = command.spawn() { + /// println!("Child's id is {}", child.id()); + /// } else { + /// println!("ls command didn't start"); + /// } + /// ``` #[stable(feature = "process_id", since = "1.3.0")] pub fn id(&self) -> u32 { self.handle.id() @@ -488,6 +664,22 @@ impl Child { /// before waiting. This helps avoid deadlock: it ensures that the /// child does not block waiting for input from the parent, while /// the parent waits for the child to exit. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ```no_run + /// use std::process::Command; + /// + /// let mut command = Command::new("ls"); + /// if let Ok(mut child) = command.spawn() { + /// child.wait().expect("command wasn't running"); + /// println!("Child has finished its execution!"); + /// } else { + /// println!("ls command didn't start"); + /// } + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn wait(&mut self) -> io::Result { drop(self.stdin.take()); From 47d9f49ebf3b32ac79011e282f5bd8d2dce2df39 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 1 May 2016 18:13:36 +0200 Subject: [PATCH 03/22] Remove rust flags from doc block --- src/librustc_driver/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 4aaeeed343016..3b25104437aee 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -352,7 +352,13 @@ fn handle_explain(code: &str, match descriptions.find_description(&normalised) { Some(ref description) => { // Slice off the leading newline and print. - print!("{}", &description[1..]); + print!("{}", &(&description[1..]).split("\n").map(|x| { + format!("{}\n", if x.starts_with("```") { + "```" + } else { + x + }) + }).collect::()); } None => { early_error(output, &format!("no extended information for {}", code)); From e3f13129b42354ca9cc408df084796f0404c30a9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 1 May 2016 19:23:29 +0200 Subject: [PATCH 04/22] dep_graph: avoid panicking in thread when channel closed On my system, when the processor is already loaded, and I try to run the test suite, e.g. compile-fail/dep-graph-assoc-type-trans.rs fails because of undecodable JSON. Running the compiler manually, I can see that the dep graph thread panics (and puts non-JSON on stderr) while `send`ing on `swap_out`, presumably because the other end has already quit. I think that in this case, we can just gracefully exit the thread. --- src/librustc/dep_graph/thread.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/librustc/dep_graph/thread.rs b/src/librustc/dep_graph/thread.rs index 5b0e4a909c8d3..b15e0e33b8402 100644 --- a/src/librustc/dep_graph/thread.rs +++ b/src/librustc/dep_graph/thread.rs @@ -176,6 +176,9 @@ pub fn main(swap_in: Receiver>, DepMessage::Query => query_out.send(edges.query()).unwrap(), } } - swap_out.send(messages).unwrap(); + if let Err(_) = swap_out.send(messages) { + // the receiver must have been dropped already + break; + } } } From eba43fb5c3baaeb543edb6c0abbcf778a176c4a9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 1 May 2016 22:59:20 +0200 Subject: [PATCH 05/22] std::thread docs: spawn() returns not a Thread anymore Also move the "Thread type" section down a bit, since it is not so important anymore. Fixes: #33321 --- src/libstd/thread/mod.rs | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index b3549dc12645a..2f0dec759b3d5 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -13,7 +13,8 @@ //! ## The threading model //! //! An executing Rust program consists of a collection of native OS threads, -//! each with their own stack and local state. +//! each with their own stack and local state. Threads can be named, and +//! provide some built-in support for low-level synchronization. //! //! Communication between threads can be done through //! [channels](../../std/sync/mpsc/index.html), Rust's message-passing @@ -37,20 +38,6 @@ //! convenient facilities for automatically waiting for the termination of a //! child thread (i.e., join). //! -//! ## The `Thread` type -//! -//! Threads are represented via the `Thread` type, which you can -//! get in one of two ways: -//! -//! * By spawning a new thread, e.g. using the `thread::spawn` function. -//! * By requesting the current thread, using the `thread::current` function. -//! -//! Threads can be named, and provide some built-in support for low-level -//! synchronization (described below). -//! -//! The `thread::current()` function is available even for threads not spawned -//! by the APIs of this module. -//! //! ## Spawning a thread //! //! A new thread can be spawned using the `thread::spawn` function: @@ -99,6 +86,18 @@ //! }); //! ``` //! +//! ## The `Thread` type +//! +//! Threads are represented via the `Thread` type, which you can get in one of +//! two ways: +//! +//! * By spawning a new thread, e.g. using the `thread::spawn` function, and +//! calling `thread()` on the `JoinHandle`. +//! * By requesting the current thread, using the `thread::current` function. +//! +//! The `thread::current()` function is available even for threads not spawned +//! by the APIs of this module. +//! //! ## Blocking support: park and unpark //! //! Every thread is equipped with some basic low-level blocking support, via the From b75f81c9b3f996100c72f9141dcf6161f8fc90f4 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 2 May 2016 08:45:38 +0200 Subject: [PATCH 06/22] parser: do not try to continue with `unsafe` on foreign fns The changed line makes it look like `unsafe` is allowed, but the first statement of `parse_item_foreign_fn` is: `self.expect_keyword(keywords::Fn)?;` So we get the strange "expected one of `fn`, `pub`, `static`, or `unsafe`, found `unsafe`". Fixes: #27361 --- src/libsyntax/parse/parser.rs | 2 +- src/test/parse-fail/extern-no-fn.rs | 2 +- src/test/parse-fail/removed-syntax-extern-const.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 671a11b57dec1..c22a36739d678 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6025,7 +6025,7 @@ impl<'a> Parser<'a> { // FOREIGN STATIC ITEM return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); } - if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) { + if self.check_keyword(keywords::Fn) { // FOREIGN FUNCTION ITEM return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } diff --git a/src/test/parse-fail/extern-no-fn.rs b/src/test/parse-fail/extern-no-fn.rs index bf5cbe0c4592a..acf7187cf436f 100644 --- a/src/test/parse-fail/extern-no-fn.rs +++ b/src/test/parse-fail/extern-no-fn.rs @@ -11,7 +11,7 @@ // compile-flags: -Z parse-only extern { - f(); //~ ERROR expected one of `fn`, `pub`, `static`, `unsafe`, or `}`, found `f` + f(); //~ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `f` } fn main() { diff --git a/src/test/parse-fail/removed-syntax-extern-const.rs b/src/test/parse-fail/removed-syntax-extern-const.rs index c42fae71237da..e632af6c83b1d 100644 --- a/src/test/parse-fail/removed-syntax-extern-const.rs +++ b/src/test/parse-fail/removed-syntax-extern-const.rs @@ -12,5 +12,5 @@ extern { const i: isize; - //~^ ERROR expected one of `fn`, `pub`, `static`, `unsafe`, or `}`, found `const` + //~^ ERROR expected one of `fn`, `pub`, `static`, or `}`, found `const` } From a11ddb3727ffa9f232f6bfbe69f4369bf8eafb39 Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Wed, 4 May 2016 13:05:21 -0400 Subject: [PATCH 07/22] Replace copy-pasted variable name with relevant one --- src/libcollections/slice.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 588ad7a319ac3..0f77ebb3c5745 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -419,8 +419,8 @@ impl [T] { /// /// ```rust /// let v = &[1, 2, 3, 4, 5]; - /// for win in v.chunks(2) { - /// println!("{:?}", win); + /// for chunk in v.chunks(2) { + /// println!("{:?}", chunk); /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] From 2ca31205f3688f452eafccf0337fe381d9db8457 Mon Sep 17 00:00:00 2001 From: Kaiyin Zhong Date: Wed, 4 May 2016 21:50:51 +0200 Subject: [PATCH 08/22] errors in the doc --- src/libcore/iter/iterator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index 2033ae58d3804..c13512a399ad8 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -214,7 +214,7 @@ pub trait Iterator { /// Like most indexing operations, the count starts from zero, so `nth(0)` /// returns the first value, `nth(1)` the second, and so on. /// - /// `nth()` will return `None` if `n` is larger than the length of the + /// `nth()` will return `None` if `n` >= the length of the /// iterator. /// /// # Examples @@ -237,7 +237,7 @@ pub trait Iterator { /// assert_eq!(iter.nth(1), None); /// ``` /// - /// Returning `None` if there are less than `n` elements: + /// Returning `None` if there are less than `n + 1` elements: /// /// ``` /// let a = [1, 2, 3]; From 16219deb5c87bcc85f4c28dff7d83705abbcfe19 Mon Sep 17 00:00:00 2001 From: Kaiyin Zhong Date: Wed, 4 May 2016 23:29:28 +0200 Subject: [PATCH 09/22] Update iterator.rs --- src/libcore/iter/iterator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs index c13512a399ad8..b80f77c0d25a9 100644 --- a/src/libcore/iter/iterator.rs +++ b/src/libcore/iter/iterator.rs @@ -214,7 +214,7 @@ pub trait Iterator { /// Like most indexing operations, the count starts from zero, so `nth(0)` /// returns the first value, `nth(1)` the second, and so on. /// - /// `nth()` will return `None` if `n` >= the length of the + /// `nth()` will return `None` if `n` is greater than or equal to the length of the /// iterator. /// /// # Examples From 8facc977114dd80be031d2de94d66d87126aab5f Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Tue, 3 May 2016 11:26:01 -0700 Subject: [PATCH 10/22] Add detailed error explanation for E0506 Broke up long lines in E0506 Trimmed E0506 comment to be under max line width Added function example to E0506 Changed example of erroneous code wording on E0506 --- src/librustc_borrowck/diagnostics.rs | 85 +++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index e838921a83178..ba8ea024c26a8 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -390,6 +390,90 @@ fn foo(a: &mut i32) { ``` "##, +E0506: r##" +This error occurs when an attempt is made to assign to a borrowed value. + +Example of erroneous code: + +```compile_fail +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + let fancy_ref = &fancy_num; + fancy_num = FancyNum { num: 6 }; + // error: cannot assign to `fancy_num` because it is borrowed + + println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num); +} +``` + +Because `fancy_ref` still holds a reference to `fancy_num`, `fancy_num` can't +be assigned to a new value as it would invalidate the reference. + +Alternatively, we can move out of `fancy_num` into a second `fancy_num`: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + let moved_num = fancy_num; + fancy_num = FancyNum { num: 6 }; + + println!("Num: {}, Moved num: {}", fancy_num.num, moved_num.num); +} +``` + +If the value has to be borrowed, try limiting the lifetime of the borrow using +a scoped block: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + + { + let fancy_ref = &fancy_num; + println!("Ref: {}", fancy_ref.num); + } + + // Works because `fancy_ref` is no longer in scope + fancy_num = FancyNum { num: 6 }; + println!("Num: {}", fancy_num.num); +} +``` + +Or by moving the reference into a function: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + + print_fancy_ref(&fancy_num); + + // Works because function borrow has ended + fancy_num = FancyNum { num: 6 }; + println!("Num: {}", fancy_num.num); +} + +fn print_fancy_ref(fancy_ref: &FancyNum){ + println!("Ref: {}", fancy_ref.num); +} +``` +"##, + E0507: r##" You tried to move out of a value which was borrowed. Erroneous code example: @@ -516,7 +600,6 @@ register_diagnostics! { E0503, // cannot use `..` because it was mutably borrowed E0504, // cannot move `..` into closure because it is borrowed E0505, // cannot move out of `..` because it is borrowed - E0506, // cannot assign to `..` because it is borrowed E0508, // cannot move out of type `..`, a non-copy fixed-size array E0509, // cannot move out of type `..`, which defines the `Drop` trait E0524, // two closures require unique access to `..` at the same time From d1c487e6c738ebaee576c03f711ed26a1117d7f1 Mon Sep 17 00:00:00 2001 From: Philipp Matthias Schaefer Date: Thu, 5 May 2016 08:23:24 +0200 Subject: [PATCH 11/22] Add an example to Wrapping's documentation. --- src/libcore/num/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 589ac90b308ad..af4ac482cf7d0 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -37,6 +37,17 @@ use slice::SliceExt; /// `wrapping_add`, or through the `Wrapping` type, which says that /// all standard arithmetic operations on the underlying value are /// intended to have wrapping semantics. +/// +/// # Examples +/// +/// ``` +/// use std::num::Wrapping; +/// +/// let zero = Wrapping(0u32); +/// let one = Wrapping(1u32); +/// +/// assert_eq!(std::u32::MAX, (zero - one).0); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default, Hash)] pub struct Wrapping(#[stable(feature = "rust1", since = "1.0.0")] pub T); From a22ca2872ef6782306012e6817dc4b8b778c43e9 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 5 May 2016 14:23:43 +0200 Subject: [PATCH 12/22] [Doc] Default cpu is "generic" (and not "default") --- src/librustc_back/target/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 3f75201aad2cc..0f40de56e0279 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -201,7 +201,7 @@ pub struct TargetOptions { pub post_link_args: Vec, /// Default CPU to pass to LLVM. Corresponds to `llc -mcpu=$cpu`. Defaults - /// to "default". + /// to "generic". pub cpu: String, /// Default target features to pass to LLVM. These features will *always* be /// passed, and cannot be disabled even via `-C`. Corresponds to `llc From 39eec8071c5b2920203c1ba98943efe2b1007e62 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 1 May 2016 10:40:01 -0700 Subject: [PATCH 13/22] mk: Fix building with --enable-ccache We will no longer use `ccache` in the makefiles for our local dependencies like miniz, but they're so small anyway it doesn't really matter. Closes #33285 --- mk/platform.mk | 6 +++--- mk/tests.mk | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mk/platform.mk b/mk/platform.mk index 59c8f7726c92f..c2644621c571a 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -169,7 +169,7 @@ ifdef CFG_CCACHE_BASEDIR export CCACHE_BASEDIR endif -FIND_COMPILER = $(word 1,$(1:ccache=)) +FIND_COMPILER = $(strip $(1:ccache=)) define CFG_MAKE_TOOLCHAIN # Prepend the tools with their prefix if cross compiling @@ -187,7 +187,7 @@ define CFG_MAKE_TOOLCHAIN endif endif - CFG_COMPILE_C_$(1) = '$$(CC_$(1))' \ + CFG_COMPILE_C_$(1) = '$$(call FIND_COMPILER,$$(CC_$(1)))' \ $$(CFLAGS) \ $$(CFG_GCCISH_CFLAGS) \ $$(CFG_GCCISH_CFLAGS_$(1)) \ @@ -198,7 +198,7 @@ define CFG_MAKE_TOOLCHAIN $$(CFG_GCCISH_LINK_FLAGS_$(1)) \ $$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \ $$(call CFG_INSTALL_NAME_$(1),$$(4)) - CFG_COMPILE_CXX_$(1) = '$$(CXX_$(1))' \ + CFG_COMPILE_CXX_$(1) = '$$(call FIND_COMPILER,$$(CXX_$(1)))' \ $$(CXXFLAGS) \ $$(CFG_GCCISH_CFLAGS) \ $$(CFG_GCCISH_CXXFLAGS) \ diff --git a/mk/tests.mk b/mk/tests.mk index 90a7888af09c7..f2f3290ba6825 100644 --- a/mk/tests.mk +++ b/mk/tests.mk @@ -636,8 +636,8 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \ --host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \ --lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \ --target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \ - --cc '$$(CC_$(2))' \ - --cxx '$$(CXX_$(2))' \ + --cc '$$(call FIND_COMPILER,$$(CC_$(2)))' \ + --cxx '$$(call FIND_COMPILER,$$(CXX_$(2)))' \ --cflags "$$(CFG_GCCISH_CFLAGS_$(2))" \ --llvm-components "$$(LLVM_ALL_COMPONENTS_$(2))" \ --llvm-cxxflags "$$(LLVM_CXXFLAGS_$(2))" \ From 2912bfb2b94c302e7395e49d8683356be5b9103e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 5 May 2016 18:20:31 +0000 Subject: [PATCH 14/22] doc: Update reference with better description of target_env The definition of this value recently changed slightly. It no longer corresponds directly to the target triple. Also shuffled things around to make the order of cfg descriptions more logical and added text related them to the target triple. cc #33403 --- src/doc/reference.md | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index fcf9aefaba847..397abfe563c1f 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2063,33 +2063,41 @@ arbitrarily complex configurations through nesting. The following configurations must be defined by the implementation: -* `debug_assertions` - Enabled by default when compiling without optimizations. - This can be used to enable extra debugging code in development but not in - production. For example, it controls the behavior of the standard library's - `debug_assert!` macro. -* `target_arch = "..."` - Target CPU architecture, such as `"x86"`, `"x86_64"` - `"mips"`, `"powerpc"`, `"powerpc64"`, `"arm"`, or `"aarch64"`. -* `target_endian = "..."` - Endianness of the target CPU, either `"little"` or - `"big"`. -* `target_env = ".."` - An option provided by the compiler by default - describing the runtime environment of the target platform. Some examples of - this are `musl` for builds targeting the MUSL libc implementation, `msvc` for - Windows builds targeting MSVC, and `gnu` frequently the rest of the time. This - option may also be blank on some platforms. +* `target_arch = "..."` - Target CPU architecture, such as `"x86"`, + `"x86_64"` `"mips"`, `"powerpc"`, `"powerpc64"`, `"arm"`, or + `"aarch64"`. This value is closely related to the first element of + the platform target triple, though it is not identical. +* `target_os = "..."` - Operating system of the target, examples + include `"windows"`, `"macos"`, `"ios"`, `"linux"`, `"android"`, + `"freebsd"`, `"dragonfly"`, `"bitrig"` , `"openbsd"` or + `"netbsd"`. This value is closely related to the second and third + element of the platform target triple, though it is not identical. * `target_family = "..."` - Operating system family of the target, e. g. `"unix"` or `"windows"`. The value of this configuration option is defined as a configuration itself, like `unix` or `windows`. -* `target_os = "..."` - Operating system of the target, examples include - `"windows"`, `"macos"`, `"ios"`, `"linux"`, `"android"`, `"freebsd"`, `"dragonfly"`, - `"bitrig"` , `"openbsd"` or `"netbsd"`. +* `unix` - See `target_family`. +* `windows` - See `target_family`. +* `target_env = ".."` - Further disambiguates the target platform with + information about the ABI/libc. Presently this value is either + `"gnu"`, `"msvc"`, `"musl"`, or the empty string. For historical + reasons this value has only been defined as non-empty when needed + for disambiguation. Thus on many GNU platforms this value will be + empty. This value is closely related to the fourth element of the + platform target triple, though it is not identical. For example, + embedded ABIs such as `gnueabihf` will simply define `target_env` as + `"gnu"`. +* `target_endian = "..."` - Endianness of the target CPU, either `"little"` or + `"big"`. * `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_vendor = "..."` - Vendor of the target, for example `apple`, `pc`, or simply `"unknown"`. * `test` - Enabled when compiling the test harness (using the `--test` flag). -* `unix` - See `target_family`. -* `windows` - See `target_family`. +* `debug_assertions` - Enabled by default when compiling without optimizations. + This can be used to enable extra debugging code in development but not in + production. For example, it controls the behavior of the standard library's + `debug_assert!` macro. You can also set another attribute based on a `cfg` variable with `cfg_attr`: From 26eb2bef2591ddb4cdf45d256cdcfa7c7353b0fc Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 5 May 2016 21:11:41 +0200 Subject: [PATCH 15/22] Fix some some duplicate words. --- src/bootstrap/build/job.rs | 2 +- src/librustc/session/config.rs | 2 +- src/librustc/traits/project.rs | 2 +- src/librustc/ty/trait_def.rs | 2 +- src/librustc/ty/wf.rs | 2 +- src/librustc_trans/intrinsic.rs | 2 +- src/libstd/net/ip.rs | 2 +- src/libstd/sys/unix/process.rs | 2 +- src/test/codegen-units/item-collection/cross-crate-closures.rs | 2 +- src/test/run-pass/regions-lub-ref-ref-rc.rs | 2 +- src/tools/linkchecker/main.rs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bootstrap/build/job.rs b/src/bootstrap/build/job.rs index a4e53bc45fcfb..4558e6f049432 100644 --- a/src/bootstrap/build/job.rs +++ b/src/bootstrap/build/job.rs @@ -54,7 +54,7 @@ pub unsafe fn setup() { // Indicate that when all handles to the job object are gone that all // process in the object should be killed. Note that this includes our - // entire process tree by default because we've added ourselves and and our + // entire process tree by default because we've added ourselves and our // children will reside in the job by default. let mut info = mem::zeroed::(); info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index b8dd750d3f1c2..1a2c1b9a09528 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1355,7 +1355,7 @@ pub mod nightly_options { early_error(ErrorOutputType::default(), &msg); } OptionStability::UnstableButNotReally => { - let msg = format!("the option `{}` is is unstable and should \ + let msg = format!("the option `{}` is unstable and should \ only be used on the nightly compiler, but \ it is currently accepted for backwards \ compatibility; this will soon change, \ diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index a0d6f5f912b2c..7fb13f49cb4a5 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -40,7 +40,7 @@ use std::rc::Rc; pub enum ProjectionMode { /// FIXME (#32205) /// At coherence-checking time, we're still constructing the - /// specialization graph, and thus we only project project + /// specialization graph, and thus we only project /// non-`default` associated types that are defined directly in /// the applicable impl. (This behavior should be improved over /// time, to allow for successful projections modulo cycles diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index faae95e711699..f194afaa81762 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -176,7 +176,7 @@ impl<'tcx> TraitDef<'tcx> { /// Records a trait-to-implementation mapping for a non-local impl. /// /// The `parent_impl` is the immediately-less-specialized impl, or the - /// trait's def ID if the impl is is not a specialization -- information that + /// trait's def ID if the impl is not a specialization -- information that /// should be pulled from the metadata. pub fn record_remote_impl(&self, tcx: &TyCtxt<'tcx>, diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index f93332e07737d..7de83ef5cc920 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -268,7 +268,7 @@ impl<'a,'tcx> WfPredicates<'a,'tcx> { /// into `self.out`. fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) { // A projection is well-formed if (a) the trait ref itself is - // WF WF and (b) the trait-ref holds. (It may also be + // WF and (b) the trait-ref holds. (It may also be // normalizable and be WF that way.) self.compute_trait_ref(&data.trait_ref); diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index 1220fbafa29c9..7c5ce371ee919 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -1327,7 +1327,7 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, // %ret = call i32 @the_real_filter_function(%ehptrs, %arg) // ret i32 %ret // - // The recoverfp intrinsic is used to recover the frame frame pointer of the + // The recoverfp intrinsic is used to recover the frame pointer of the // `rust_try_fn` function, which is then in turn passed to the // `localrecover` intrinsic (pairing with the `localescape` intrinsic // mentioned above). Putting all this together means that we now have a diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index adceee6d73ec5..019241982502e 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -371,7 +371,7 @@ impl Ipv6Addr { } /// Returns true if this is an address reserved for documentation - /// This is defined to be 2001:db8::/32 in RFC RFC 3849 + /// This is defined to be 2001:db8::/32 in RFC 3849. pub fn is_documentation(&self) -> bool { (self.segments()[0] == 0x2001) && (self.segments()[1] == 0xdb8) } diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 270c2096b2c3b..0500480add22f 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -147,7 +147,7 @@ impl Command { let new_key = pair_to_key(key, val, &mut self.saw_nul); let (map, envp) = self.init_env_map(); - // If `key` is already present then we we just update `envp` in place + // If `key` is already present then we just update `envp` in place // (and store the owned value), but if it's not there we override the // trailing NULL pointer, add a new NULL pointer, and store where we // were located. diff --git a/src/test/codegen-units/item-collection/cross-crate-closures.rs b/src/test/codegen-units/item-collection/cross-crate-closures.rs index 30f3ef12d0743..546bb235a5f50 100644 --- a/src/test/codegen-units/item-collection/cross-crate-closures.rs +++ b/src/test/codegen-units/item-collection/cross-crate-closures.rs @@ -27,7 +27,7 @@ fn main() { //~ TRANS_ITEM fn cgu_extern_closures::inlined_fn_generic[0]::{{closure}}[0] let _ = cgu_extern_closures::inlined_fn_generic(3, 4, 5i32); - // Nothing should be generated for this call, we just link to the instance instance + // Nothing should be generated for this call, we just link to the instance // in the extern crate. let _ = cgu_extern_closures::non_inlined_fn(6, 7); } diff --git a/src/test/run-pass/regions-lub-ref-ref-rc.rs b/src/test/run-pass/regions-lub-ref-ref-rc.rs index 41c64197acbe8..ade742863a9da 100644 --- a/src/test/run-pass/regions-lub-ref-ref-rc.rs +++ b/src/test/run-pass/regions-lub-ref-ref-rc.rs @@ -9,7 +9,7 @@ // except according to those terms. // Test a corner case of LUB coercion. In this case, one arm of the -// match requires a deref coercion and other other doesn't, and there +// match requires a deref coercion and the other doesn't, and there // is an extra `&` on the `rc`. We want to be sure that the lifetime // assigned to this `&rc` value is not `'a` but something smaller. In // other words, the type from `rc` is `&'a Rc` and the type diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index 12419d4f7e5f7..a7c8c01fab850 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -110,7 +110,7 @@ fn walk(cache: &mut Cache, if let Some(pretty_path) = pretty_path { let entry = cache.get_mut(&pretty_path).unwrap(); // we don't need the source anymore, - // so drop to to reduce memory-usage + // so drop to reduce memory-usage entry.source = String::new(); } } From 10599e464107ccd7628e7189c286073f88b5063b Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 5 May 2016 21:15:15 +0200 Subject: [PATCH 16/22] doc: make RFC references consistent --- src/libstd/net/ip.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libstd/net/ip.rs b/src/libstd/net/ip.rs index adceee6d73ec5..87389299d9b37 100644 --- a/src/libstd/net/ip.rs +++ b/src/libstd/net/ip.rs @@ -89,7 +89,7 @@ impl Ipv4Addr { /// Returns true if this is a loopback address (127.0.0.0/8). /// - /// This property is defined by RFC 6890 + /// This property is defined by RFC 6890. #[stable(since = "1.7.0", feature = "ip_17")] pub fn is_loopback(&self) -> bool { self.octets()[0] == 127 @@ -97,7 +97,7 @@ impl Ipv4Addr { /// Returns true if this is a private address. /// - /// The private address ranges are defined in RFC1918 and include: + /// The private address ranges are defined in RFC 1918 and include: /// /// - 10.0.0.0/8 /// - 172.16.0.0/12 @@ -114,7 +114,7 @@ impl Ipv4Addr { /// Returns true if the address is link-local (169.254.0.0/16). /// - /// This property is defined by RFC 6890 + /// This property is defined by RFC 6890. #[stable(since = "1.7.0", feature = "ip_17")] pub fn is_link_local(&self) -> bool { self.octets()[0] == 169 && self.octets()[1] == 254 @@ -140,7 +140,7 @@ impl Ipv4Addr { /// Returns true if this is a multicast address. /// /// Multicast addresses have a most significant octet between 224 and 239, - /// and is defined by RFC 5771 + /// and is defined by RFC 5771. #[stable(since = "1.7.0", feature = "ip_17")] pub fn is_multicast(&self) -> bool { self.octets()[0] >= 224 && self.octets()[0] <= 239 @@ -354,7 +354,7 @@ impl Ipv6Addr { /// Returns true if this is a unique local address (IPv6). /// - /// Unique local addresses are defined in RFC4193 and have the form fc00::/7. + /// Unique local addresses are defined in RFC 4193 and have the form fc00::/7. pub fn is_unique_local(&self) -> bool { (self.segments()[0] & 0xfe00) == 0xfc00 } From 89aa04299451baf73750c8480d14471dfced44db Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 3 May 2016 19:15:59 +0200 Subject: [PATCH 17/22] rustdoc: add "src" links to individual impls Since these impls can be scattered around quite a bit, it is nice to be able to jump to the location where individual methods and trait impls are defined. Fixes: #30416 --- src/librustdoc/html/render.rs | 98 +++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 39 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 5cdddc76582b3..96a9315599f9a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -145,14 +145,19 @@ pub struct Implementor { /// Metadata about implementations for a type. #[derive(Clone)] pub struct Impl { - pub impl_: clean::Impl, - pub dox: Option, - pub stability: Option, + pub impl_item: clean::Item, } impl Impl { + fn inner_impl(&self) -> &clean::Impl { + match self.impl_item.inner { + clean::ImplItem(ref impl_) => impl_, + _ => panic!("non-impl item found in impl") + } + } + fn trait_did(&self) -> Option { - self.impl_.trait_.def_id() + self.inner_impl().trait_.def_id() } } @@ -1189,31 +1194,34 @@ impl DocFolder for Cache { // Once we've recursively found all the generics, then hoard off all the // implementations elsewhere let ret = self.fold_item_recur(item).and_then(|item| { - if let clean::Item { attrs, inner: clean::ImplItem(i), .. } = item { + if let clean::Item { inner: clean::ImplItem(_), .. } = item { // Figure out the id of this impl. This may map to a // primitive rather than always to a struct/enum. - let did = match i.for_ { - clean::ResolvedPath { did, .. } | - clean::BorrowedRef { - type_: box clean::ResolvedPath { did, .. }, .. - } => { - Some(did) - } - ref t => { - t.primitive_type().and_then(|t| { - self.primitive_locations.get(&t).map(|n| { - let id = t.to_def_index(); - DefId { krate: *n, index: id } + // Note: matching twice to restrict the lifetime of the `i` borrow. + let did = if let clean::Item { inner: clean::ImplItem(ref i), .. } = item { + match i.for_ { + clean::ResolvedPath { did, .. } | + clean::BorrowedRef { + type_: box clean::ResolvedPath { did, .. }, .. + } => { + Some(did) + } + ref t => { + t.primitive_type().and_then(|t| { + self.primitive_locations.get(&t).map(|n| { + let id = t.to_def_index(); + DefId { krate: *n, index: id } + }) }) - }) + } } + } else { + unreachable!() }; if !self.seen_mod { if let Some(did) = did { self.impls.entry(did).or_insert(vec![]).push(Impl { - impl_: i, - dox: attrs.value("doc").map(|s|s.to_owned()), - stability: item.stability.clone(), + impl_item: item, }); } } @@ -1510,11 +1518,15 @@ impl<'a> Item<'a> { // located, then we return `None`. } else { let cache = cache(); - let path = &cache.external_paths[&self.item.def_id]; - let root = match cache.extern_locations[&self.item.def_id.krate] { - (_, Remote(ref s)) => s.to_string(), - (_, Local) => self.cx.root_path.clone(), - (_, Unknown) => return None, + let path = match cache.external_paths.get(&self.item.def_id) { + Some(path) => path, + None => return None, + }; + let root = match cache.extern_locations.get(&self.item.def_id.krate) { + Some(&(_, Remote(ref s))) => s.to_string(), + Some(&(_, Local)) => self.cx.root_path.clone(), + Some(&(_, Unknown)) => return None, + None => return None, }; Some(format!("{root}{path}/{file}?gotosrc={goto}", root = root, @@ -2449,7 +2461,7 @@ fn render_assoc_items(w: &mut fmt::Formatter, None => return Ok(()), }; let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| { - i.impl_.trait_.is_none() + i.inner_impl().trait_.is_none() }); if !non_trait.is_empty() { let render_header = match what { @@ -2473,7 +2485,7 @@ fn render_assoc_items(w: &mut fmt::Formatter, } if !traits.is_empty() { let deref_impl = traits.iter().find(|t| { - t.impl_.trait_.def_id() == c.deref_trait_did + t.inner_impl().trait_.def_id() == c.deref_trait_did }); if let Some(impl_) = deref_impl { render_deref_methods(w, cx, impl_, containing_item)?; @@ -2481,11 +2493,11 @@ fn render_assoc_items(w: &mut fmt::Formatter, write!(w, "

Trait \ Implementations

")?; let (derived, manual): (Vec<_>, Vec<&Impl>) = traits.iter().partition(|i| { - i.impl_.derived + i.inner_impl().derived }); for i in &manual { let did = i.trait_did().unwrap(); - let assoc_link = AssocItemLink::GotoSource(did, &i.impl_.provided_trait_methods); + let assoc_link = AssocItemLink::GotoSource(did, &i.inner_impl().provided_trait_methods); render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?; } if !derived.is_empty() { @@ -2494,7 +2506,8 @@ fn render_assoc_items(w: &mut fmt::Formatter, ")?; for i in &derived { let did = i.trait_did().unwrap(); - let assoc_link = AssocItemLink::GotoSource(did, &i.impl_.provided_trait_methods); + let assoc_link = AssocItemLink::GotoSource(did, + &i.inner_impl().provided_trait_methods); render_impl(w, cx, i, assoc_link, true, containing_item.stable_since())?; } } @@ -2504,8 +2517,8 @@ fn render_assoc_items(w: &mut fmt::Formatter, fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl, container_item: &clean::Item) -> fmt::Result { - let deref_type = impl_.impl_.trait_.as_ref().unwrap(); - let target = impl_.impl_.items.iter().filter_map(|item| { + let deref_type = impl_.inner_impl().trait_.as_ref().unwrap(); + let target = impl_.inner_impl().items.iter().filter_map(|item| { match item.inner { clean::TypedefItem(ref t, true) => Some(&t.type_), _ => None, @@ -2531,11 +2544,18 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl, fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLink, render_header: bool, outer_version: Option<&str>) -> fmt::Result { if render_header { - write!(w, "

{}", i.impl_)?; - let since = i.stability.as_ref().map(|s| &s.since[..]); + write!(w, "

{}", i.inner_impl())?; + let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]); render_stability_since_raw(w, since, outer_version)?; - write!(w, "

")?; - if let Some(ref dox) = i.dox { + write!(w, "")?; + if let Some(l) = (Item { item: &i.impl_item, cx: cx }).href() { + write!(w, "[src]", + i.impl_item.def_id.index.as_usize(), l, "goto source code")?; + } + write!(w, "")?; + write!(w, "\n")?; + if let Some(ref dox) = i.impl_item.attrs.value("doc") { write!(w, "
{}
", Markdown(dox))?; } } @@ -2601,7 +2621,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } write!(w, "
")?; - for trait_item in &i.impl_.items { + for trait_item in &i.inner_impl().items { doctraititem(w, cx, trait_item, link, render_header, false, outer_version)?; } @@ -2629,7 +2649,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi // default items which weren't overridden in the implementation block. if let Some(did) = i.trait_did() { if let Some(t) = cache().traits.get(&did) { - render_default_items(w, cx, t, &i.impl_, render_header, outer_version)?; + render_default_items(w, cx, t, &i.inner_impl(), render_header, outer_version)?; } } write!(w, "
")?; From 32edf1d7a81a0db65282374daf846727c8e2a8fd Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Fri, 6 May 2016 11:18:05 +0200 Subject: [PATCH 18/22] Fix Typo in Barrier::wait documentation This should be `have` instead of `has`. --- src/libstd/sync/barrier.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sync/barrier.rs b/src/libstd/sync/barrier.rs index b543240c15afb..b1267acdee61a 100644 --- a/src/libstd/sync/barrier.rs +++ b/src/libstd/sync/barrier.rs @@ -71,7 +71,7 @@ impl Barrier { } } - /// Blocks the current thread until all threads has rendezvoused here. + /// Blocks the current thread until all threads have rendezvoused here. /// /// Barriers are re-usable after all threads have rendezvoused once, and can /// be used continuously. From 40025e8cd3214488444d34b2074e68231c8f1fc2 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 6 May 2016 09:07:05 -0400 Subject: [PATCH 19/22] Indicate struct names are code-like in doc-comment. --- src/libstd/sync/rwlock.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 09b1b0a939dcd..cfb8ee16cb069 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -38,8 +38,8 @@ use sys_common::rwlock as sys; /// /// # Poisoning /// -/// RwLocks, like Mutexes, will become poisoned on panics. Note, however, that -/// an RwLock may only be poisoned if a panic occurs while it is locked +/// An `RwLock`, like `Mutex`, will become poisoned on a panic. Note, however, +/// that an `RwLock` may only be poisoned if a panic occurs while it is locked /// exclusively (write mode). If a panic occurs in any reader, then the lock /// will not be poisoned. /// From f25cbe62e88a90e060ca65a4467e671c90f68e32 Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Wed, 4 May 2016 14:00:43 -0700 Subject: [PATCH 20/22] Add detailed error explanation for E0389 Cleanup of E0389 Added type-d out version of type in E0389 description --- src/librustc_borrowck/diagnostics.rs | 65 +++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index c7ad0b6a6c606..d2569f0f07449 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -286,6 +286,70 @@ You can read more about cell types in the API documentation: https://doc.rust-lang.org/std/cell/ "##, +E0389: r##" +An attempt was made to mutate data using a non-mutable reference. This +commonly occurs when attempting to assign to a non-mutable reference of a +mutable reference (`&(&mut T)`). + +Example of erroneous code: + +```compile_fail +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + let fancy_ref = &(&mut fancy); + fancy_ref.num = 6; // error: cannot assign to data in a `&` reference + println!("{}", fancy_ref.num); +} +``` + +Here, `&mut fancy` is mutable, but `&(&mut fancy)` is not. Creating an +immutable reference to a value borrows it immutably. There can be multiple +references of type `&(&mut T)` that point to the same value, so they must be +immutable to prevent multiple mutable references to the same value. + +To fix this, either remove the outer reference: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + + let fancy_ref = &mut fancy; + // `fancy_ref` is now &mut FancyNum, rather than &(&mut FancyNum) + + fancy_ref.num = 6; // No error! + + println!("{}", fancy_ref.num); +} +``` + +Or make the outer reference mutable: + +``` +struct FancyNum { + num: u8 +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + + let fancy_ref = &mut (&mut fancy); + // `fancy_ref` is now &mut(&mut FancyNum), rather than &(&mut FancyNum) + + fancy_ref.num = 6; // No error! + + println!("{}", fancy_ref.num); +} +``` +"##, + E0499: r##" A variable was borrowed as mutable more than once. Erroneous code example: @@ -434,7 +498,6 @@ http://doc.rust-lang.org/stable/book/references-and-borrowing.html register_diagnostics! { E0385, // {} in an aliasable location E0388, // {} in a static location - E0389, // {} in a `&` reference E0500, // closure requires unique access to `..` but .. is already borrowed E0501, // cannot borrow `..`.. as .. because previous closure requires unique access E0502, // cannot borrow `..`.. as .. because .. is also borrowed as ... From 8e9008dc307f97f596add6cbb27d3b1ca1b88d4a Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 5 May 2016 23:55:08 +0200 Subject: [PATCH 21/22] doc: mut not needed --- src/libstd/io/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index ca15aa2d56c49..46c6a23d8d4e8 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -182,7 +182,7 @@ //! //! # fn foo() -> io::Result<()> { //! let f = try!(File::open("foo.txt")); -//! let mut reader = BufReader::new(f); +//! let reader = BufReader::new(f); //! //! for line in reader.lines() { //! let line = try!(line); From 9f935c8dd891ec6eb0809b8438656d1b39c2e2f5 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 5 May 2016 23:55:36 +0200 Subject: [PATCH 22/22] doc: binding not needed --- src/libstd/io/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 46c6a23d8d4e8..a058337a50afd 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -185,8 +185,7 @@ //! let reader = BufReader::new(f); //! //! for line in reader.lines() { -//! let line = try!(line); -//! println!("{}", line); +//! println!("{}", try!(line)); //! } //! //! # Ok(())