Skip to content

Commit b75fe81

Browse files
committed
Auto merge of #28897 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #28836, #28856, #28874, #28876, #28878, #28880, #28882, #28885, #28889, #28896 - Failed merges:
2 parents bcd27eb + 0fbf7ea commit b75fe81

16 files changed

+178
-84
lines changed

src/doc/style/style/comments.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ Use inner doc comments _only_ to document crates and file-level modules:
8585
//!
8686
//! The core library is a something something...
8787
```
88+
89+
### Explain context.
90+
91+
Rust doesn't have special constructors, only functions that return new
92+
instances. These aren't visible in the automatically generated documentation
93+
for a type, so you should specifically link to them:
94+
95+
``` rust
96+
/// An iterator that yields `None` forever after the underlying iterator
97+
/// yields `None` once.
98+
///
99+
/// These can be created through
100+
/// [`iter.fuse()`](trait.Iterator.html#method.fuse).
101+
pub struct Fuse<I> {
102+
// ...
103+
}
104+
```

src/doc/trpl/advanced-linking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ shells out to the system linker (`gcc` on most systems, `link.exe` on MSVC),
2626
so it makes sense to provide extra command line
2727
arguments, but this will not always be the case. In the future `rustc` may use
2828
LLVM directly to link native libraries, in which case `link_args` will have no
29-
meaning. You can achieve the same effect as the `link-args` attribute with the
29+
meaning. You can achieve the same effect as the `link_args` attribute with the
3030
`-C link-args` argument to `rustc`.
3131

3232
It is highly recommended to *not* use this attribute, and rather use the more
@@ -71,7 +71,7 @@ Dynamic linking on Linux can be undesirable if you wish to use new library
7171
features on old systems or target systems which do not have the required
7272
dependencies for your program to run.
7373

74-
Static linking is supported via an alternative `libc`, `musl`. You can compile
74+
Static linking is supported via an alternative `libc`, [`musl`](http://www.musl-libc.org). You can compile
7575
your own version of Rust with `musl` enabled and install it into a custom
7676
directory with the instructions below:
7777

src/doc/trpl/closures.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
% Closures
22

3-
Rust not only has named functions, but anonymous functions as well. Anonymous
4-
functions that have an associated environment are called ‘closures’, because they
5-
close over an environment. Rust has a really great implementation of them, as
6-
we’ll see.
3+
Sometimes it is useful to wrap up a function and _free variables_ for better
4+
clarity and reuse. The free variables that can be used come from the
5+
enclosing scope and are ‘closed over’ when used in the function. From this, we
6+
get the name ‘closures’ and Rust provides a really great implementation of
7+
them, as we’ll see.
78

89
# Syntax
910

@@ -34,7 +35,7 @@ assert_eq!(4, plus_two(2));
3435
```
3536

3637
You’ll notice a few things about closures that are a bit different from regular
37-
functions defined with `fn`. The first is that we did not need to
38+
named functions defined with `fn`. The first is that we did not need to
3839
annotate the types of arguments the closure takes or the values it returns. We
3940
can:
4041

@@ -44,14 +45,15 @@ let plus_one = |x: i32| -> i32 { x + 1 };
4445
assert_eq!(2, plus_one(1));
4546
```
4647

47-
But we don’t have to. Why is this? Basically, it was chosen for ergonomic reasons.
48-
While specifying the full type for named functions is helpful with things like
49-
documentation and type inference, the types of closures are rarely documented
50-
since they’re anonymous, and they don’t cause the kinds of error-at-a-distance
51-
problems that inferring named function types can.
48+
But we don’t have to. Why is this? Basically, it was chosen for ergonomic
49+
reasons. While specifying the full type for named functions is helpful with
50+
things like documentation and type inference, the full type signatures of
51+
closures are rarely documented since they’re anonymous, and they don’t cause
52+
the kinds of error-at-a-distance problems that inferring named function types
53+
can.
5254

53-
The second is that the syntax is similar, but a bit different. I’ve added spaces
54-
here for easier comparison:
55+
The second is that the syntax is similar, but a bit different. I’ve added
56+
spaces here for easier comparison:
5557

5658
```rust
5759
fn plus_one_v1 (x: i32) -> i32 { x + 1 }
@@ -63,8 +65,8 @@ Small differences, but they’re similar.
6365

6466
# Closures and their environment
6567

