Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f4f0e22

Browse files
committedJan 19, 2025·
Allow the 'unused' category of lints
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`.
1 parent 68e1ebd commit f4f0e22

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed
 

‎src/generics/trait-bounds.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn duplicate<T: Clone>(a: T) -> (T, T) {
1414
(a.clone(), a.clone())
1515
}
1616
17-
// struct NotCloneable;
17+
struct NotCloneable;
1818
1919
fn main() {
2020
let foo = String::from("foo");

‎src/testing/lints.md

+5-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ The Rust compiler produces fantastic error messages, as well as helpful built-in
88
lints. [Clippy](https://doc.rust-lang.org/clippy/) provides even more lints,
99
organized into groups that can be enabled per-project.
1010

11-
```rust,editable,should_panic
11+
```rust,editable,should_panic,warnunused
1212
#[deny(clippy::cast_possible_truncation)]
1313
fn main() {
14-
let x = 3;
14+
let mut x = 3;
1515
while (x < 70000) {
1616
x *= 2;
1717
}
@@ -21,13 +21,9 @@ fn main() {
2121

2222
<details>
2323

24-
Run the code sample and examine the error message. There are also lints visible
25-
here, but those will not be shown once the code compiles. Switch to the
26-
Playground site to show those lints.
27-
28-
After resolving the lints, run `clippy` on the playground site to show clippy
29-
warnings. Clippy has extensive documentation of its lints, and adds new lints
30-
(including default-deny lints) all the time.
24+
There are compiler lints visible here, but not clippy lints. Run `clippy` on the
25+
playground site to show clippy warnings. Clippy has extensive documentation of
26+
its lints, and adds new lints (including default-deny lints) all the time.
3127

3228
Note that errors or warnings with `help: ...` can be fixed with `cargo fix` or
3329
via your editor.

‎src/types-and-values/variables.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ minutes: 5
77
Rust provides type safety via static typing. Variable bindings are made with
88
`let`:
99

10-
```rust,editable
10+
```rust,editable,warnunused
1111
fn main() {
1212
let x: i32 = 10;
1313
println!("x: {x}");
@@ -21,6 +21,10 @@ fn main() {
2121
- Uncomment the `x = 20` to demonstrate that variables are immutable by default.
2222
Add the `mut` keyword to allow changes.
2323

24+
- Warnings are enabled for this slide, such as for unused variables or
25+
unnecessary `mut`. These are omitted in most slides to avoid distracting
26+
warnings. Try removing the mutation but leaving the `mut` keyword in place.
27+
2428
- The `i32` here is the type of the variable. This must be known at compile
2529
time, but type inference (covered later) allows the programmer to omit it in
2630
many cases.

‎theme/book.js

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ function playground_text(playground, hidden = true) {
127127

128128
let text = playground_text(code_block);
129129
let classes = code_block.querySelector('code').classList;
130+
// Unless the code block has `warnunused`, allow all "unused" lints to avoid cluttering
131+
// the output.
132+
if(!classes.contains("warnunused")) {
133+
text = '#![allow(unused)]\n' + text;
134+
}
130135
let edition = "2015";
131136
if(classes.contains("edition2018")) {
132137
edition = "2018";

0 commit comments

Comments
 (0)