Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update destructors.md #1471

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ dropped last when evaluating the function. Each actual function parameter is
dropped after any bindings introduced in that parameter's pattern.

```rust
// entire function scope begins
Copy link

@jdahlstrom jdahlstrom Apr 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First letter should be capitalized unless it's an identifier, for correctness and consistency with other Rust documentation (including this file). Ditto for all the other comments.

fn fun(a:i8) -> i8
{ // function body block begins
let b:i8 = 0;
return b;
} // function body block ends. `b` is dropped here.
// entire function scope ends. `a` is dropped here.

// entire function begins.
fn fun1(a:i8) // `a` associated to entire function.
{ // function body block begins.
match &fun(2) { // match expression begins. temporary associated to match expression.
v => {}
} // match expression ends. temporary is dropped here.
{ // inner block begins.
let b:i8 = fun(3); // `b` associated to inner block.
} // inner block ends. `b` is dropped here.
}
// entire function ends. `a` is dropped here.

# struct PrintOnDrop(&'static str);
# impl Drop for PrintOnDrop {
# fn drop(&mut self) {
Expand Down Expand Up @@ -131,6 +151,13 @@ the block that contains the `let` statement. Local variables declared in a
are declared in.

```rust
{ // outer scope begins.
let a:i8; // `a` is associated to the outer scope.
{ // inner scope begins.
let b:i8; // `b` associated to the inner scope.
} // inner scope ends. `b` is dropped here.
} // outer scope ends. `a` is dropped here.

# struct PrintOnDrop(&'static str);
# impl Drop for PrintOnDrop {
# fn drop(&mut self) {
Expand Down