Skip to content

Commit ceeac26

Browse files
committed
auto merge of #18338 : chastell/rust/guide_pointer_fixes, r=alexcrichton
This removes some leftover line-numbering cruft from elided error examples and brings some minor clarifications. I’m not super happy about the ‘we cannot have two mutable pointers that point to the same memory’ wording (to the best of my understanding we can’t even have one mutable and one immutable), but other attempts to word this were derailing the flow a bit too much.
2 parents bb70ee5 + 9be04d5 commit ceeac26

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/doc/guide.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,7 @@ let y = &mut x;
34483448
Rust will complain:
34493449

34503450
```{ignore,notrust}
3451-
6:19 error: cannot borrow immutable local variable `x` as mutable
3451+
error: cannot borrow immutable local variable `x` as mutable
34523452
let y = &mut x;
34533453
^
34543454
```
@@ -3492,7 +3492,7 @@ note: previous borrow ends here
34923492

34933493
This is a big error message. Let's dig into it for a moment. There are three
34943494
parts: the error and two notes. The error says what we expected, we cannot have
3495-
two pointers that point to the same memory.
3495+
two mutable pointers that point to the same memory.
34963496

34973497
The two notes give some extra context. Rust's error messages often contain this
34983498
kind of extra information when the error is complex. Rust is telling us two
@@ -3763,10 +3763,10 @@ let y = &mut x;
37633763
This gives us this error:
37643764

37653765
```{notrust,ignore}
3766-
8:7 error: cannot use `*x` because it was mutably borrowed
3766+
error: cannot use `*x` because it was mutably borrowed
37673767
*x;
37683768
^~
3769-
6:19 note: borrow of `x` occurs here
3769+
note: borrow of `x` occurs here
37703770
let y = &mut x;
37713771
^
37723772
```
@@ -3791,7 +3791,7 @@ value that must persist as long as any of several referrers, read on.
37913791

37923792
## Rc and Arc
37933793

3794-
Sometimes, you need a variable that is referenced from multiple places
3794+
Sometimes you need a variable that is referenced from multiple places
37953795
(immutably!), lasting as long as any of those places, and disappearing when it
37963796
is no longer referenced. For instance, in a graph-like data structure, a node
37973797
might be referenced from all of its neighbors. In this case, it is not possible
@@ -3887,7 +3887,7 @@ match x {
38873887
```
38883888

38893889
If you're matching on an enum which has variants, you can use `..` to
3890-
ignore the value in the variant:
3890+
ignore the value and type in the variant:
38913891

38923892
```{rust}
38933893
enum OptionalInt {
@@ -4559,8 +4559,8 @@ So this would give us the numbers from `2-100`. Well, almost! If you
45594559
compile the example, you'll get a warning:
45604560

45614561
```{notrust,ignore}
4562-
2:37 warning: unused result which must be used: iterator adaptors are lazy and
4563-
do nothing unless consumed, #[warn(unused_must_use)] on by default
4562+
warning: unused result which must be used: iterator adaptors are lazy and
4563+
do nothing unless consumed, #[warn(unused_must_use)] on by default
45644564
range(1i, 100i).map(|x| x + 1i);
45654565
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45664566
```

0 commit comments

Comments
 (0)