rust-in-action / code

Source code for the book Rust in Action
https://www.manning.com/books/rust-in-action?a_aid=rust&a_bid=0367c58f&chan=github
1.9k stars 445 forks source link

Chapter 5 listing 5.4 ch5/ch5-bit-pattern.rs doesn't compile #94

Open bgigous opened 1 year ago

bgigous commented 1 year ago

The listing defines variables like sixtyfivethousand_533, but references non existent variables sixty5_533 and so on.

$ rustc -O ch5-bit-patterns.rs
error[E0425]: cannot find value `sixty5_533` in this scope
  --> main.rs:11:28
   |
11 |     println!("{}, {}, {}", sixty5_533, sixty5_534, sixty5_535);
   |                            ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `sixty5_534` in this scope
  --> main.rs:11:40
   |
11 |     println!("{}, {}, {}", sixty5_533, sixty5_534, sixty5_535);
   |                                        ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `sixty5_535` in this scope
  --> main.rs:11:52
   |
11 |     println!("{}, {}, {}", sixty5_533, sixty5_534, sixty5_535);
   |                                                    ^^^^^^^^^^ not found in this scope

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0425`.
ewenmcneill commented 1 year ago

@bgigous FYI, there's a fix for this issue in PR #56:

https://github.com/rust-in-action/code/pull/56/files

which was submitted over a year ago, but still hasn't been merged. (I too just ran into this same issue.)

From the "ch5" directory on my machine I've just manually applied the PR fix with:

ewen@basadi:~/misc/src/rust/rust-in-action/code/ch5$ curl -s https://patch-diff.githubusercontent.com/raw/rust-in-action/code/pull/56.patch | patch -p 2       
patching file ch5-bit-patterns.rs
ewen@basadi:~/misc/src/rust/rust-in-action/code/ch5$ git diff .
diff --git a/ch5/ch5-bit-patterns.rs b/ch5/ch5-bit-patterns.rs
index 03dab50..dae61fc 100644
--- a/ch5/ch5-bit-patterns.rs
+++ b/ch5/ch5-bit-patterns.rs
@@ -8,5 +8,5 @@ fn main() {
   let sixtyfivethousand_535: u16 = 0b1111_1111_1111_1111;

   print!("{}, {}, {}, ..., ", zero, one, two);
-  println!("{}, {}, {}", sixty5_533, sixty5_534, sixty5_535);
+  println!("{}, {}, {}", sixtyfivethousand_533, sixtyfivethousand_534, sixtyfivethousand_535);
 }
ewen@basadi:~/misc/src/rust/rust-in-action/code/ch5$ rustc ch5-bit-patterns.rs
ewen@basadi:~/misc/src/rust/rust-in-action/code/ch5$ ./ch5-bit-patterns 
0, 1, 2, ..., 65533, 65534, 65535
ewen@basadi:~/misc/src/rust/rust-in-action/code/ch5$ 

Ewen

PS: Note that the code printed in the book (at least in the PDF version from November 2022) is also wrong, so appears the code got partially changed to make it more readable, and never tested again. cc @timClicks

PPS: ETA: The same fix is also in PR #80 (https://github.com/rust-in-action/code/pull/80/files), so that's at least 4 people who have run into this same issue with the "obvious typos" in the code in the repo.