Skip to content

Commit ea6b3dd

Browse files
committed
Auto merge of rust-lang#33257 - steveklabnik:rollup, r=steveklabnik
Rollup of 7 pull requests - Successful merges: rust-lang#32991, rust-lang#33056, rust-lang#33095, rust-lang#33152, rust-lang#33212, rust-lang#33218, rust-lang#33234 - Failed merges: rust-lang#32912
2 parents 4751e45 + b9dd8aa commit ea6b3dd

File tree

9 files changed

+64
-13
lines changed

9 files changed

+64
-13
lines changed

src/doc/book/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ enter the following commands:
412412

413413
```bash
414414
$ mkdir src
415-
$ mv main.rs src/main.rs
415+
$ mv main.rs src/main.rs # or 'move main.rs src/main.rs' on Windows
416416
$ rm main # or 'del main.exe' on Windows
417417
```
418418

src/doc/book/lifetimes.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Lifetimes
22

3-
This guide is three of three presenting Rust’s ownership system. This is one of
4-
Rust’s most unique and compelling features, with which Rust developers should
3+
This is the last of three sections presenting Rust’s ownership system. This is one of
4+
Rust’s most distinct and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own chapter:
77

src/doc/book/ownership.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Ownership
22

3-
This guide is one of three presenting Rust’s ownership system. This is one of
4-
Rust’s most unique and compelling features, with which Rust developers should
3+
This is the first of three sections presenting Rust’s ownership system. This is one of
4+
Rust’s most distinct and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own
77
chapter:

src/doc/book/references-and-borrowing.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% References and Borrowing
22

3-
This guide is two of three presenting Rust’s ownership system. This is one of
4-
Rust’s most unique and compelling features, with which Rust developers should
3+
This is the second of three sections presenting Rust’s ownership system. This is one of
4+
Rust’s most distinct and compelling features, with which Rust developers should
55
become quite acquainted. Ownership is how Rust achieves its largest goal,
66
memory safety. There are a few distinct concepts, each with its own
77
chapter:
@@ -77,6 +77,32 @@ let answer = foo(&v1, &v2);
7777
// we can use v1 and v2 here!
7878
```
7979

80+
A more concrete example:
81+
82+
```rust
83+
fn main() {
84+
// Don't worry if you don't understand how `fold` works, the point here is that an immutable reference is borrowed.
85+
fn sum_vec(v: &Vec<i32>) -> i32 {
86+
return v.iter().fold(0, |a, &b| a + b);
87+
}
88+
// Borrow two vectors and and sum them.
89+
// This kind of borrowing does not allow mutation to the borrowed.
90+
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
91+
// do stuff with v1 and v2
92+
let s1 = sum_vec(v1);
93+
let s2 = sum_vec(v2);
94+
// return the answer
95+
s1 + s2
96+
}
97+
98+
let v1 = vec![1, 2, 3];
99+
let v2 = vec![4, 5, 6];
100+
101+
let answer = foo(&v1, &v2);
102+
println!("{}", answer);
103+
}
104+
```
105+
80106
Instead of taking `Vec<i32>`s as our arguments, we take a reference:
81107
`&Vec<i32>`. And instead of passing `v1` and `v2` directly, we pass `&v1` and
82108
`&v2`. We call the `&T` type a ‘reference’, and rather than owning the resource,

src/libcore/ptr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ impl<T: ?Sized> *mut T {
459459
/// ```
460460
/// let mut s = [1, 2, 3];
461461
/// let ptr: *mut u32 = s.as_mut_ptr();
462+
/// let first_value = unsafe { ptr.as_mut().unwrap() };
463+
/// *first_value = 4;
464+
/// println!("{:?}", s); // It'll print: "[4, 2, 3]".
462465
/// ```
463466
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
464467
#[inline]

src/librustc/infer/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'tcx> TyCtxt<'tcx> {
157157
"scope of call-site for function"
158158
}
159159
region::CodeExtentData::ParameterScope { .. } => {
160-
"scope of parameters for function"
160+
"scope of function body"
161161
}
162162
region::CodeExtentData::DestructionScope(_) => {
163163
new_string = format!("destruction scope surrounding {}", tag);

src/libstd/collections/hash/set.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,9 @@ impl<T, S> HashSet<T, S>
535535

536536
/// Adds a value to the set.
537537
///
538-
/// If the set did not have a value present, `true` is returned.
538+
/// If the set did not have this value present, `true` is returned.
539539
///
540-
/// If the set did have this key present, `false` is returned.
540+
/// If the set did have this value present, `false` is returned.
541541
///
542542
/// # Examples
543543
///

src/libsyntax/attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ pub enum InlineAttr {
333333
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
334334
attrs.iter().fold(InlineAttr::None, |ia,attr| {
335335
match attr.node.value.node {
336-
MetaItemKind::Word(ref n) if *n == "inline" => {
336+
MetaItemKind::Word(ref n) if n == "inline" => {
337337
mark_used(attr);
338338
InlineAttr::Hint
339339
}
340-
MetaItemKind::List(ref n, ref items) if *n == "inline" => {
340+
MetaItemKind::List(ref n, ref items) if n == "inline" => {
341341
mark_used(attr);
342342
if items.len() != 1 {
343343
diagnostic.map(|d|{ d.span_err(attr.span, "expected one argument"); });
@@ -711,7 +711,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
711711
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
712712
let mut acc = Vec::new();
713713
match attr.node.value.node {
714-
ast::MetaItemKind::List(ref s, ref items) if *s == "repr" => {
714+
ast::MetaItemKind::List(ref s, ref items) if s == "repr" => {
715715
mark_used(attr);
716716
for item in items {
717717
match item.node {

src/libsyntax/parse/token.rs

+22
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,28 @@ impl<'a> PartialEq<InternedString> for &'a str {
566566
}
567567
}
568568

569+
impl PartialEq<str> for InternedString {
570+
#[inline(always)]
571+
fn eq(&self, other: &str) -> bool {
572+
PartialEq::eq(&self.string[..], other)
573+
}
574+
#[inline(always)]
575+
fn ne(&self, other: &str) -> bool {
576+
PartialEq::ne(&self.string[..], other)
577+
}
578+
}
579+
580+
impl PartialEq<InternedString> for str {
581+
#[inline(always)]
582+
fn eq(&self, other: &InternedString) -> bool {
583+
PartialEq::eq(self, &other.string[..])
584+
}
585+
#[inline(always)]
586+
fn ne(&self, other: &InternedString) -> bool {
587+
PartialEq::ne(self, &other.string[..])
588+
}
589+
}
590+
569591
impl Decodable for InternedString {
570592
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
571593
Ok(intern(d.read_str()?.as_ref()).as_str())

0 commit comments

Comments
 (0)