66-
Closures are called such because they ‘close over their environment’. It
67-
looks like this:
68+
The environment for a closure can include bindings from its enclosing scope in
69+
addition to parameters and local bindings. It looks like this:
6870

6971
```rust
7072
let num = 5;
@@ -197,9 +199,10 @@ frame. Without `move`, a closure may be tied to the stack frame that created
197199
it, while a `move` closure is self-contained. This means that you cannot
198200
generally return a non-`move` closure from a function, for example.
199201

200-
But before we talk about taking and returning closures, we should talk some more
201-
about the way that closures are implemented. As a systems language, Rust gives
202-
you tons of control over what your code does, and closures are no different.
202+
But before we talk about taking and returning closures, we should talk some
203+
more about the way that closures are implemented. As a systems language, Rust
204+
gives you tons of control over what your code does, and closures are no
205+
different.
203206

204207
# Closure implementation
205208

@@ -288,9 +291,9 @@ isn’t interesting. The next part is:
288291
# some_closure(1) }
289292
```
290293

291-
Because `Fn` is a trait, we can bound our generic with it. In this case, our closure
292-
takes a `i32` as an argument and returns an `i32`, and so the generic bound we use
293-
is `Fn(i32) -> i32`.
294+
Because `Fn` is a trait, we can bound our generic with it. In this case, our
295+
closure takes a `i32` as an argument and returns an `i32`, and so the generic
296+
bound we use is `Fn(i32) -> i32`.
294297

295298
There’s one other key point here: because we’re bounding a generic with a
296299
trait, this will get monomorphized, and therefore, we’ll be doing static
@@ -452,7 +455,7 @@ autogenerated name.
452455
The error also points out that the return type is expected to be a reference,
453456
but what we are trying to return is not. Further, we cannot directly assign a
454457
`'static` lifetime to an object. So we'll take a different approach and return
455-
a "trait object" by `Box`ing up the `Fn`. This _almost_ works:
458+
a trait object by `Box`ing up the `Fn`. This _almost_ works:
456459

457460
```rust,ignore
458461
fn factory() -> Box<Fn(i32) -> i32> {

src/doc/trpl/crates-and-modules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ What's going on here?
563563
First, both `extern crate` and `use` allow renaming the thing that is being
564564
imported. So the crate is still called "phrases", but here we will refer
565565
to it as "sayings". Similarly, the first `use` statement pulls in the
566-
`japanese::farewells` module from the crate, but makes it available as
567-
`jp_farewells` as opposed to simply `farewells`. This can help to avoid
566+
`japanese::greetings` module from the crate, but makes it available as
567+
`ja_greetings` as opposed to simply `greetings`. This can help to avoid
568568
ambiguity when importing similarly-named items from different places.
569569
570570
The second `use` statement uses a star glob to bring in _all_ symbols from the

src/doc/trpl/iterators.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ loop is just a handy way to write this `loop`/`match`/`break` construct.
4242
`for` loops aren't the only thing that uses iterators, however. Writing your
4343
own iterator involves implementing the `Iterator` trait. While doing that is
4444
outside of the scope of this guide, Rust provides a number of useful iterators
45-
to accomplish various tasks. Before we talk about those, we should talk about a
46-
Rust anti-pattern. And that's using ranges like this.
45+
to accomplish various tasks. But first, a few notes about limitations of ranges.
4746

48-
Yes, we just talked about how ranges are cool. But ranges are also very
49-
primitive. For example, if you needed to iterate over the contents of a vector,
50-
you may be tempted to write this:
47+
Ranges are very primitive, and we often can use better alternatives. Consider
48+
following Rust anti-pattern: using ranges to emulate a C-style `for` loop. Let’s
49+
suppose you needed to iterate over the contents of a vector. You may be tempted
50+
to write this:
5151

5252
```rust
5353
let nums = vec![1, 2, 3];
@@ -281,8 +281,8 @@ If you are trying to execute a closure on an iterator for its side effects,
281281
just use `for` instead.
282282

283283
There are tons of interesting iterator adapters. `take(n)` will return an
284-
iterator over the next `n` elements of the original iterator. Let's try it out with our infinite
285-
iterator from before:
284+
iterator over the next `n` elements of the original iterator. Let's try it out
285+
with an infinite iterator:
286286

