Skip to content

Commit f6f050d

Browse files
committed
Auto merge of #31873 - Manishearth:rollup, r=Manishearth
- Successful merges: #31677, #31784, #31839, #31842, #31843, #31850, #31863, #31868, #31870 - Failed merges:
2 parents 0ef8d42 + b660ca5 commit f6f050d

File tree

17 files changed

+138
-62
lines changed

17 files changed

+138
-62
lines changed

src/doc/book/iterators.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ for i in (1..100).filter(|&x| x % 2 == 0) {
311311
```
312312

313313
This will print all of the even numbers between one and a hundred.
314-
(Note that because `filter` doesn't consume the elements that are
315-
being iterated over, it is passed a reference to each element, and
316-
thus the filter predicate uses the `&x` pattern to extract the integer
317-
itself.)
314+
(Note that, unlike `map`, the closure passed to `filter` is passed a reference
315+
to the element instead of the element itself. The filter predicate here uses
316+
the `&x` pattern to extract the integer. The filter closure is passed a
317+
reference because it returns `true` or `false` instead of the element,
318+
so the `filter` implementation must retain ownership to put the elements
319+
into the newly constructed iterator.)
318320

319321
You can chain all three things together: start with an iterator, adapt it
320322
a few times, and then consume the result. Check it out:

src/doc/book/ownership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ this point of time). These two parts of the vector (the one on the stack and
157157
one on the heap) must agree with each other at all times with regards to
158158
things like the length, capacity etc.
159159

160-
When we move `v` to `v2`, rust actually does a bitwise copy of the vector
160+
When we move `v` to `v2`, Rust actually does a bitwise copy of the vector
161161
object `v` into the stack allocation represented by `v2`. This shallow copy
162162
does not create a copy of the heap allocation containing the actual data.
163163
Which means that there would be two pointers to the contents of the vector

src/doc/nomicon/other-reprs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ These reprs have no effect on a struct.
5757

5858
# repr(packed)
5959

60-
`repr(packed)` forces rust to strip any padding, and only align the type to a
60+
`repr(packed)` forces Rust to strip any padding, and only align the type to a
6161
byte. This may improve the memory footprint, but will likely have other negative
6262
side-effects.
6363

src/doc/reference.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,8 @@ extern crate std as ruststd; // linking to 'std' under another name
841841

842842
A _use declaration_ creates one or more local name bindings synonymous with
843843
some other [path](#paths). Usually a `use` declaration is used to shorten the
844-
path required to refer to a module item. These declarations may appear at the
845-
top of [modules](#modules) and [blocks](grammar.html#block-expressions).
844+
path required to refer to a module item. These declarations may appear in
845+
[modules](#modules) and [blocks](grammar.html#block-expressions), usually at the top.
846846

847847
> **Note**: Unlike in many languages,
848848
> `use` declarations in Rust do *not* declare linkage dependency with external crates.
@@ -1764,7 +1764,7 @@ pub mod submodule {
17641764
# fn main() {}
17651765
```
17661766

1767-
For a rust program to pass the privacy checking pass, all paths must be valid
1767+
For a Rust program to pass the privacy checking pass, all paths must be valid
17681768
accesses given the two rules above. This includes all use statements,
17691769
expressions, types, etc.
17701770

@@ -3564,8 +3564,9 @@ Each instance of a trait object includes:
35643564
each method of `SomeTrait` that `T` implements, a pointer to `T`'s
35653565
implementation (i.e. a function pointer).
35663566

3567-
The purpose of trait objects is to permit "late binding" of methods. A call to
3568-
a method on a trait object is only resolved to a vtable entry at compile time.
3567+
The purpose of trait objects is to permit "late binding" of methods. Calling a
3568+
method on a trait object results in virtual dispatch at runtime: that is, a
3569+
function pointer is loaded from the trait object vtable and invoked indirectly.
35693570
The actual implementation for each vtable entry can vary on an object-by-object
35703571
basis.
35713572

src/libcollections/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<T> [T] {
407407
}
408408

409409
/// Returns an iterator over `size` elements of the slice at a
410-
/// time. The chunks do not overlap. If `size` does not divide the
410+
/// time. The chunks are slices and do not overlap. If `size` does not divide the
411411
/// length of the slice, then the last chunk will not have length
412412
/// `size`.
413413
///
@@ -433,7 +433,7 @@ impl<T> [T] {
433433
}
434434

435435
/// Returns an iterator over `chunk_size` elements of the slice at a time.
436-
/// The chunks are mutable and do not overlap. If `chunk_size` does
436+
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
437437
/// not divide the length of the slice, then the last chunk will not
438438
/// have length `chunk_size`.
439439
///

src/libcollections/vec.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,49 @@ use super::range::RangeArgument;
135135
/// }
136136
/// ```
137137
///
138+
/// # Indexing
139+
///
140+
/// The Vec type allows to access values by index, because it implements the
141+
/// `Index` trait. An example will be more explicit:
142+
///
143+
/// ```
144+
/// let v = vec!(0, 2, 4, 6);
145+
/// println!("{}", v[1]); // it will display '2'
146+
/// ```
147+
///
148+
/// However be careful: if you try to access an index which isn't in the Vec,
149+
/// your software will panic! You cannot do this:
150+
///
151+
/// ```ignore
152+
/// let v = vec!(0, 2, 4, 6);
153+
/// println!("{}", v[6]); // it will panic!
154+
/// ```
155+
///
156+
/// In conclusion: always check if the index you want to get really exists
157+
/// before doing it.
158+
///
159+
/// # Slicing
160+
///
161+
/// A Vec can be mutable. Slices, on the other hand, are read-only objects.
162+
/// To get a slice, use "&". Example:
163+
///
164+
/// ```
165+
/// fn read_slice(slice: &[usize]) {
166+
/// // ...
167+
/// }
168+
///
169+
/// let v = vec!(0, 1);
170+
/// read_slice(&v);
171+
///
172+
/// // ... and that's all!
173+
/// // you can also do it like this:
174+
/// let x : &[usize] = &v;
175+
/// ```
176+
///
177+
/// In Rust, it's more common to pass slices as arguments rather than vectors
178+
/// when you just want to provide a read access. The same goes for String and
179+
/// &str.
180+
///
138181
/// # Capacity and reallocation
139182
///
140183
/// The capacity of a vector is the amount of space allocated for any future

src/libgetopts/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ impl Matches {
331331
/// Returns the string argument supplied to one of several matching options or `None`.
332332
pub fn opts_str(&self, names: &[String]) -> Option<String> {
333333
for nm in names {
334-
match self.opt_val(&nm[..]) {
335-
Some(Val(ref s)) => return Some(s.clone()),
336-
_ => (),
334+
if let Some(Val(ref s)) = self.opt_val(&nm[..]) {
335+
return Some(s.clone())
337336
}
338337
}
339338
None

src/librustc_trans/back/link.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,8 @@ fn symbol_hash<'tcx>(tcx: &ty::ctxt<'tcx>,
226226
}
227227

228228
fn get_symbol_hash<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> String {
229-
match ccx.type_hashcodes().borrow().get(&t) {
230-
Some(h) => return h.to_string(),
231-
None => {}
229+
if let Some(h) = ccx.type_hashcodes().borrow().get(&t) {
230+
return h.to_string()
232231
}
233232

234233
let mut symbol_hasher = ccx.symbol_hasher().borrow_mut();
@@ -315,9 +314,8 @@ pub fn mangle<PI: Iterator<Item=InternedString>>(path: PI, hash: Option<&str>) -
315314
push(&mut n, &data);
316315
}
317316

318-
match hash {
319-
Some(s) => push(&mut n, s),
320-
None => {}
317+
if let Some(s) = hash {
318+
push(&mut n, s)
321319
}
322320

323321
n.push('E'); // End name-sequence.

src/librustc_trans/trans/base.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ impl Drop for _InsnCtxt {
150150
pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
151151
debug!("new InsnCtxt: {}", s);
152152
TASK_LOCAL_INSN_KEY.with(|slot| {
153-
match slot.borrow_mut().as_mut() {
154-
Some(ctx) => ctx.push(s),
155-
None => {}
153+
if let Some(ctx) = slot.borrow_mut().as_mut() {
154+
ctx.push(s)
156155
}
157156
});
158157
_InsnCtxt {
@@ -198,9 +197,8 @@ fn get_extern_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
198197
name: &str,
199198
did: DefId)
200199
-> ValueRef {
201-
match ccx.externs().borrow().get(name) {
202-
Some(n) => return *n,
203-
None => (),
200+
if let Some(n) = ccx.externs().borrow().get(name) {
201+
return *n;
204202
}
205203

206204
let f = declare::declare_rust_fn(ccx, name, fn_ty);
@@ -238,9 +236,8 @@ pub fn get_extern_const<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
238236
-> ValueRef {
239237
let name = ccx.sess().cstore.item_symbol(did);
240238
let ty = type_of(ccx, t);
241-
match ccx.externs().borrow_mut().get(&name) {
242-
Some(n) => return *n,
243-
None => (),
239+
if let Some(n) = ccx.externs().borrow_mut().get(&name) {
240+
return *n;
244241
}
245242
// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
246243
// FIXME(nagisa): investigate whether it can be changed into define_global
@@ -2755,9 +2752,8 @@ fn contains_null(s: &str) -> bool {
27552752
pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
27562753
debug!("get_item_val(id=`{}`)", id);
27572754

2758-
match ccx.item_vals().borrow().get(&id).cloned() {
2759-
Some(v) => return v,
2760-
None => {}
2755+
if let Some(v) = ccx.item_vals().borrow().get(&id).cloned() {
2756+
return v;
27612757
}
27622758

27632759
let item = ccx.tcx().map.get(id);

src/librustc_trans/trans/common.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,8 @@ pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef {
947947
// our boxed-and-length-annotated strings.
948948
pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
949949
unsafe {
950-
match cx.const_cstr_cache().borrow().get(&s) {
951-
Some(&llval) => return llval,
952-
None => ()
950+
if let Some(&llval) = cx.const_cstr_cache().borrow().get(&s) {
951+
return llval;
953952
}
954953

955954
let sc = llvm::LLVMConstStringInContext(cx.llcx(),

0 commit comments

Comments
 (0)