about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-04-28 07:59:02 -0700
committerbors <bors@rust-lang.org>2016-04-28 07:59:02 -0700
commitea6b3ddee9663e27221f366671261b21618394a0 (patch)
tree0343b5361085cbbe94966b0608b7483e54a953c5
parent4751e45521e5a1e70f5cf5086b7712c999546af8 (diff)
parentb9dd8aa4c291ce464655735802e68b26fe9c6862 (diff)
downloadrust-ea6b3ddee9663e27221f366671261b21618394a0.tar.gz
rust-ea6b3ddee9663e27221f366671261b21618394a0.zip
Auto merge of #33257 - steveklabnik:rollup, r=steveklabnik
Rollup of 7 pull requests

- Successful merges: #32991, #33056, #33095, #33152, #33212, #33218, #33234
- Failed merges: #32912
-rw-r--r--src/doc/book/getting-started.md2
-rw-r--r--src/doc/book/lifetimes.md4
-rw-r--r--src/doc/book/ownership.md4
-rw-r--r--src/doc/book/references-and-borrowing.md30
-rw-r--r--src/libcore/ptr.rs3
-rw-r--r--src/librustc/infer/error_reporting.rs2
-rw-r--r--src/libstd/collections/hash/set.rs4
-rw-r--r--src/libsyntax/attr.rs6
-rw-r--r--src/libsyntax/parse/token.rs22
9 files changed, 64 insertions, 13 deletions
diff --git a/src/doc/book/getting-started.md b/src/doc/book/getting-started.md
index 3a20663cda6..fc2a7620883 100644
--- a/src/doc/book/getting-started.md
+++ b/src/doc/book/getting-started.md
@@ -412,7 +412,7 @@ enter the following commands:
 
 ```bash
 $ mkdir src
-$ mv main.rs src/main.rs
+$ mv main.rs src/main.rs # or 'move main.rs src/main.rs' on Windows
 $ rm main  # or 'del main.exe' on Windows
 ```
 
diff --git a/src/doc/book/lifetimes.md b/src/doc/book/lifetimes.md
index 695b1614fb7..cb075731898 100644
--- a/src/doc/book/lifetimes.md
+++ b/src/doc/book/lifetimes.md
@@ -1,7 +1,7 @@
 % Lifetimes
 
-This guide is three of three presenting Rust’s ownership system. This is one of
-Rust’s most unique and compelling features, with which Rust developers should
+This is the last of three sections presenting Rust’s ownership system. This is one of
+Rust’s most distinct and compelling features, with which Rust developers should
 become quite acquainted. Ownership is how Rust achieves its largest goal,
 memory safety. There are a few distinct concepts, each with its own chapter:
 
diff --git a/src/doc/book/ownership.md b/src/doc/book/ownership.md
index 988103a1180..e2e0403b738 100644
--- a/src/doc/book/ownership.md
+++ b/src/doc/book/ownership.md
@@ -1,7 +1,7 @@
 % Ownership
 
-This guide is one of three presenting Rust’s ownership system. This is one of
-Rust’s most unique and compelling features, with which Rust developers should
+This is the first of three sections presenting Rust’s ownership system. This is one of
+Rust’s most distinct and compelling features, with which Rust developers should
 become quite acquainted. Ownership is how Rust achieves its largest goal,
 memory safety. There are a few distinct concepts, each with its own
 chapter:
diff --git a/src/doc/book/references-and-borrowing.md b/src/doc/book/references-and-borrowing.md
index a08d53f958b..a28f450c942 100644
--- a/src/doc/book/references-and-borrowing.md
+++ b/src/doc/book/references-and-borrowing.md
@@ -1,7 +1,7 @@
 % References and Borrowing
 
-This guide is two of three presenting Rust’s ownership system. This is one of
-Rust’s most unique and compelling features, with which Rust developers should
+This is the second of three sections presenting Rust’s ownership system. This is one of
+Rust’s most distinct and compelling features, with which Rust developers should
 become quite acquainted. Ownership is how Rust achieves its largest goal,
 memory safety. There are a few distinct concepts, each with its own
 chapter:
