Skip to content

Commit 663b670

Browse files
committed
Rename ShowOnDrop -> PrintOnDrop
1 parent 2d09cbf commit 663b670

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

src/destructors.md

+39-38
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ pointer, [`std::ptr::drop_in_place`] can be used.
2525
Some examples:
2626

2727
```rust
28-
struct ShowOnDrop(&'static str);
28+
struct PrintOnDrop(&'static str);
2929

30-
impl Drop for ShowOnDrop {
30+
impl Drop for PrintOnDrop {
3131
fn drop(&mut self) {
3232
println!("{}", self.0);
3333
}
3434
}
3535

36-
let mut overwritten = ShowOnDrop("drops when overwritten");
37-
overwritten = ShowOnDrop("drops when scope ends");
36+
let mut overwritten = PrintOnDrop("drops when overwritten");
37+
overwritten = PrintOnDrop("drops when scope ends");
3838

39-
let tuple = (ShowOnDrop("Tuple first"), ShowOnDrop("Tuple second"));
39+
let tuple = (PrintOnDrop("Tuple first"), PrintOnDrop("Tuple second"));
4040

4141
let moved;
4242
// No destructor run on assignment.
43-
moved = ShowOnDrop("Drops when moved");
43+
moved = PrintOnDrop("Drops when moved");
4444
// Drops now, but is then uninitialized.
4545
moved;
4646

47-
let uninitialized: ShowOnDrop;
47+
let uninitialized: PrintOnDrop;
4848
// Only the first element is dropped.
49-
let mut partially_initialized: (ShowOnDrop, ShowOnDrop);
50-
partially_initialized.0 = ShowOnDrop("Partial tuple first");
49+
let mut partially_initialized: (PrintOnDrop, PrintOnDrop);
50+
partially_initialized.0 = PrintOnDrop("Partial tuple first");
5151
```
5252

5353
## Drop scopes
@@ -97,22 +97,22 @@ dropped last when evaluating the function. Actual function parameters are
9797
dropped after any named parameters that are bound to parts of it.
9898

9999
```rust
100-
# struct ShowOnDrop(&'static str);
101-
# impl Drop for ShowOnDrop {
100+
# struct PrintOnDrop(&'static str);
101+
# impl Drop for PrintOnDrop {
102102
# fn drop(&mut self) {
103103
# println!("drop({})", self.0);
104104
# }
105105
# }
106106
// Drops the second parameter, then `y`, then the first parameter, then `x`
107107
fn patterns_in_parameters(
108-
(x, _): (ShowOnDrop, ShowOnDrop),
109-
(_, y): (ShowOnDrop, ShowOnDrop),
108+
(x, _): (PrintOnDrop, PrintOnDrop),
109+
(_, y): (PrintOnDrop, PrintOnDrop),
110110
) {}
111111

112112
// drop order is 3 2 0 1
113113
patterns_in_parameters(
114-
(ShowOnDrop("0"), ShowOnDrop("1")),
115-
(ShowOnDrop("2"), ShowOnDrop("3")),
114+
(PrintOnDrop("0"), PrintOnDrop("1")),
115+
(PrintOnDrop("2"), PrintOnDrop("3")),
116116
);
117117
```
118118

@@ -124,17 +124,17 @@ the block that contains the `let` statement. Local variables declared in a
124124
in.
125125

126126
```rust
127-
# struct ShowOnDrop(&'static str);
128-
# impl Drop for ShowOnDrop {
127+
# struct PrintOnDrop(&'static str);
128+
# impl Drop for PrintOnDrop {
129129
# fn drop(&mut self) {
130130
# println!("drop({})", self.0);
131131
# }
132132
# }
133-
let declared_first = ShowOnDrop("Dropped last in outer scope");
133+
let declared_first = PrintOnDrop("Dropped last in outer scope");
134134
{
135-
let declared_in_block = ShowOnDrop("Dropped in inner scope");
135+
let declared_in_block = PrintOnDrop("Dropped in inner scope");
136136
}
137-
let declared_last = ShowOnDrop("Dropped first in outer scope");
137+
let declared_last = PrintOnDrop("Dropped first in outer scope");
138138
```
139139

