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

Error during compiling alien cake: can't compare std::ops::Range<{float}> with std::ops::Range<{float}> #13371

Closed
daresan opened this issue May 14, 2024 · 4 comments
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled

Comments

@daresan
Copy link

daresan commented May 14, 2024

Bevy version

v0.13.2

[Optional] Relevant system information

Windows 10 Home 64-bit

What you did

I copied the code from the alien cake example to the main.rs file of my project and tried cargo run. First I was missing the rand module in the dependencies (which is not described in the example or manual btw), but then also these errors show up during compiling, instead of starting the game:

Compiling bevy v0.13.2
Compiling alien_cake v0.1.0 (C:\Users\Daniel\Documents\Visual Studio 2022\Projects\alien_cake)
error[E0277]: can't compare std::ops::Range<{float}> with std::ops::Range<{float}>
--> src\main.rs:132:53
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1);
| ^^^^^^^^^ no implementation for std::ops::Range<{float}> < std::ops::Range<{float}> and std::ops::Range<{float}> > std::ops::Range<{float}>
|
= help: the trait PartialOrd is not implemented for std::ops::Range<{float}>
note: required by a bound in gen_range
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:21
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^^ required by this bound in Rng::gen_range

error[E0277]: the trait bound std::ops::Range<{float}>: SampleRange is not satisfied
--> src\main.rs:132:53
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1);
| ^^^^^^^^^ the trait SampleRange is not implemented for std::ops::Range<{float}>
|
= help: the following other types implement trait SampleRange:
isize
i8
i16
i32
i64
usize
u8
u16
and 4 others
note: required by a bound in gen_range
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:34
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^^^ required by this bound in Rng::gen_range

error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> src\main.rs:132:53
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1);
| ^^^^^^^^^----------- an argument of type std::ops::Range<{float}> is missing
|
note: method defined here
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:8
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^
help: provide the argument
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1, /* high */);
| ~~~~~~~~~~~~~~~~~~~~~~~

error[E0369]: cannot subtract {float} from std::ops::Range<{float}>
--> src\main.rs:134:73
|
134 | transform: Transform::from_xyz(i as f32, height - 0.2, j as f32),
| ------ ^ --- {float}
| |
| std::ops::Range<{float}>

error[E0308]: mismatched types
--> src\main.rs:138:28
|
138 | Cell { height }
| ^^^^^^ expected f32, found Range<{float}>
|
= note: expected type f32
found struct std::ops::Range<{float}>

error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> src\main.rs:326:43
|
326 | game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
| ^^^^^^^^^----------------- an argument of type usize is missing
|
note: expected usize, found Range<usize>
--> src\main.rs:326:53
|
326 | game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
| ^^^^^^^^^^^^^^^
= note: expected type usize
found struct std::ops::Range<usize>
help: the return type of this call is std::ops::Range<usize> due to the type of the argument passed
--> src\main.rs:326:24
|
326 | game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| this argument influences the return type of gen_range
note: method defined here
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:8
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^
help: provide the argument
|
326 | game.bonus.i = rand::thread_rng().gen_range(/* usize /, / usize */);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> src\main.rs:327:43
|
327 | game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
| ^^^^^^^^^----------------- an argument of type usize is missing
|
note: expected usize, found Range<usize>
--> src\main.rs:327:53
|
327 | game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
| ^^^^^^^^^^^^^^^
= note: expected type usize
found struct std::ops::Range<usize>
help: the return type of this call is std::ops::Range<usize> due to the type of the argument passed
--> src\main.rs:327:24
|
327 | game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| this argument influences the return type of gen_range
note: method defined here
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:8
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^
help: provide the argument
|
327 | game.bonus.j = rand::thread_rng().gen_range(/* usize /, / usize */);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~

Some errors have detailed explanations: E0061, E0277, E0308, E0369.
For more information about an error, try rustc --explain E0061.
error: could not compile alien_cake (bin "alien_cake") due to 7 previous errors

c:\Users\Daniel\Documents\Visual Studio 2022\Projects\alien_cake>cargo run
Compiling alien_cake v0.1.0 (C:\Users\Daniel\Documents\Visual Studio 2022\Projects\alien_cake)
error[E0277]: can't compare std::ops::Range<{float}> with std::ops::Range<{float}>
--> src\main.rs:132:53
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1);
| ^^^^^^^^^ no implementation for std::ops::Range<{float}> < std::ops::Range<{float}> and std::ops::Range<{float}> > std::ops::Range<{float}>
|
= help: the trait PartialOrd is not implemented for std::ops::Range<{float}>
note: required by a bound in gen_range
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:21
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^^ required by this bound in Rng::gen_range