287287
```rust
288288
for i in (1..).take(5) {

src/doc/trpl/lifetimes.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ With that in mind, let’s learn about lifetimes.
4343
Lending out a reference to a resource that someone else owns can be
4444
complicated. For example, imagine this set of operations:
4545

46-
- I acquire a handle to some kind of resource.
47-
- I lend you a reference to the resource.
48-
- I decide I’m done with the resource, and deallocate it, while you still have
46+
1. I acquire a handle to some kind of resource.
47+
2. I lend you a reference to the resource.
48+
3. I decide I’m done with the resource, and deallocate it, while you still have
4949
your reference.
50-
- You decide to use the resource.
50+
4. You decide to use the resource.
5151

5252
Uh oh! Your reference is pointing to an invalid resource. This is called a
5353
dangling pointer or ‘use after free’, when the resource is memory.

src/doc/trpl/patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ match x {
299299
```
300300

301301
This prints `no`, because the `if` applies to the whole of `4 | 5`, and not to
302-
just the `5`, In other words, the the precedence of `if` behaves like this:
302+
just the `5`. In other words, the precedence of `if` behaves like this:
303303

304304
```text
305305
(4 | 5) if y => ...

src/libcore/fmt/builders.rs

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ pub struct DebugStruct<'a, 'b: 'a> {
6161
has_fields: bool,
6262
}
6363

64-
pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str)
64+
pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>,
65+
name: &str)
6566
-> DebugStruct<'a, 'b> {
6667
let result = fmt.write_str(name);
6768
DebugStruct {
@@ -84,7 +85,8 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
8485

8586
if self.is_pretty() {
8687
let mut writer = PadAdapter::new(self.fmt);
87-
fmt::write(&mut writer, format_args!("{}\n{}: {:#?}", prefix, name, value))
88+
fmt::write(&mut writer,
89+
format_args!("{}\n{}: {:#?}", prefix, name, value))
8890
} else {
8991
write!(self.fmt, "{} {}: {:?}", prefix, name, value)
9092
}
@@ -195,10 +197,18 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
195197
self.result = self.result.and_then(|_| {
196198
if self.is_pretty() {
197199
let mut writer = PadAdapter::new(self.fmt);
198-
let prefix = if self.has_fields { "," } else { "" };
200+
let prefix = if self.has_fields {
201+
","
202+
} else {
203+
""
204+
};
199205
fmt::write(&mut writer, format_args!("{}\n{:#?}", prefix, entry))
200206
} else {
201-
let prefix = if self.has_fields { ", " } else { "" };
207+
let prefix = if self.has_fields {
208+
", "
209+
} else {
210+
""
211+
};
202212
write!(self.fmt, "{}{:?}", prefix, entry)
203213
}
204214
});
@@ -207,7 +217,11 @@ impl<'a, 'b: 'a> DebugInner<'a, 'b> {
207217
}
208218

209219
pub fn finish(&mut self) {
210-
let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
220+
let prefix = if self.is_pretty() && self.has_fields {
221+
"\n"
222+
} else {
223+
""
224+
};
211225
self.result = self.result.and_then(|_| self.fmt.write_str(prefix));
212226
}
213227

@@ -232,7 +246,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b
232246
fmt: fmt,
233247
result: result,
234248
has_fields: false,
235-
}
249+
},
236250
}
237251
}
238252

@@ -247,7 +261,9 @@ impl<'a, 'b: 'a> DebugSet<'a, 'b> {
247261
/// Adds the contents of an iterator of entries to the set output.
248262
#[stable(feature = "debug_builders", since = "1.2.0")]
249263
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugSet<'a, 'b>
250-
where D: fmt::Debug, I: IntoIterator<Item=D> {
264+
where D: fmt::Debug,
265+
I: IntoIterator<Item = D>
266+
{
251267
for entry in entries {
252268
self.entry(&entry);
253269
}
@@ -278,7 +294,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a,
278294
fmt: fmt,
279295
result: result,
280296
has_fields: false,
281-
}
297+
},
282298
}
283299
}
284300

@@ -293,7 +309,9 @@ impl<'a, 'b: 'a> DebugList<'a, 'b> {
293309
/// Adds the contents of an iterator of entries to the list output.
294310
#[stable(feature = "debug_builders", since = "1.2.0")]
295311
pub fn entries<D, I>(&mut self, entries: I) -> &mut DebugList<'a, 'b>
296-
where D: fmt::Debug, I: IntoIterator<Item=D> {
312+
where D: fmt::Debug,
313+
I: IntoIterator<Item = D>
314+
{
297315
for entry in entries {
298316
self.entry(&entry);
299317
}
@@ -335,10 +353,19 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
335353
self.result = self.result.and_then(|_| {
336354
if self.is_pretty() {
337355
let mut writer = PadAdapter::new(self.fmt);
338-
let prefix = if self.has_fields { "," } else { "" };
339-
fmt::write(&mut writer, format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
356+
let prefix = if self.has_fields {
357+
","
358+
} else {
359+
""
360+
};
361+
fmt::write(&mut writer,
362+
format_args!("{}\n{:#?}: {:#?}", prefix, key, value))
340363
} else {
341-
let prefix = if self.has_fields { ", " } else { "" };
364+
let prefix = if self.has_fields {
365+
", "
366+
} else {
367+
""
368+
};
342369
write!(self.fmt, "{}{:?}: {:?}", prefix, key, value)
343370
}
344371
});
@@ -350,7 +377,10 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
350377
/// Adds the contents of an iterator of entries to the map output.
351378
#[stable(feature = "debug_builders", since = "1.2.0")]
352379
pub fn entries<K, V, I>(&mut self, entries: I) -> &mut DebugMap<'a, 'b>
353-
where K: fmt::Debug, V: fmt::Debug, I: IntoIterator<Item=(K, V)> {
380+
where K: fmt::Debug,
381+
V: fmt::Debug,
382+
I: IntoIterator<Item = (K, V)>
383+
{
354384
for (k, v) in entries {
355385
self.entry(&k, &v);
356386
}
@@ -360,7 +390,11 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
360390
/// Finishes output and returns any error encountered.
361391
#[stable(feature = "debug_builders", since = "1.2.0")]
362392
pub fn finish(&mut self) -> fmt::Result {
363-
let prefix = if self.is_pretty() && self.has_fields { "\n" } else { "" };
393+
let prefix = if self.is_pretty() && self.has_fields {
394+
"\n"
395+
} else {
396+
""
397+
};
364398
self.result.and_then(|_| write!(self.fmt, "{}}}", prefix))
365399
}
366400

src/libcore/fmt/num.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ trait GenericRadix {
4848
fn base(&self) -> u8;
4949

5050
/// A radix-specific prefix string.
51-
fn prefix(&self) -> &'static str { "" }
51+
fn prefix(&self) -> &'static str {
52+
""
53+
}
5254

5355
/// Converts an integer to corresponding radix digit.
5456
fn digit(&self, x: u8) -> u8;
@@ -70,7 +72,10 @@ trait GenericRadix {
7072
x = x / base; // Deaccumulate the number.
7173
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
7274
curr -= 1;
73-
if x == zero { break }; // No more digits left to accumulate.
75+
if x == zero {
76+
// No more digits left to accumulate.
77+
break
78+
};
7479
}
7580
} else {
7681
// Do the same as above, but accounting for two's complement.
@@ -79,7 +84,10 @@ trait GenericRadix {
7984
x = x / base; // Deaccumulate the number.
8085
*byte = self.digit(n.to_u8()); // Store the digit in the buffer.
8186
curr -= 1;
82-
if x == zero { break }; // No more digits left to accumulate.
87+
if x == zero {
88+
// No more digits left to accumulate.
89+
break
90+
};
8391
}
8492
}
8593
let buf = unsafe { str::from_utf8_unchecked(&buf[curr..]) };
@@ -141,13 +149,17 @@ pub struct Radix {
141149

142150
impl Radix {
143151
fn new(base: u8) -> Radix {
144-
assert!(2 <= base && base <= 36, "the base must be in the range of 2..36: {}", base);
152+
assert!(2 <= base && base <= 36,
153+
"the base must be in the range of 2..36: {}",
154+
base);
145155
Radix { base: base }
146156
}
147157
}
148158

149159
impl GenericRadix for Radix {
150-
fn base(&self) -> u8 { self.base }
160+
fn base(&self) -> u8 {
161+
self.base
162+
}
151163
fn digit(&self, x: u8) -> u8 {
152164
match x {
153165
x @ 0 ... 9 => b'0' + x,

0 commit comments

Comments
 (0)