1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-28 11:31:32 +02:00

Allow the 'unused' category of lints (#2571)

These sort of warnings can be distracting when commenting out a few
lines of code or demonstrating some other concept. They can be
re-enabled for a code block with `warnunused`.

I filed https://github.com/rust-lang/mdBook/issues/2527 to get behavior
like this upstream.
This commit is contained in:
Dustin J. Mitchell
2025-01-20 12:47:50 -05:00
committed by GitHub
parent 9fa1b645be
commit 5f7e0c3f64
4 changed files with 16 additions and 11 deletions

View File

@ -7,7 +7,7 @@ minutes: 5
Rust provides type safety via static typing. Variable bindings are made with
`let`:
```rust,editable
```rust,editable,warnunused
fn main() {
let x: i32 = 10;
println!("x: {x}");
@ -21,6 +21,10 @@ fn main() {
- Uncomment the `x = 20` to demonstrate that variables are immutable by default.
Add the `mut` keyword to allow changes.
- Warnings are enabled for this slide, such as for unused variables or
unnecessary `mut`. These are omitted in most slides to avoid distracting
warnings. Try removing the mutation but leaving the `mut` keyword in place.
- The `i32` here is the type of the variable. This must be known at compile
time, but type inference (covered later) allows the programmer to omit it in
many cases.