Skip to content

Commit 59675d2

Browse files
committed
Auto merge of #43800 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 18 pull requests - Successful merges: #43176, #43632, #43650, #43712, #43715, #43721, #43739, #43741, #43744, #43747, #43752, #43760, #43773, #43779, #43783, #43791, #43793, #43795 - Failed merges:
2 parents 9868352 + 742bba0 commit 59675d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+249
-76
lines changed

src/liballoc/arc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const MAX_REFCOUNT: usize = (isize::MAX) as usize;
9595
/// # Cloning references
9696
///
9797
/// Creating a new reference from an existing reference counted pointer is done using the
98-
/// `Clone` trait implemented for [`Arc<T>`][`arc`] and [`Weak<T>`][`weak`].
98+
/// `Clone` trait implemented for [`Arc<T>`][arc] and [`Weak<T>`][weak].
9999
///
100100
/// ```
101101
/// use std::sync::Arc;

src/liballoc/string.rs

+32-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ use boxed::Box;
144144
/// # Deref
145145
///
146146
/// `String`s implement [`Deref`]`<Target=str>`, and so inherit all of [`str`]'s
147-
/// methods. In addition, this means that you can pass a `String` to any
147+
/// methods. In addition, this means that you can pass a `String` to a
148148
/// function which takes a [`&str`] by using an ampersand (`&`):
149149
///
150150
/// ```
@@ -160,8 +160,38 @@ use boxed::Box;
160160
///
161161
/// This will create a [`&str`] from the `String` and pass it in. This
162162
/// conversion is very inexpensive, and so generally, functions will accept
163-
/// [`&str`]s as arguments unless they need a `String` for some specific reason.
163+
/// [`&str`]s as arguments unless they need a `String` for some specific
164+
/// reason.
164165
///
166+
/// In certain cases Rust doesn't have enough information to make this
167+
/// conversion, known as `Deref` coercion. In the following example a string
168+
/// slice `&'a str` implements the trait `TraitExample`, and the function
169+
/// `example_func` takes anything that implements the trait. In this case Rust
170+
/// would need to make two implicit conversions, which Rust doesn't have the
171+
/// means to do. For that reason, the following example will not compile.
172+
///
173+
/// ```compile_fail,E0277
174+
/// trait TraitExample {}
175+
///
176+
/// impl<'a> TraitExample for &'a str {}
177+
///
178+
/// fn example_func<A: TraitExample>(example_arg: A) {}
179+
///
180+
/// fn main() {
181+
/// let example_string = String::from("example_string");
182+
/// example_func(&example_string);
183+
/// }
184+
/// ```
185+
///
186+
/// There are two options that would work instead. The first would be to
187+
/// change the line `example_func(&example_string);` to
188+
/// `example_func(example_string.as_str());`, using the method `as_str()`
189+
/// to explicitly extract the string slice containing the string. The second
190+
/// way changes `example_func(&example_string);` to
191+
/// `example_func(&*example_string);`. In this case we are dereferencing a
192+
/// `String` to a `str`, then referencing the `str` back to `&str`. The
193+
/// second way is more idiomatic, however both work to do the conversion
194+
/// explicitly rather than relying on the implicit conversion.
165195
///
166196
/// # Representation
167197
///

src/librustc/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2197,8 +2197,8 @@ impl<'a, 'tcx> TyLayout<'tcx> {
21972197
let tcx = cx.tcx();
21982198