140140
If multiple patterns are used in the same arm for a `match` expression, then an unspecified
@@ -153,7 +153,8 @@ smallest scope that contains the expression and is for one of the following:
153153
* A statement.
154154
* The body of a [`if`], [`while`] or [`loop`] expression.
155155
* The `else` block of an `if` expression.
156-
* The condition expression of an `if` or `while` expression, or a `match` guard.
156+
* The condition expression of an `if` or `while` expression, or a `match`
157+
guard.
157158
* The expression for a match arm.
158159
* The second operand of a [lazy boolean expression].
159160

@@ -164,36 +165,36 @@ smallest scope that contains the expression and is for one of the following:
164165
Some examples:
165166

166167
```rust
167-
# struct ShowOnDrop(&'static str);
168-
# impl Drop for ShowOnDrop {
168+
# struct PrintOnDrop(&'static str);
169+
# impl Drop for PrintOnDrop {
169170
# fn drop(&mut self) {
170171
# println!("drop({})", self.0);
171172
# }
172173
# }
173-
let local_var = ShowOnDrop("local var");
174+
let local_var = PrintOnDrop("local var");
174175

175176
// Dropped once the condition has been evaluated
176-
if ShowOnDrop("If condition").0 == "If condition" {
177+
if PrintOnDrop("If condition").0 == "If condition" {
177178
// Dropped at the end of the block
178-
ShowOnDrop("If body").0
179+
PrintOnDrop("If body").0
179180
} else {
180181
unreachable!()
181182
};
182183

183184
// Dropped at the end of the statement
184-
(ShowOnDrop("first operand").0 == ""
185+
(PrintOnDrop("first operand").0 == ""
185186
// Dropped at the )
186-
|| ShowOnDrop("second operand").0 == "")
187+
|| PrintOnDrop("second operand").0 == "")
187188
// Dropped at the end of the expression
188-
|| ShowOnDrop("third operand").0 == "";
189+
|| PrintOnDrop("third operand").0 == "";
189190

190191
// Dropped at the end of the function, after local variables.
191192
// Changing this to a statement containing a return expression would make the
192193
// temporary be dropped before the local variables. Binding to a variable
193194
// which is then returned would also make the temporary be dropped first.
194-
match ShowOnDrop("Matched value in final expression") {
195+
match PrintOnDrop("Matched value in final expression") {
195196
// Dropped once the condition has been evaluated
196-
_ if ShowOnDrop("guard condition").0 == "" => (),
197+
_ if PrintOnDrop("guard condition").0 == "" => (),
197198
_ => (),
198199
}
199200
```
@@ -207,23 +208,23 @@ once the expression is evaluated, dropping them has no effect unless one of the
207208
operands to an expression breaks out of the expression, returns, or panics.
208209

209210
```rust
210-
# struct ShowOnDrop(&'static str);
211-
# impl Drop for ShowOnDrop {
211+
# struct PrintOnDrop(&'static str);
212+
# impl Drop for PrintOnDrop {
212213
# fn drop(&mut self) {
213214
# println!("drop({})", self.0);
214215
# }
215216
# }
216217
loop {
217218
// Tuple expression doesn't finish evaluating so operands drop in reverse order
218219
(
219-
ShowOnDrop("Outer tuple first"),
220-
ShowOnDrop("Outer tuple second"),
220+
PrintOnDrop("Outer tuple first"),
221+
PrintOnDrop("Outer tuple second"),
221222
(
222-
ShowOnDrop("Inner tuple first"),
223-
ShowOnDrop("Inner tuple second"),
223+
PrintOnDrop("Inner tuple first"),
224+
PrintOnDrop("Inner tuple second"),
224225
break,
225226
),
226-
ShowOnDrop("Never created"),
227+
PrintOnDrop("Never created"),
227228
);
228229
}
229230
```

0 commit comments

Comments
 (0)