Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bgigous opened this issue Dec 28, 2022 · 1 comment
Open

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

bgigous opened this issue Dec 28, 2022 · 1 comment

Comments

@bgigous
Copy link

bgigous commented Dec 28, 2022

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
Copy link

ewenmcneill commented Jan 6, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants