Skip to content

Commit ea53e3c

Browse files
egithinjiEric Githinji
andauthored
Use dbg! instead of println! in day 3 & 4. (#2669)
Part of #2478 to clean up code blocks when all that is needed is a trivial debug print statement. Co-authored-by: Eric Githinji <[email protected]>
1 parent 241c28e commit ea53e3c

File tree

12 files changed

+25
-25
lines changed

12 files changed

+25
-25
lines changed

src/borrowing/borrowck.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
let x = 10;
1616
&x
1717
};
18-
println!("x: {x_ref}");
18+
dbg!(x_ref);
1919
}
2020
```
2121

@@ -37,8 +37,8 @@ fn main() {
3737
*c = 20;
3838
}
3939
40-
println!("a: {a}");
41-
println!("b: {b}");
40+
dbg!(a);
41+
dbg!(b);
4242
}
4343
```
4444

@@ -57,8 +57,8 @@ fn main() {
5757
conflict. Replace `c` with a direct mutation of `a` and demonstrate that
5858
this produces a similar error. This is because direct mutation of a value
5959
effectively creates a temporary mutable reference.
60-
- Move the `println!` statement for `b` before the scope that introduces `c` to
61-
make the code compile.
60+
- Move the `dbg!` statement for `b` before the scope that introduces `c` to make
61+
the code compile.
6262
- After that change, the compiler realizes that `b` is only ever used before
6363
the new mutable borrow of `a` through `c`. This is a feature of the borrow
6464
checker called "non-lexical lifetimes".

src/borrowing/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
let mut vec = vec![1, 2, 3, 4, 5];
1414
let elem = &vec[2];
1515
vec.push(6);
16-
println!("{elem}");
16+
dbg!(elem);
1717
}
1818
```
1919

src/borrowing/interior-mutability/cell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let cell = Cell::new(5);
1313
1414
cell.set(123);
15-
println!("{}", cell.get());
15+
dbg!(cell.get());
1616
}
1717
```
1818

src/error-handling/panics.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Rust will trigger a panic if a fatal error happens at runtime:
1111
```rust,editable,should_panic
1212
fn main() {
1313
let v = vec![10, 20, 30];
14-
println!("v[100]: {}", v[100]);
14+
dbg!(v[100]);
1515
}
1616
```
1717

@@ -33,12 +33,12 @@ use std::panic;
3333
3434
fn main() {
3535
let result = panic::catch_unwind(|| "No problem here!");
36-
println!("{result:?}");
36+
dbg!(result);
3737
3838
let result = panic::catch_unwind(|| {
3939
panic!("oh no!");
4040
});
41-
println!("{result:?}");
41+
dbg!(result);
4242
}
4343
```
4444

src/iterators/iterator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() {
3232
let slice = &[2, 4, 6, 8];
3333
let iter = SliceIter { slice, i: 0 };
3434
for elem in iter {
35-
println!("elem: {elem}");
35+
dbg!(elem);
3636
}
3737
}
3838
```

src/lifetimes/lifetime-annotations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() {
4040
let p1: Point = Point(10, 10);
4141
let p2: Point = Point(20, 20);
4242
let p3 = left_most(&p1, &p2); // What is the lifetime of p3?
43-
println!("p3: {p3:?}");
43+
dbg!(p3);
4444
}
4545
```
4646

src/lifetimes/struct-lifetimes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fn main() {
2424
let noun = Highlight { slice: &doc[16..19], color: HighlightColor::Yellow };
2525
let verb = Highlight { slice: &doc[20..25], color: HighlightColor::Pink };
2626
// drop(doc);
27-
println!("{noun:?}");
28-
println!("{verb:?}");
27+
dbg!(noun);
28+
dbg!(verb);
2929
}
3030
```
3131

src/memory-management/copy-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ While move semantics are the default, certain types are copied by default:
1212
fn main() {
1313
let x = 42;
1414
let y = x;
15-
println!("x: {x}"); // would not be accessible if not Copy
16-
println!("y: {y}");
15+
dbg!(x); // would not be accessible if not Copy
16+
dbg!(y);
1717
}
1818
```
1919

src/memory-management/exercise.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ impl PackageBuilder {
113113
// ANCHOR: main
114114
fn main() {
115115
let base64 = PackageBuilder::new("base64").version("0.13").build();
116-
println!("base64: {base64:?}");
116+
dbg!(&base64);
117117
let log =
118118
PackageBuilder::new("log").version("0.4").language(Language::Rust).build();
119-
println!("log: {log:?}");
119+
dbg!(&log);
120120
let serde = PackageBuilder::new("serde")
121121
.authors(vec!["djmitche".into()])
122122
.version(String::from("4.0"))
123123
.dependency(base64.as_dependency())
124124
.dependency(log.as_dependency())
125125
.build();
126-
println!("serde: {serde:?}");
126+
dbg!(serde);
127127
}
128128
// ANCHOR_END: main

src/memory-management/move.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ An assignment will transfer _ownership_ between variables:
1010
fn main() {
1111
let s1: String = String::from("Hello!");
1212
let s2: String = s1;
13-
println!("s2: {s2}");
14-
// println!("s1: {s1}");
13+
dbg!(s2);
14+
// dbg!(s1);
1515
}
1616
```
1717

0 commit comments

Comments
 (0)