21992199
let ptr_field_type = |pointee: Ty<'tcx>| {
2200+
assert!(i < 2);
22002201
let slice = |element: Ty<'tcx>| {
2201-
assert!(i < 2);
22022202
if i == 0 {
22032203
tcx.mk_mut_ptr(element)
22042204
} else {

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
563563
Entry {
564564
kind: EntryKind::Mod(self.lazy(&data)),
565565
visibility: self.lazy(&ty::Visibility::from_hir(vis, id, tcx)),
566-
span: self.lazy(&md.inner),
566+
span: self.lazy(&tcx.def_span(def_id)),
567567
attributes: self.encode_attributes(attrs),
568568
children: self.lazy_seq(md.item_ids.iter().map(|item_id| {
569569
tcx.hir.local_def_id(item_id.id).index

src/librustc_typeck/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,9 @@ static BAR: _ = "test"; // error, explicitly write out the type instead
15251525
"##,
15261526

15271527
E0122: r##"
1528-
An attempt was made to add a generic constraint to a type alias. While Rust will
1529-
allow this with a warning, it will not currently enforce the constraint.
1530-
Consider the example below:
1528+
An attempt was made to add a generic constraint to a type alias. This constraint
1529+
is entirely ignored. For backwards compatibility, Rust still allows this with a
1530+
warning. Consider the example below:
15311531
15321532
```
15331533
trait Foo{}

src/librustdoc/html/render.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -2141,8 +2141,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21412141

21422142
if !types.is_empty() {
21432143
write!(w, "
2144-
<h2 id='associated-types' class='section-header'>
2145-
<a href='#associated-types'>Associated Types</a>
2144+
<h2 id='associated-types' class='small-section-header'>
2145+
Associated Types<a href='#associated-types' class='anchor'></a>
21462146
</h2>
21472147
<div class='methods'>
21482148
")?;
@@ -2154,8 +2154,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21542154

21552155
if !consts.is_empty() {
21562156
write!(w, "
2157-
<h2 id='associated-const' class='section-header'>
2158-
<a href='#associated-const'>Associated Constants</a>
2157+
<h2 id='associated-const' class='small-section-header'>
2158+
Associated Constants<a href='#associated-const' class='anchor'></a>
21592159
</h2>
21602160
<div class='methods'>
21612161
")?;
@@ -2168,8 +2168,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21682168
// Output the documentation for each function individually
21692169
if !required.is_empty() {
21702170
write!(w, "
2171-
<h2 id='required-methods' class='section-header'>
2172-
<a href='#required-methods'>Required Methods</a>
2171+
<h2 id='required-methods' class='small-section-header'>
2172+
Required Methods<a href='#required-methods' class='anchor'></a>
21732173
</h2>
21742174
<div class='methods'>
21752175
")?;
@@ -2180,8 +2180,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21802180
}
21812181
if !provided.is_empty() {
21822182
write!(w, "
2183-
<h2 id='provided-methods' class='section-header'>
2184-
<a href='#provided-methods'>Provided Methods</a>
2183+
<h2 id='provided-methods' class='small-section-header'>
2184+
Provided Methods<a href='#provided-methods' class='anchor'></a>
21852185
</h2>
21862186
<div class='methods'>
21872187
")?;
@@ -2196,8 +2196,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
21962196

21972197
let cache = cache();
21982198
write!(w, "
2199-
<h2 id='implementors' class='section-header'>
2200-
<a href='#implementors'>Implementors</a>
2199+
<h2 id='implementors' class='small-section-header'>
2200+
Implementors<a href='#implementors' class='anchor'></a>
22012201
</h2>
22022202
<ul class='item-list' id='implementors-list'>
22032203
")?;
@@ -2436,8 +2436,8 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24362436
}).peekable();
24372437
if let doctree::Plain = s.struct_type {
24382438
if fields.peek().is_some() {
2439-
write!(w, "<h2 id='fields' class='fields section-header'>
2440-
<a href='#fields'>Fields</a></h2>")?;
2439+
write!(w, "<h2 id='fields' class='fields small-section-header'>
2440+
Fields<a href='#fields' class='anchor'></a></h2>")?;
24412441
for (field, ty) in fields {
24422442
let id = derive_id(format!("{}.{}",
24432443
ItemType::StructField,
@@ -2485,8 +2485,8 @@ fn item_union(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
24852485
}
24862486
}).peekable();
24872487
if fields.peek().is_some() {
2488-
write!(w, "<h2 id='fields' class='fields section-header'>
2489-
<a href='#fields'>Fields</a></h2>")?;
2488+
write!(w, "<h2 id='fields' class='fields small-section-header'>
2489+
Fields<a href='#fields' class='anchor'></a></h2>")?;
24902490
for (field, ty) in fields {
24912491
write!(w, "<span id='{shortty}.{name}' class=\"{shortty}\"><code>{name}: {ty}</code>
24922492
</span>",
@@ -2558,8 +2558,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
25582558

25592559
document(w, cx, it)?;
25602560
if !e.variants.is_empty() {
2561-
write!(w, "<h2 id='variants' class='variants section-header'>
2562-
<a href='#variants'>Variants</a></h2>\n")?;
2561+
write!(w, "<h2 id='variants' class='variants small-section-header'>
2562+
Variants<a href='#variants' class='anchor'></a></h2>\n")?;
25632563
for variant in &e.variants {
25642564
let id = derive_id(format!("{}.{}",
25652565
ItemType::Variant,
@@ -2831,16 +2831,16 @@ fn render_assoc_items(w: &mut fmt::Formatter,
28312831
let render_mode = match what {
28322832
AssocItemRender::All => {
28332833
write!(w, "
2834-
<h2 id='methods' class='section-header'>
2835-
<a href='#methods'>Methods</a>
2834+
<h2 id='methods' class='small-section-header'>
2835+
Methods<a href='#methods' class='anchor'></a>
28362836
</h2>
28372837
")?;
28382838
RenderMode::Normal
28392839
}
28402840
AssocItemRender::DerefFor { trait_, type_, deref_mut_ } => {
28412841
write!(w, "
2842-
<h2 id='deref-methods' class='section-header'>
2843-
<a href='#deref-methods'>Methods from {}&lt;Target = {}&gt;</a>
2842+
<h2 id='deref-methods' class='small-section-header'>
2843+
Methods from {}&lt;Target = {}&gt;<a href='#deref-methods' class='anchor'></a>
28442844
</h2>
28452845
", trait_, type_)?;
28462846
RenderMode::ForDeref { mut_: deref_mut_ }
@@ -2865,8 +2865,8 @@ fn render_assoc_items(w: &mut fmt::Formatter,
28652865
render_deref_methods(w, cx, impl_, containing_item, has_deref_mut)?;
28662866
}
28672867
write!(w, "
2868-
<h2 id='implementations' class='section-header'>
2869-
<a href='#implementations'>Trait Implementations</a>
2868+
<h2 id='implementations' class='small-section-header'>
2869+
Trait Implementations<a href='#implementations' class='anchor'></a>
28702870
</h2>
28712871
")?;
28722872
for i in &traits {

src/librustdoc/html/static/rustdoc.css

+15-1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,16 @@ a {
438438
background: transparent;
439439
}
440440

441+
.small-section-header:hover > .anchor {
442+
display: initial;
443+
}
444+
.anchor {
445+
display: none;
446+
}
447+
.anchor:after {
448+
content: '\2002\00a7\2002';
449+
}
450+
441451
.docblock a:hover, .docblock-short a:hover, .stability a {
442452
text-decoration: underline;
443453
}
@@ -677,6 +687,10 @@ span.since {
677687
left: 0;
678688
}
679689

690+
.variant + .toggle-wrapper + .docblock > p {
691+
margin-top: 5px;
692+
}
693+
680694
.variant + .toggle-wrapper > a {
681695
margin-top: 5px;
682696
}
@@ -695,7 +709,7 @@ span.since {
695709
margin-bottom: 25px;
696710
}
697711

698-
.enum .variant, .struct .structfield, .union .structfield {
712+
#main > .variant, #main > .structfield {
699713
display: block;
700714
}
701715

src/libstd/fs.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use time::SystemTime;
2828
/// A reference to an open file on the filesystem.
2929
///
3030
/// An instance of a `File` can be read and/or written depending on what options
31-
/// it was opened with. Files also implement `Seek` to alter the logical cursor
31+
/// it was opened with. Files also implement [`Seek`] to alter the logical cursor
3232
/// that the file contains internally.
3333
///
3434
/// Files are automatically closed when they go out of scope.
@@ -48,7 +48,7 @@ use time::SystemTime;
4848
/// # }
4949
/// ```
5050
///
51-
/// Read the contents of a file into a `String`:
51+
/// Read the contents of a file into a [`String`]:
5252
///
5353
/// ```no_run
5454
/// use std::fs::File;
@@ -81,6 +81,8 @@ use time::SystemTime;
8181
/// # }
8282
/// ```
8383
///
84+
/// [`Seek`]: ../io/trait.Seek.html
85+
/// [`String`]: ../string/struct.String.html
8486
/// [`Read`]: ../io/trait.Read.html
8587
/// [`BufReader<R>`]: ../io/struct.BufReader.html
8688
#[stable(feature = "rust1", since = "1.0.0")]
@@ -104,19 +106,19 @@ pub struct Metadata(fs_imp::FileAttr);
104106
/// Iterator over the entries in a directory.
105107
///
106108
/// This iterator is returned from the [`read_dir`] function of this module and
107-
/// will yield instances of `io::Result<DirEntry>`. Through a [`DirEntry`]
109+
/// will yield instances of [`io::Result`]`<`[`DirEntry`]`>`. Through a [`DirEntry`]
108110
/// information like the entry's path and possibly other metadata can be
109111
/// learned.
110112
///
111-
/// [`read_dir`]: fn.read_dir.html
112-
/// [`DirEntry`]: struct.DirEntry.html
113-
///
114113
/// # Errors
115114
///
116-
/// This [`io::Result`] will be an `Err` if there's some sort of intermittent
115+
/// This [`io::Result`] will be an [`Err`] if there's some sort of intermittent
117116
/// IO error during iteration.
118117
///
118+
/// [`read_dir`]: fn.read_dir.html
119+
/// [`DirEntry`]: struct.DirEntry.html
119120
/// [`io::Result`]: ../io/type.Result.html
121+
/// [`Err`]: ../result/enum.Result.html#variant.Err
120122
#[stable(feature = "rust1", since = "1.0.0")]
121123
#[derive(Debug)]
122124
pub struct ReadDir(fs_imp::ReadDir);

src/libstd/io/error.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ use convert::From;
1717
/// A specialized [`Result`](../result/enum.Result.html) type for I/O
1818
/// operations.
1919
///
20-
/// This type is broadly used across `std::io` for any operation which may
20+
/// This type is broadly used across [`std::io`] for any operation which may
2121
/// produce an error.
2222
///
23-
/// This typedef is generally used to avoid writing out `io::Error` directly and
24-
/// is otherwise a direct mapping to `Result`.
23+
/// This typedef is generally used to avoid writing out [`io::Error`] directly and
24+
/// is otherwise a direct mapping to [`Result`].
2525
///
26-
/// While usual Rust style is to import types directly, aliases of `Result`
27-
/// often are not, to make it easier to distinguish between them. `Result` is
28-
/// generally assumed to be `std::result::Result`, and so users of this alias
26+
/// While usual Rust style is to import types directly, aliases of [`Result`]
27+
/// often are not, to make it easier to distinguish between them. [`Result`] is
28+
/// generally assumed to be [`std::result::Result`][`Result`], and so users of this alias
2929
/// will generally use `io::Result` instead of shadowing the prelude's import
30-
/// of `std::result::Result`.
30+
/// of [`std::result::Result`][`Result`].
31+
///
32+
/// [`std::io`]: ../io/index.html
33+
/// [`io::Error`]: ../io/struct.Error.html
34+
/// [`Result`]: ../result/enum.Result.html
3135
///
3236
/// # Examples
3337
///
@@ -47,13 +51,16 @@ use convert::From;
4751
#[stable(feature = "rust1", since = "1.0.0")]
4852
pub type Result<T> = result::Result<T, Error>;
4953

50-
/// The error type for I/O operations of the `Read`, `Write`, `Seek`, and
54+
/// The error type for I/O operations of the [`Read`], [`Write`], [`Seek`], and
5155
/// associated traits.
5256
///
5357
/// Errors mostly originate from the underlying OS, but custom instances of
5458
/// `Error` can be created with crafted error messages and a particular value of
5559
/// [`ErrorKind`].
5660
///
61+
/// [`Read`]: ../io/trait.Read.html
62+
/// [`Write`]: ../io/trait.Write.html
63+
/// [`Seek`]: ../io/trait.Seek.html
5764
/// [`ErrorKind`]: enum.ErrorKind.html
5865
#[derive(Debug)]
5966
#[stable(feature = "rust1", since = "1.0.0")]

src/libstd/io/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! you'll see a few different types of I/O throughout the documentation in
2323
//! this module: [`File`]s, [`TcpStream`]s, and sometimes even [`Vec<T>`]s. For
2424
//! example, [`Read`] adds a [`read`][`Read::read`] method, which we can use on
25-
//! `File`s:
25+
//! [`File`]s:
2626
//!
2727
//! ```
2828
//! use std::io;
@@ -146,9 +146,9 @@
146146
//! # }
147147
//! ```
148148
//!
149-
//! Note that you cannot use the `?` operator in functions that do not return
150-
//! a `Result<T, E>` (e.g. `main`). Instead, you can call `.unwrap()` or `match`
151-
//! on the return value to catch any possible errors:
149+
//! Note that you cannot use the [`?` operator] in functions that do not return
150+
//! a [`Result<T, E>`][`Result`] (e.g. `main`). Instead, you can call [`.unwrap()`]
151+
//! or `match` on the return value to catch any possible errors:
152152
//!
153153
//! ```
154154
//! use std::io;
@@ -265,6 +265,8 @@
265265
//! [`io::Result`]: type.Result.html
266266
//! [`?` operator]: ../../book/first-edition/syntax-index.html
267267
//! [`Read::read`]: trait.Read.html#tymethod.read
268+
//! [`Result`]: ../result/enum.Result.html
269+
//! [`.unwrap()`]: ../result/enum.Result.html#method.unwrap
268270
269271
#![stable(feature = "rust1", since = "1.0.0")]
270272

src/libstd/net/ip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl Ipv4Addr {
466466
/// - test addresses used for documentation (192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24)
467467
/// - the unspecified address (0.0.0.0)
468468
///
469-
/// [ipv4-sr]: http://goo.gl/RaZ7lg
469+
/// [ipv4-sr]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
470470
/// [`true`]: ../../std/primitive.bool.html
471471
///
472472
/// # Examples

src/libstd/sys/unix/ext/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl UnixListener {
655655
/// Accepts a new incoming connection to this listener.
656656
///
657657
/// This function will block the calling thread until a new Unix connection
658-
/// is established. When established, the corersponding [`UnixStream`] and
658+
/// is established. When established, the corresponding [`UnixStream`] and
659659
/// the remote peer's address will be returned.
660660
///
661661
/// [`UnixStream`]: ../../../../std/os/unix/net/struct.UnixStream.html

0 commit comments

Comments
 (0)