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

Typo in Tuple Structs #72

Closed
ghost opened this issue Dec 27, 2022 · 2 comments
Closed

Typo in Tuple Structs #72

ghost opened this issue Dec 27, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Dec 27, 2022

https://google.github.io/comprehensive-rust/structs/tuple-structs.html

struct PoundOfForce(f64);
struct Newtons(f64);

fn compute_thruster_force() -> PoundOfForce {
    todo!("Ask a rocket scientist at NASA")
}

fn set_thruster_force(force: Newtons) {
    // ...
}

fn main() {
    let force = compute_thruster_force();
    set_thruster_force(force);
}

compile with cargo run shows:

❯ cargo run
   Compiling exercise v0.1.0 (/Users/z/code/exercise)
error[E0308]: mismatched types
  --> src/main.rs:14:24
   |
14 |     set_thruster_force(force);
   |     ------------------ ^^^^^ expected struct `Newtons`, found struct `PoundOfForce`
   |     |
   |     arguments to this function are incorrect
   |
note: function defined here
  --> src/main.rs:8:4
   |
8  | fn set_thruster_force(force: Newtons) {
   |    ^^^^^^^^^^^^^^^^^^ --------------

For more information about this error, try `rustc --explain E0308`.
error: could not compile `exercise` due to previous error

So this maybe a typo in the code?

@mgeisler
Copy link
Collaborator

Hey @livrth,

Thanks for opening the issue! The compilation error is actually intentional: it shows you that Rust found the error in the use of units at compilation time — in the real world, the mistake was found when the Mars Climate Orbiter crashed into Mars.

I'm working on adding support for speaker notes #53 and then I'll fill in such details on all the pages.

@mgeisler mgeisler closed this as not planned Won't fix, can't repro, duplicate, stale Dec 27, 2022
@ghost
Copy link
Author

ghost commented Dec 28, 2022

Oh I see, thank you very much!

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

1 participant