error[E0277]: the trait bound std::ops::Range<{float}>: SampleRange is not satisfied
--> src\main.rs:132:53
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1);
| ^^^^^^^^^ the trait SampleRange is not implemented for std::ops::Range<{float}>
|
= help: the following other types implement trait SampleRange:
isize
i8
i16
i32
i64
usize
u8
u16
and 4 others
note: required by a bound in gen_range
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:34
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^^^ required by this bound in Rng::gen_range

error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> src\main.rs:132:53
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1);
| ^^^^^^^^^----------- an argument of type std::ops::Range<{float}> is missing
|
note: method defined here
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:8
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^
help: provide the argument
|
132 | let height = rand::thread_rng().gen_range(-0.1..0.1, /* high */);
| ~~~~~~~~~~~~~~~~~~~~~~~

error[E0369]: cannot subtract {float} from std::ops::Range<{float}>
--> src\main.rs:134:73
|
134 | transform: Transform::from_xyz(i as f32, height - 0.2, j as f32),
| ------ ^ --- {float}
| |
| std::ops::Range<{float}>

error[E0308]: mismatched types
--> src\main.rs:138:28
|
138 | Cell { height }
| ^^^^^^ expected f32, found Range<{float}>
|
= note: expected type f32
found struct std::ops::Range<{float}>

error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> src\main.rs:326:43
|
326 | game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
| ^^^^^^^^^----------------- an argument of type usize is missing
|
note: expected usize, found Range<usize>
--> src\main.rs:326:53
|
326 | game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
| ^^^^^^^^^^^^^^^
= note: expected type usize
found struct std::ops::Range<usize>
help: the return type of this call is std::ops::Range<usize> due to the type of the argument passed
--> src\main.rs:326:24
|
326 | game.bonus.i = rand::thread_rng().gen_range(0..BOARD_SIZE_I);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| this argument influences the return type of gen_range
note: method defined here
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:8
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^
help: provide the argument
|
326 | game.bonus.i = rand::thread_rng().gen_range(/* usize /, / usize */);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~

error[E0061]: this method takes 2 arguments but 1 argument was supplied
--> src\main.rs:327:43
|
327 | game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
| ^^^^^^^^^----------------- an argument of type usize is missing
|
note: expected usize, found Range<usize>
--> src\main.rs:327:53
|
327 | game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
| ^^^^^^^^^^^^^^^
= note: expected type usize
found struct std::ops::Range<usize>
help: the return type of this call is std::ops::Range<usize> due to the type of the argument passed
--> src\main.rs:327:24
|
327 | game.bonus.j = rand::thread_rng().gen_range(0..BOARD_SIZE_J);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------^
| |
| this argument influences the return type of gen_range
note: method defined here
--> C:\Users\Daniel.cargo\registry\src\index.crates.io-6f17d22bba15001f\rand-0.4.6\src\lib.rs:524:8
|
524 | fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T where Self: Sized {
| ^^^^^^^^^
help: provide the argument
|
327 | game.bonus.j = rand::thread_rng().gen_range(/* usize /, / usize */);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~

Some errors have detailed explanations: E0061, E0277, E0308, E0369.
For more information about an error, try rustc --explain E0061.
error: could not compile alien_cake (bin "alien_cake") due to 7 previous errors

@daresan daresan added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 14, 2024
@SkiFire13
Copy link
Contributor

You're using the 0.4 version of the rand crate, which had a different API than the latest one (0.8), most notably gen_range took two separate arguments min and max. I suggest you to depend on rand = "0.8" or change the call to gen_range to .gen_range(-0.1, 0.1)

That said, how is this an issue with Bevy (or even just related to Bevy)?

@daresan
Copy link
Author

daresan commented May 15, 2024

I am not using rand, this example from bevy is using rand and there is no description anywhere of which version to use or whatever. So for me and any other bevy newbie this is absolutely a bevy issue and nothing else. Please put more effort in the documentation!

@GitGhillie
Copy link
Contributor

As mentioned in the readme you should clone this repo to run the examples.
If you want to copy the code into your own project, including the rand dependency, you can look at the [dev-dependencies] in the Cargo.toml of this repo. There you will find which version of rand the Bevy example uses.

Let me know if that clears things up. IMO these are basic Rust/Cargo things, so adding documentation about this would only add noise.

@mnmaita
Copy link
Member

mnmaita commented May 21, 2024

Closing this one as it's not a bug within Bevy. Feel free to reopen if there's more to it.

@mnmaita mnmaita closed this as completed May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled
Projects
None yet
Development

No branches or pull requests

4 participants