about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-04-18 12:03:14 -0700
committerbors <bors@rust-lang.org>2016-04-18 12:03:14 -0700
commitb324fa7204dbdc17544d4402ffd0b1964df326f7 (patch)
tree67e4bcf0b273718594c1dd33c6dcace22c48aeb6 /src
parentd00782494b47ca7a4ae8e665f99ab10012b45f9c (diff)
parentec44ddc33a77192f2b9a03ec1747200f0fcb9ac3 (diff)
downloadrust-b324fa7204dbdc17544d4402ffd0b1964df326f7.tar.gz
rust-b324fa7204dbdc17544d4402ffd0b1964df326f7.zip
Auto merge of #33081 - steveklabnik:rollup, r=steveklabnik
Rollup of 6 pull requests

- Successful merges: #32558, #32906, #33007, #33008, #33035, #33058
- Failed merges: #32912
Diffstat (limited to 'src')
-rw-r--r--src/doc/book/mutability.md8
-rw-r--r--src/doc/book/ownership.md8
-rw-r--r--src/doc/book/primitive-types.md7
-rw-r--r--src/librustc_typeck/diagnostics.rs33
-rw-r--r--src/librustdoc/clean/mod.rs11
-rw-r--r--src/librustdoc/html/format.rs32
-rw-r--r--src/librustdoc/html/render.rs5
-rw-r--r--src/test/rustdoc/trait-self-link.rs16
8 files changed, 71 insertions, 49 deletions
diff --git a/src/doc/book/mutability.md b/src/doc/book/mutability.md
index 71acb551e6e..6aad3c5f746 100644
--- a/src/doc/book/mutability.md
+++ b/src/doc/book/mutability.md
@@ -24,18 +24,16 @@ changed from one `i32` to another.
 
 [vb]: variable-bindings.html
 
-If you want to change what the binding points to, you’ll need a [mutable reference][mr]:
+You can also create a [reference][ref] to it, using `&x`, but if you want to use the reference to change it, you will need a mutable reference:
 
 ```rust
 let mut x = 5;
 let y = &mut x;
 ```
 
-[mr]: references-and-borrowing.html
+[ref]: references-and-borrowing.html
 
-`y` is an immutable binding to a mutable reference, which means that you can’t
-bind `y` to something else (`y = &mut z`), but you can mutate the thing that’s
-bound to `y` (`*y = 5`). A subtle distinction.
+`y` is an immutable binding to a mutable reference, which means that you can’t bind 'y' to something else (`y = &mut z`), but `y` can be used to bind `x` to something else (`*y = 5`). A subtle distinction.
 
 Of course, if you need both:
 
diff --git a/src/doc/book/ownership.md b/src/doc/book/ownership.md
index f8938be30ed..988103a1180 100644
--- a/src/doc/book/ownership.md
+++ b/src/doc/book/ownership.md
@@ -173,11 +173,11 @@ For example if we truncated the vector to just two elements through `v2`:
 v2.truncate(2);
 ```
 
-and `v1` were still accessible we'd end up with an invalid vector since `v1`
+and `v` were still accessible we'd end up with an invalid vector since `v`
 would not know that the heap data has been truncated. Now, the part of the
-vector `v1` on the stack does not agree with the corresponding part on the
-heap. `v1` still thinks there are three elements in the vector and will
-happily let us access the non existent element `v1[2]` but as you might
+vector `v` on the stack does not agree with the corresponding part on the
+heap. `v` still thinks there are three elements in the vector and will
+happily let us access the non existent element `v[2]` but as you might
 already know this is a recipe for disaster. Especially because it might lead
 to a segmentation fault or worse allow an unauthorized user to read from
 memory to which they don't have access.
diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md
index 69040931de6..2a4b7ba37f2 100644
--- a/src/doc/book/primitive-types.md
+++ b/src/doc/book/primitive-types.md
@@ -97,9 +97,10 @@ and `i64` is a signed, 64-bit integer.
 
 ## Variable-size types
 
-Rust also provides types whose size depends on the size of a pointer of the
-underlying machine. These types have ‘size’ as the category, and come in signed
-and unsigned varieties. This makes for two types: `isize` and `usize`.
+Rust also provides types whose particular size depends on the underlying machine
+architecture. Their range is sufficient to express the size of any collection, so
+these types have ‘size’ as the category. They come in signed and unsigned varieties
+which account for two types: `isize` and `usize`.
 
 ## Floating-point types
 
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 646efe09da8..582b9696bb1 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -1420,45 +1420,24 @@ fn main() {
 "##,
 
 E0102: r##"
-You hit this error because the compiler lacks information to
-determine a type for this variable. Erroneous code example:
+You hit this error because the compiler lacks the information to
+determine the type of this variable. Erroneous code example:
 
 ```compile_fail
