Skip to content

Commit

Permalink
Remove slide on shadowing (#2596)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison authored Feb 6, 2025
1 parent 72c7618 commit f1459c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
1 change: 0 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
- [Solution](types-and-values/solution.md)
- [Control Flow Basics](control-flow-basics.md)
- [Blocks and Scopes](control-flow-basics/blocks-and-scopes.md)
- [Scopes and Shadowing](control-flow-basics/blocks-and-scopes/scopes.md)
- [`if` Expressions](control-flow-basics/if.md)
- [`match` Expressions](control-flow-basics/match.md)
- [Loops](control-flow-basics/loops.md)
Expand Down
10 changes: 8 additions & 2 deletions src/control-flow-basics/blocks-and-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ minutes: 5

# Blocks and Scopes

## Blocks

A block in Rust contains a sequence of expressions, enclosed by braces `{}`.
Each block has a value and a type, which are those of the last expression of the
block:
Expand All @@ -19,14 +17,22 @@ fn main() {
z - y
};
println!("x: {x}");
// println!("y: {y}");
}
```

If the last expression ends with `;`, then the resulting value and type is `()`.

A variable's scope is limited to the enclosing block.

<details>

- You can show how the value of the block changes by changing the last line in
the block. For instance, adding/removing a semicolon or using a `return`.

- Demonstrate that attempting to access `y` outside of its scope won't compile.

- Values are effectively "deallocated" when they go out of their scope, even if
their data on the stack is still there.

</details>
35 changes: 0 additions & 35 deletions src/control-flow-basics/blocks-and-scopes/scopes.md

This file was deleted.

0 comments on commit f1459c5

Please sign in to comment.