Skip to content

Commit 46e6194

Browse files
committed
auto merge of #13298 : ckendell/rust/remove_managed_pointers_from_tutorial, r=cmr
Work on #13287 This is not ready for a merge yet, but I wanted to get some eyes on what I have done so far. As of right now, all references in the text to managed boxes or pointers are removed. Code associated with those specific sections of text have likewise been altered. I also removed all references to managed closures. There is a small change I would like to add to the work done in 3137cd5, on the new lines 1495 and 1496, I would like to change those values to 10 and 20. I did the same in a later change on lines 1596 and 1508. There are still bits of sample code that use managed pointers and the sigil @. Those are next on my list to remove, but I wanted to have the outstanding changes reviewed first. The uses of @ in the code samples are a bit more embedded, and I will need to be more careful changing them as to not change the purpose of the code examples. I ensured that make check still passes, although I'm not sure if that actually tests the code in tutorial.md. One issues I ran into, and tried to avoid, was that `tutorial.md` is formatted with a nice column limit. I was unsure how this was enforced, so wherever I edited a line, I did my best to keep edits on the line they previously existed on. As such, the plain text of `tutorial.md` looks a bit strange as I've left it, and I will clean that up as suggested. The rendered markdown output should not be affected.
2 parents 286b62e + be07cab commit 46e6194

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/doc/tutorial.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,20 +1408,17 @@ struct Point {
14081408
~~~~
14091409
14101410
We can use this simple definition to allocate points in many different
1411-
ways. For example, in this code, each of these three local variables
1411+
ways. For example, in this code, each of these local variables
14121412
contains a point, but allocated in a different location:
14131413
14141414
~~~
14151415
# struct Point { x: f64, y: f64 }
14161416
let on_the_stack : Point = Point { x: 3.0, y: 4.0 };
1417-
let managed_box : @Point = @Point { x: 5.0, y: 1.0 };
14181417
let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 };
14191418
~~~
14201419
14211420
Suppose we want to write a procedure that computes the distance
1422-
between any two points, no matter where they are stored. For example,
1423-
we might like to compute the distance between `on_the_stack` and
1424-
`managed_box`, or between `managed_box` and `owned_box`. One option is
1421+
between any two points, no matter where they are stored. One option is
14251422
to define a function that takes two arguments of type point—that is,
14261423
it takes the points by value. But this will cause the points to be
14271424
copied when we call the function. For points, this is probably not so
@@ -1442,11 +1439,9 @@ Now we can call `compute_distance()` in various ways:
14421439
~~~
14431440
# struct Point{ x: f64, y: f64 };
14441441
# let on_the_stack : Point = Point { x: 3.0, y: 4.0 };
1445-
# let managed_box : @Point = @Point { x: 5.0, y: 1.0 };
14461442
# let owned_box : ~Point = ~Point { x: 7.0, y: 9.0 };
14471443
# fn compute_distance(p1: &Point, p2: &Point) -> f64 { 0.0 }
1448-
compute_distance(&on_the_stack, managed_box);
1449-
compute_distance(managed_box, owned_box);
1444+
compute_distance(&on_the_stack, owned_box);
14501445
~~~
14511446
14521447
Here the `&` operator is used to take the address of the variable
@@ -1456,11 +1451,11 @@ reference. We also call this _borrowing_ the local variable
14561451
`on_the_stack`, because we are creating an alias: that is, another
14571452
route to the same data.
14581453
1459-
In the case of the boxes `managed_box` and `owned_box`, however, no
1454+
In the case of `owned_box`, however, no
14601455
explicit action is necessary. The compiler will automatically convert
1461-
a box like `@point` or `~point` to a reference like
1456+
a box `~point` to a reference like
14621457
`&point`. This is another form of borrowing; in this case, the
1463-
contents of the managed/owned box are being lent out.
1458+
contents of the owned box are being lent out.
14641459
14651460
Whenever a value is borrowed, there are some limitations on what you
14661461
can do with the original. For example, if the contents of a variable
@@ -1497,26 +1492,24 @@ Rust uses the unary star operator (`*`) to access the contents of a
14971492
box or pointer, similarly to C.
14981493
14991494
~~~
1500-
let managed = @10;
15011495
let owned = ~20;
15021496
let borrowed = &30;
15031497

1504-
let sum = *managed + *owned + *borrowed;
1498+
let sum = *owned + *borrowed;
15051499
~~~
15061500
15071501
Dereferenced mutable pointers may appear on the left hand side of
15081502
assignments. Such an assignment modifies the value that the pointer
15091503
points to.
15101504
15111505
~~~
1512-
let managed = @10;
1513-
let mut owned = ~20;
1506+
let mut owned = ~10;
15141507

1515-
let mut value = 30;
1508+
let mut value = 20;
15161509
let borrowed = &mut value;
15171510

15181511
*owned = *borrowed + 100;
1519-
*borrowed = *managed + 1000;
1512+
*borrowed = *owned + 1000;
15201513
~~~
15211514
15221515
Pointers have high operator precedence, but lower precedence than the
@@ -1781,8 +1774,8 @@ pervasively in Rust code.
17811774
17821775
Owned closures, written `proc`,
17831776
hold on to things that can safely be sent between
1784-
processes. They copy the values they close over, much like managed
1785-
closures, but they also own them: that is, no other code can access
1777+
processes. They copy the values they close over,
1778+
but they also own them: that is, no other code can access
17861779
them. Owned closures are used in concurrent code, particularly
17871780
for spawning [tasks][tasks].
17881781
@@ -1911,7 +1904,7 @@ to a reference.
19111904
# fn draw_value(self) { /* ... */ }
19121905
# }
19131906
# let s = Circle(Point { x: 1.0, y: 2.0 }, 3.0);
1914-
// As with typical function arguments, managed and owned pointers
1907+
// As with typical function arguments, owned pointers
19151908
// are automatically converted to references
19161909

19171910
(@s).draw_reference();
@@ -2094,7 +2087,7 @@ and may not be overridden:
20942087
20952088
* `Send` - Sendable types.
20962089
Types are sendable
2097-
unless they contain managed boxes, managed closures, or references.
2090+
unless they contain references.
20982091
20992092
* `Share` - Types that are *threadsafe*
21002093
These are types that are safe to be used across several threads with access to

0 commit comments

Comments
 (0)