-fn demo(devil: fn () -> !) {
-    let x: &_ = devil();
-    // error: cannot determine a type for this local variable
-}
-
-fn oh_no() -> ! { panic!("the devil is in the details") }
-
 fn main() {
-    demo(oh_no);
+    // could be an array of anything
+    let x = []; // error: cannot determine a type for this local variable
 }
 ```
 
 To solve this situation, constrain the type of the variable.
 Examples:
 
-```no_run
+```
 #![allow(unused_variables)]
 
-fn some_func(x: &u32) {
-    // some code
-}
-
-fn demo(devil: fn () -> !) {
-    let x: &u32 = devil();
-    // Here we defined the type at the variable creation
-
-    let x: &_ = devil();
-    some_func(x);
-    // Here, the type is determined by the function argument type
-}
-
-fn oh_no() -> ! { panic!("the devil is in the details") }
-
 fn main() {
-    demo(oh_no);
+    let x: [u8; 0] = [];
 }
 ```
 "##,
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 42db93e1803..023da1612e6 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -1518,6 +1518,13 @@ impl Type {
             _ => None,
         }
     }
+
+    pub fn trait_name(&self) -> Option<String> {
+        match *self {
+            ResolvedPath { ref path, .. } => Some(path.last_name()),
+            _ => None,
+        }
+    }
 }
 
 impl GetDefId for Type {
@@ -2009,6 +2016,10 @@ impl Path {
             }]
         }
     }
+
+    pub fn last_name(&self) -> String {
+        self.segments.last().unwrap().name.clone()
+    }
 }
 
 impl Clean<Path> for hir::Path {
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index d2b43ae5bda..1a228b4af8b 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -561,19 +561,33 @@ impl fmt::Display for clean::Type {
     }
 }
 
+fn fmt_impl(i: &clean::Impl, f: &mut fmt::Formatter, link_trait: bool) -> fmt::Result {
+    write!(f, "impl{} ", i.generics)?;
+    if let Some(ref ty) = i.trait_ {
+        write!(f, "{}",
+               if i.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" })?;
+        if link_trait {
+            write!(f, "{}", *ty)?;
+        } else {
+            write!(f, "{}", ty.trait_name().unwrap())?;
+        }
+        write!(f, " for ")?;
+    }
+    write!(f, "{}{}", i.for_, WhereClause(&i.generics))?;
+    Ok(())
+}
+
 impl fmt::Display for clean::Impl {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "impl{} ", self.generics)?;
-        if let Some(ref ty) = self.trait_ {
-            write!(f, "{}{} for ",
-                   if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
-                   *ty)?;
-        }
-        write!(f, "{}{}", self.for_, WhereClause(&self.generics))?;
-        Ok(())
+        fmt_impl(self, f, true)
     }
 }
 
+// The difference from above is that trait is not hyperlinked.
+pub fn fmt_impl_for_trait_page(i: &clean::Impl, f: &mut fmt::Formatter) -> fmt::Result {
+    fmt_impl(i, f, false)
+}
+
 impl fmt::Display for clean::Arguments {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         for (i, input) in self.values.iter().enumerate() {
@@ -667,7 +681,7 @@ impl fmt::Display for clean::Import {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             clean::SimpleImport(ref name, ref src) => {
-                if *name == src.path.segments.last().unwrap().name {
+                if *name == src.path.last_name() {
                     write!(f, "use {};", *src)
                 } else {
                     write!(f, "use {} as {};", *src, *name)
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 864e10407d5..31071cdc3ca 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -69,6 +69,7 @@ use html::escape::Escape;
 use html::format::{ConstnessSpace};
 use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
 use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
+use html::format::fmt_impl_for_trait_page;
 use html::item_type::ItemType;
 use html::markdown::{self, Markdown};
 use html::{highlight, layout};
@@ -2010,7 +2011,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
     match cache.implementors.get(&it.def_id) {
         Some(implementors) => {
             for i in implementors {
-                writeln!(w, "<li><code>{}</code></li>", i.impl_)?;
+                write!(w, "<li><code>")?;
+                fmt_impl_for_trait_page(&i.impl_, w)?;
+                writeln!(w, "</code></li>")?;
             }
         }
         None => {}
diff --git a/src/test/rustdoc/trait-self-link.rs b/src/test/rustdoc/trait-self-link.rs
new file mode 100644
index 00000000000..3233fb96c5c
--- /dev/null
+++ b/src/test/rustdoc/trait-self-link.rs
@@ -0,0 +1,16 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// @!has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
+pub trait Foo {}
+
+pub struct Bar;
+
+impl Foo for Bar {}