From 46885ee0848ab0d3e07bb677ef332e77b9c258f7 Mon Sep 17 00:00:00 2001 From: jocki84 Date: Sat, 30 Jan 2016 17:43:03 +0100 Subject: Reword explanation of 'size' types. Do not reference machine 'pointers' in explanation of 'size' types. --- src/doc/book/primitive-types.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 840609d1dd6..ed9b32809f1 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -97,9 +97,11 @@ and `i64` is a signed, 64-bit integer. ## Variable sized 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 sizes of collections and they +are used to address items in a vector, for example. These types have ‘size’ as +the category, and come in signed and unsigned varieties. This makes for two types: +`isize` and `usize`. ## Floating-point types -- cgit 1.4.1-3-g733a5 From b308a8c036bcc90cf294c84a1d43b80f7223066c Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 29 Mar 2016 01:11:08 +0900 Subject: Avoid linking to itself in implementors section of trait page --- src/librustdoc/clean/mod.rs | 11 +++++++++++ src/librustdoc/html/format.rs | 32 +++++++++++++++++++++++--------- src/librustdoc/html/render.rs | 5 ++++- 3 files changed, 38 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b26e56008ac..5020b93d925 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1505,6 +1505,13 @@ impl Type { _ => None, } } + + pub fn trait_name(&self) -> Option { + match *self { + ResolvedPath { ref path, .. } => Some(path.last_name()), + _ => None, + } + } } impl GetDefId for Type { @@ -1994,6 +2001,10 @@ impl Path { }] } } + + pub fn last_name(&self) -> String { + self.segments.last().unwrap().name.clone() + } } impl Clean for hir::Path { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index e9a883d6d7a..015f5c91a65 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 0f436efd70b..042d9f011e9 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}; @@ -2006,7 +2007,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, "
  • {}
  • ", i.impl_)?; + write!(w, "
  • ")?; + fmt_impl_for_trait_page(&i.impl_, w)?; + writeln!(w, "
  • ")?; } } None => {} -- cgit 1.4.1-3-g733a5 From 87030f603ba3a0b66387daa87b8b2f836661e51e Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Wed, 6 Apr 2016 01:24:49 +0900 Subject: Add a test --- src/test/rustdoc/trait-self-link.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/rustdoc/trait-self-link.rs (limited to 'src') 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 or the MIT license +// , 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 {} -- cgit 1.4.1-3-g733a5 From 069b3a67f52fa5cac91dd14d40110ed081d55166 Mon Sep 17 00:00:00 2001 From: jocki84 Date: Tue, 12 Apr 2016 14:59:55 +0200 Subject: Update primitive-types.md Simplify explanation and rephrase as per @GuillaumeGomez's suggestion. --- src/doc/book/primitive-types.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index ed9b32809f1..e6ef7bcba6c 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -98,10 +98,9 @@ and `i64` is a signed, 64-bit integer. ## Variable sized types Rust also provides types whose particular size depends on the underlying machine -architecture. Their range is sufficient to express sizes of collections and they -are used to address items in a vector, for example. These types have ‘size’ as -the category, and come in signed and unsigned varieties. This makes for two types: -`isize` and `usize`. +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 makes for two types: `isize` and `usize`. ## Floating-point types -- cgit 1.4.1-3-g733a5 From a548d4deb67e68c204e9ce66ced741db3b99727f Mon Sep 17 00:00:00 2001 From: jocki84 Date: Tue, 12 Apr 2016 16:03:53 +0200 Subject: Update primitive-types.md Replace "make for" by the slightly more accurate "account for". --- src/doc/book/primitive-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index e6ef7bcba6c..3e97570b831 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -100,7 +100,7 @@ and `i64` is a signed, 64-bit integer. 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 makes for two types: `isize` and `usize`. +which account for two types: `isize` and `usize`. ## Floating-point types -- cgit 1.4.1-3-g733a5 From 63b508006ddf52936efef1dcd87a8dc0a7781683 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 15 Apr 2016 13:04:33 -0700 Subject: Do not use "bind" to refer to referencing and to variable binding. --- src/doc/book/mutability.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src') 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: -- cgit 1.4.1-3-g733a5 From 06e2e0e18d7617091f2812573ed66ecf4613eaab Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 16 Apr 2016 13:27:33 -0500 Subject: Use `v` instead of `v1` for consistency The code examples and previous paragraphs all use `v` and `v2` --- src/doc/book/ownership.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') 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. -- cgit 1.4.1-3-g733a5 From f089cf9b2ff2602edd989480b7cd9d4b8b820f84 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 18 Apr 2016 00:35:06 +0530 Subject: Update E0102's example (fixes #33057) --- src/librustc_typeck/diagnostics.rs | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1cfbfb37d34..ed74a5166d4 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] = []; } ``` "##, -- cgit 1.4.1-3-g733a5