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

Fixed compilation on Getting Started page #63

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

YohDeadfall
Copy link
Contributor

No description provided.

@dhardy
Copy link
Member

dhardy commented Sep 26, 2024

Is this enough to actually fix it? According to (a skim of) rust-lang/mdBook#394 we do need the extern crate line, but also -L.

The example works when copy+pasted to the playground (which has the top 1000 crates installed).

@YohDeadfall
Copy link
Contributor Author

I took that line from another place where an example worked in the book, but here it isn't and fails with that:

   Compiling playground v0.0.1 (/playground)
error[E0433]: failed to resolve: maybe a missing crate `rand`?
 --> src/main.rs:1:5
  |
1 | use rand::prelude::*;
  |     ^^^^ maybe a missing crate `rand`?
  |
  = help: consider adding `extern crate rand` to use the `rand` crate

error[E0599]: no method named `gen_range` found for struct `ThreadRng` in the current scope
   --> src/main.rs:6:41
    |
6   |     println!("Random die roll: {}", rng.gen_range(1..=6));
    |                                         ^^^^^^^^^
    |
   ::: /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rng.rs:129:8
    |
129 |     fn gen_range<T, R>(&mut self, range: R) -> T
    |        --------- the method is available for `ThreadRng` here
    |
    = help: items from traits can only be used if the trait is in scope
help: there is a method `gen_ratio` with a similar name, but with different arguments
   --> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rng.rs:299:5
    |
299 |     fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: trait `Rng` which provides `gen_range` is implemented but not in scope; perhaps you want to import it
    |
1   + use rand::Rng;
    |

error[E0599]: no method named `gen` found for struct `ThreadRng` in the current scope
  --> src/main.rs:7:41
   |
7  |     println!("Random UUID: 0x{:X}", rng.gen::<u128>());
   |                                         ^^^ method not found in `ThreadRng`
   |
  ::: /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rng.rs:93:8
   |
93 |     fn gen<T>(&mut self) -> T
   |        --- the method is available for `ThreadRng` here
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `Rng` which provides `gen` is implemented but not in scope; perhaps you want to import it
   |
1  + use rand::Rng;
   |

error[E0599]: no method named `gen` found for struct `ThreadRng` in the current scope
  --> src/main.rs:9:12
   |
9  |     if rng.gen() {
   |            ^^^ method not found in `ThreadRng`
   |
  ::: /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand-0.8.5/src/rng.rs:93:8
   |
93 |     fn gen<T>(&mut self) -> T
   |        --- the method is available for `ThreadRng` here
   |
   = help: items from traits can only be used if the trait is in scope
help: trait `Rng` which provides `gen` is implemented but not in scope; perhaps you want to import it
   |
1  + use rand::Rng;
   |

Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `playground` (bin "playground") due to 4 previous errors

After adding that # extern crate line it compiles fine:

Random die roll: 4
Random UUID: 0x3CBB0F3727EDEFF3F39D5F1A0B545E20

@dhardy dhardy merged commit 69a9997 into rust-random:master Sep 26, 2024
1 check passed
@YohDeadfall YohDeadfall deleted the fix-code-compilation branch September 26, 2024 10:59
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

Successfully merging this pull request may close these issues.

2 participants