From 46885ee0848ab0d3e07bb677ef332e77b9c258f7 Mon Sep 17 00:00:00 2001 From: jocki84 Date: Sat, 30 Jan 2016 17:43:03 +0100 Subject: [PATCH 01/11] 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(-) diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 840609d1dd629..ed9b32809f1f4 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 From b308a8c036bcc90cf294c84a1d43b80f7223066c Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Tue, 29 Mar 2016 01:11:08 +0900 Subject: [PATCH 02/11] 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(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b26e56008accb..5020b93d925d9 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 e9a883d6d7a01..015f5c91a65df 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 0f436efd70b2e..042d9f011e9a2 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 => {} From 87030f603ba3a0b66387daa87b8b2f836661e51e Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Wed, 6 Apr 2016 01:24:49 +0900 Subject: [PATCH 03/11] 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 diff --git a/src/test/rustdoc/trait-self-link.rs b/src/test/rustdoc/trait-self-link.rs new file mode 100644 index 0000000000000..3233fb96c5c35 --- /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 {} From 069b3a67f52fa5cac91dd14d40110ed081d55166 Mon Sep 17 00:00:00 2001 From: jocki84 Date: Tue, 12 Apr 2016 14:59:55 +0200 Subject: [PATCH 04/11] 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(-) diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index ed9b32809f1f4..e6ef7bcba6c59 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 From a548d4deb67e68c204e9ce66ced741db3b99727f Mon Sep 17 00:00:00 2001 From: jocki84 Date: Tue, 12 Apr 2016 16:03:53 +0200 Subject: [PATCH 05/11] 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(-) diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index e6ef7bcba6c59..3e97570b83113 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 From 63b508006ddf52936efef1dcd87a8dc0a7781683 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Fri, 15 Apr 2016 13:04:33 -0700 Subject: [PATCH 06/11] 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(-) diff --git a/src/doc/book/mutability.md b/src/doc/book/mutability.md index 71acb551e6e3c..6aad3c5f74655 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: From 2ef88c982a307a56dcb01f02697f40ad55f8f916 Mon Sep 17 00:00:00 2001 From: Sander Maijers Date: Fri, 15 Apr 2016 22:33:50 +0200 Subject: [PATCH 07/11] grammar: fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reading this, one item stood out a bit. Small improvements here. . ‘Compile-time’ is not a noun, ‘compilation time’ was meant; . Mathematical formulas are best not rendered as code; . Use the same tense as in other items. --- RELEASES.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 6533102a92d56..b13e138198c99 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -140,9 +140,9 @@ Cargo Performance ----------- -* [During type unification, the complexity of comparing variables for - equivalance was reduced from `O(n!)` to `O(n)`][1.9tu]. This leads - to major compile-time improvements in some scenarios. +* [The complexity of comparing variables for equivalence during type + unification is reduced from O(n!) to O(n)[1.9tu]. This leads + to major compilation time improvement in some scenarios. * [`ToString` is specialized for `str`, giving it the same performance as `to_owned`][1.9ts]. * [Spawning processes with `Command::output` no longer creates extra From 3149ff31bc7751782d2e61bf8ba8a30ac9af7a90 Mon Sep 17 00:00:00 2001 From: Sander Maijers Date: Sat, 16 Apr 2016 10:55:33 +0200 Subject: [PATCH 08/11] style: enhance font of big-O expressions --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index b13e138198c99..c9064d924097c 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -141,7 +141,7 @@ Performance ----------- * [The complexity of comparing variables for equivalence during type - unification is reduced from O(n!) to O(n)[1.9tu]. This leads + unification is reduced from _O_(_n_!) to _O_(_n_)][1.9tu]. This leads to major compilation time improvement in some scenarios. * [`ToString` is specialized for `str`, giving it the same performance as `to_owned`][1.9ts]. From 8ff34c77a201e8eea4a96e53e0907665271703df Mon Sep 17 00:00:00 2001 From: Sander Maijers Date: Sat, 16 Apr 2016 10:58:20 +0200 Subject: [PATCH 09/11] semantics: slightly clarify big-O claim Clarification by more precise specification. --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index c9064d924097c..4b404259480b5 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -140,7 +140,7 @@ Cargo Performance ----------- -* [The complexity of comparing variables for equivalence during type +* [The time complexity of comparing variables for equivalence during type unification is reduced from _O_(_n_!) to _O_(_n_)][1.9tu]. This leads to major compilation time improvement in some scenarios. * [`ToString` is specialized for `str`, giving it the same performance From 06e2e0e18d7617091f2812573ed66ecf4613eaab Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 16 Apr 2016 13:27:33 -0500 Subject: [PATCH 10/11] 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(-) diff --git a/src/doc/book/ownership.md b/src/doc/book/ownership.md index f8938be30ed49..988103a118032 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. From f089cf9b2ff2602edd989480b7cd9d4b8b820f84 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 18 Apr 2016 00:35:06 +0530 Subject: [PATCH 11/11] Update E0102's example (fixes #33057) --- src/librustc_typeck/diagnostics.rs | 33 ++++++------------------------ 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1cfbfb37d34bd..ed74a5166d40a 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] = []; } ``` "##,