@@ -77,6 +77,32 @@ let answer = foo(&v1, &v2);
 // we can use v1 and v2 here!
 ```
 
+A more concrete example:
+
+```rust
+fn main() {
+    // Don't worry if you don't understand how `fold` works, the point here is that an immutable reference is borrowed.
+    fn sum_vec(v: &Vec<i32>) -> i32 {
+        return v.iter().fold(0, |a, &b| a + b);
+    }
+    // Borrow two vectors and and sum them.
+    // This kind of borrowing does not allow mutation to the borrowed.
+    fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
+        // do stuff with v1 and v2
+        let s1 = sum_vec(v1);
+        let s2 = sum_vec(v2);
+        // return the answer
+        s1 + s2
+    }
+
+    let v1 = vec![1, 2, 3];
+    let v2 = vec![4, 5, 6];
+
+    let answer = foo(&v1, &v2);
+    println!("{}", answer);
+}
+```
+
 Instead of taking `Vec<i32>`s as our arguments, we take a reference:
 `&Vec<i32>`. And instead of passing `v1` and `v2` directly, we pass `&v1` and
 `&v2`. We call the `&T` type a ‘reference’, and rather than owning the resource,
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index a3c7ab481a7..8b3a14b24df 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -459,6 +459,9 @@ impl<T: ?Sized> *mut T {
     /// ```
     /// let mut s = [1, 2, 3];
     /// let ptr: *mut u32 = s.as_mut_ptr();
+    /// let first_value = unsafe { ptr.as_mut().unwrap() };
+    /// *first_value = 4;
+    /// println!("{:?}", s); // It'll print: "[4, 2, 3]".
     /// ```
     #[stable(feature = "ptr_as_ref", since = "1.9.0")]
     #[inline]
diff --git a/src/librustc/infer/error_reporting.rs b/src/librustc/infer/error_reporting.rs
index bcf854009e5..abc6ff4a294 100644
--- a/src/librustc/infer/error_reporting.rs
+++ b/src/librustc/infer/error_reporting.rs
@@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
                         "scope of call-site for function"
                     }
                     region::CodeExtentData::ParameterScope { .. } => {
-                        "scope of parameters for function"
+                        "scope of function body"
                     }
                     region::CodeExtentData::DestructionScope(_) => {
                         new_string = format!("destruction scope surrounding {}", tag);
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index b353a4c1ba1..e4ef3fca55d 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -535,9 +535,9 @@ impl<T, S> HashSet<T, S>
 
     /// Adds a value to the set.
     ///
-    /// If the set did not have a value present, `true` is returned.
+    /// If the set did not have this value present, `true` is returned.
     ///
-    /// If the set did have this key present, `false` is returned.
+    /// If the set did have this value present, `false` is returned.
     ///
     /// # Examples
     ///
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index dd414c463c7..8761ca37178 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -333,11 +333,11 @@ pub enum InlineAttr {
 pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
     attrs.iter().fold(InlineAttr::None, |ia,attr| {
         match attr.node.value.node {
-            MetaItemKind::Word(ref n) if *n == "inline" => {
+            MetaItemKind::Word(ref n) if n == "inline" => {
                 mark_used(attr);
                 InlineAttr::Hint
             }
-            MetaItemKind::List(ref n, ref items) if *n == "inline" => {
+            MetaItemKind::List(ref n, ref items) if n == "inline" => {
                 mark_used(attr);
                 if items.len() != 1 {
                     diagnostic.map(|d|{ d.span_err(attr.span, "expected one argument"); });
@@ -711,7 +711,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
 pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
     let mut acc = Vec::new();
     match attr.node.value.node {
-        ast::MetaItemKind::List(ref s, ref items) if *s == "repr" => {
+        ast::MetaItemKind::List(ref s, ref items) if s == "repr" => {
             mark_used(attr);
             for item in items {
                 match item.node {
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index fcb6c3539db..47de32ed7d0 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -566,6 +566,28 @@ impl<'a> PartialEq<InternedString> for &'a str {
     }
 }
 
+impl PartialEq<str> for InternedString {
+    #[inline(always)]
+    fn eq(&self, other: &str) -> bool {
+        PartialEq::eq(&self.string[..], other)
+    }
+    #[inline(always)]
+    fn ne(&self, other: &str) -> bool {
+        PartialEq::ne(&self.string[..], other)
+    }
+}
+
+impl PartialEq<InternedString> for str {
+    #[inline(always)]
+    fn eq(&self, other: &InternedString) -> bool {
+        PartialEq::eq(self, &other.string[..])
+    }
+    #[inline(always)]
+    fn ne(&self, other: &InternedString) -> bool {
+        PartialEq::ne(self, &other.string[..])
+    }
+}
+
 impl Decodable for InternedString {
     fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
         Ok(intern(d.read_str()?.as_ref()).as_str())