Skip to content

Commit b324fa7

Browse files
committed
Auto merge of #33081 - steveklabnik:rollup, r=steveklabnik
Rollup of 6 pull requests - Successful merges: #32558, #32906, #33007, #33008, #33035, #33058 - Failed merges: #32912
2 parents d007824 + ec44ddc commit b324fa7

File tree

9 files changed

+74
-52
lines changed

9 files changed

+74
-52
lines changed

RELEASES.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ Cargo
140140
Performance
141141
-----------
142142

143-
* [During type unification, the complexity of comparing variables for
144-
equivalance was reduced from `O(n!)` to `O(n)`][1.9tu]. This leads
145-
to major compile-time improvements in some scenarios.
143+
* [The time complexity of comparing variables for equivalence during type
144+
unification is reduced from _O_(_n_!) to _O_(_n_)][1.9tu]. This leads
145+
to major compilation time improvement in some scenarios.
146146
* [`ToString` is specialized for `str`, giving it the same performance
147147
as `to_owned`][1.9ts].
148148
* [Spawning processes with `Command::output` no longer creates extra

src/doc/book/mutability.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ changed from one `i32` to another.
2424

2525
[vb]: variable-bindings.html
2626

27-
If you want to change what the binding points to, you’ll need a [mutable reference][mr]:
27+
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:
2828

2929
```rust
3030
let mut x = 5;
3131
let y = &mut x;
3232
```
3333

34-
[mr]: references-and-borrowing.html
34+
[ref]: references-and-borrowing.html
3535

36-
`y` is an immutable binding to a mutable reference, which means that you can’t
37-
bind `y` to something else (`y = &mut z`), but you can mutate the thing that’s
38-
bound to `y` (`*y = 5`). A subtle distinction.
36+
`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.
3937

4038
Of course, if you need both:
4139

src/doc/book/ownership.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ For example if we truncated the vector to just two elements through `v2`:
173173
v2.truncate(2);
174174
```
175175

176-
and `v1` were still accessible we'd end up with an invalid vector since `v1`
176+
and `v` were still accessible we'd end up with an invalid vector since `v`
177177
would not know that the heap data has been truncated. Now, the part of the
178-
vector `v1` on the stack does not agree with the corresponding part on the
179-
heap. `v1` still thinks there are three elements in the vector and will
180-
happily let us access the non existent element `v1[2]` but as you might
178+
vector `v` on the stack does not agree with the corresponding part on the
179+
heap. `v` still thinks there are three elements in the vector and will
180+
happily let us access the non existent element `v[2]` but as you might
181181
already know this is a recipe for disaster. Especially because it might lead
182182
to a segmentation fault or worse allow an unauthorized user to read from
183183
memory to which they don't have access.

src/doc/book/primitive-types.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,10 @@ and `i64` is a signed, 64-bit integer.
9797

9898
## Variable-size types
9999

100-
Rust also provides types whose size depends on the size of a pointer of the
101-
underlying machine. These types have ‘size’ as the category, and come in signed
102-
and unsigned varieties. This makes for two types: `isize` and `usize`.
100+
Rust also provides types whose particular size depends on the underlying machine
101+
architecture. Their range is sufficient to express the size of any collection, so
102+
these types have ‘size’ as the category. They come in signed and unsigned varieties
103+
which account for two types: `isize` and `usize`.
103104

104105
## Floating-point types
105106

src/librustc_typeck/diagnostics.rs

+6-27
Original file line numberDiff line numberDiff line change
@@ -1420,45 +1420,24 @@ fn main() {
14201420
"##,
14211421

14221422
E0102: r##"
1423-
You hit this error because the compiler lacks information to
1424-
determine a type for this variable. Erroneous code example:
1423+
You hit this error because the compiler lacks the information to
1424+
determine the type of this variable. Erroneous code example:
14251425
14261426
```compile_fail
1427-
fn demo(devil: fn () -> !) {
1428-
let x: &_ = devil();
1429-
// error: cannot determine a type for this local variable
1430-
}
1431-
1432-
fn oh_no() -> ! { panic!("the devil is in the details") }
1433-
14341427
fn main() {
1435-
demo(oh_no);
1428+
// could be an array of anything
1429+
let x = []; // error: cannot determine a type for this local variable
14361430
}
14371431
```
14381432
14391433
To solve this situation, constrain the type of the variable.
14401434
Examples:
14411435
1442-
```no_run
1436+
```
14431437
#![allow(unused_variables)]
14441438
1445-
fn some_func(x: &u32) {
1446-
// some code
1447-
}
1448-
1449-
fn demo(devil: fn () -> !) {
1450-
let x: &u32 = devil();
1451-
// Here we defined the type at the variable creation
1452-
1453-
let x: &_ = devil();
1454-
some_func(x);
1455-
// Here, the type is determined by the function argument type
1456-
}
1457-
1458-
fn oh_no() -> ! { panic!("the devil is in the details") }
1459-
14601439
fn main() {
1461-
demo(oh_no);
1440+
let x: [u8; 0] = [];
14621441
}
14631442
```
14641443
"##,

src/librustdoc/clean/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,13 @@ impl Type {
15181518
_ => None,
15191519
}
15201520
}
1521+
1522+
pub fn trait_name(&self) -> Option<String> {
1523+
match *self {
1524+
ResolvedPath { ref path, .. } => Some(path.last_name()),
1525+
_ => None,
1526+
}
1527+
}
15211528
}
15221529

15231530
impl GetDefId for Type {
@@ -2009,6 +2016,10 @@ impl Path {
20092016
}]
20102017
}
20112018
}
2019+
2020+
pub fn last_name(&self) -> String {
2021+
self.segments.last().unwrap().name.clone()
2022+
}
20122023
}
20132024

20142025
impl Clean<Path> for hir::Path {

src/librustdoc/html/format.rs

+23-9
Original file line numberDiff line numberDiff line change
@@ -561,19 +561,33 @@ impl fmt::Display for clean::Type {
561561
}
562562
}
563563

564+
fn fmt_impl(i: &clean::Impl, f: &mut fmt::Formatter, link_trait: bool) -> fmt::Result {
565+
write!(f, "impl{} ", i.generics)?;
566+
if let Some(ref ty) = i.trait_ {
567+
write!(f, "{}",
568+
if i.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" })?;
569+
if link_trait {
570+
write!(f, "{}", *ty)?;
571+
} else {
572+
write!(f, "{}", ty.trait_name().unwrap())?;
573+
}
574+
write!(f, " for ")?;
575+
}
576+
write!(f, "{}{}", i.for_, WhereClause(&i.generics))?;
577+
Ok(())
578+
}
579+
564580
impl fmt::Display for clean::Impl {
565581
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
566-
write!(f, "impl{} ", self.generics)?;
567-
if let Some(ref ty) = self.trait_ {
568-
write!(f, "{}{} for ",
569-
if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" },
570-
*ty)?;
571-
}
572-
write!(f, "{}{}", self.for_, WhereClause(&self.generics))?;
573-
Ok(())
582+
fmt_impl(self, f, true)
574583
}
575584
}
576585

586+
// The difference from above is that trait is not hyperlinked.
587+
pub fn fmt_impl_for_trait_page(i: &clean::Impl, f: &mut fmt::Formatter) -> fmt::Result {
588+
fmt_impl(i, f, false)
589+
}
590+
577591
impl fmt::Display for clean::Arguments {
578592
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
579593
for (i, input) in self.values.iter().enumerate() {
@@ -667,7 +681,7 @@ impl fmt::Display for clean::Import {
667681
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
668682
match *self {
669683
clean::SimpleImport(ref name, ref src) => {
670-
if *name == src.path.segments.last().unwrap().name {
684+
if *name == src.path.last_name() {
671685
write!(f, "use {};", *src)
672686
} else {
673687
write!(f, "use {} as {};", *src, *name)

src/librustdoc/html/render.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use html::escape::Escape;
6969
use html::format::{ConstnessSpace};
7070
use html::format::{TyParamBounds, WhereClause, href, AbiSpace};
7171
use html::format::{VisSpace, Method, UnsafetySpace, MutableSpace};
72+
use html::format::fmt_impl_for_trait_page;
7273
use html::item_type::ItemType;
7374
use html::markdown::{self, Markdown};
7475
use html::{highlight, layout};
@@ -2010,7 +2011,9 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
20102011
match cache.implementors.get(&it.def_id) {
20112012
Some(implementors) => {
20122013
for i in implementors {
2013-
writeln!(w, "<li><code>{}</code></li>", i.impl_)?;
2014+
write!(w, "<li><code>")?;
2015+
fmt_impl_for_trait_page(&i.impl_, w)?;
2016+
writeln!(w, "</code></li>")?;
20142017
}
20152018
}
20162019
None => {}

src/test/rustdoc/trait-self-link.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// @!has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
12+
pub trait Foo {}
13+
14+
pub struct Bar;
15+
16+
impl Foo for Bar {}

0 commit comments

Comments
 (0)