You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
static MONSTER_FACTOR: float = 57.8;
let monster_size = MONSTER_FACTOR * 10.0;
let monster_size: int = 50;
Local variables may shadow earlier declarations, as in the previous example: > monster_size was first declared as a float, and then a second monster_size
was declared as an int. If you were to actually compile this example, though,
the compiler would determine that the first monster_size is unused and issue a > warning (because this situation is likely to indicate a programmer error)
but trying to compile
fn main() {
static monster_factor: float = 10;
let monster_size = monster_factor * 10.0;
let monster_size: int = 50;
println(fmt!("Number : %d\n", monster_size));
}
gives me
noufal@sanitarium% rust run trial0.rs
trial0.rs:2:35: 2:37 error: mismatched types: expected float but found <VI0> > (expected float but found integral variable)
trial0.rs:2 static monster_factor: float = 10;
^~
error: aborting due to previous error
Based on the docs, I'd expect a warning about the unused variable rather than an error.
The text was updated successfully, but these errors were encountered:
This is caused due to mismatch between the 10 (which is an integer) and the type of monster_factor which is a float. Using 10.0 (or some other float as the tutorial actually suggests) prevents the problem.
Improve `needless_borrow` lint
fixes: rust-lang#5327fixes: rust-lang#1726fixes: rust-lang#1212
This is merging `needless_borrow` into the `dereference` pass in preparation for `explicit_auto_deref`. `explicit_auto_deref` needs to implement most of what `needless_borrow` implements in order to work.
There is a minor regression here where `let x: &str = &x.deref()` will trigger `needless_borrow` without triggering `explicit_deref_methods`. Removing the redundant borrow will cause `explicit_deref_methods` to trigger. This will be fixed when `explicit_auto_deref` is implemented.
changelog: Lint `needless_borrow` when a borrow is auto-derefed more than once
changelog: Lint `needless_borrow` in the trailing expression of a block for a match arm
The documentation says
but trying to compile
gives me
Based on the docs, I'd expect a warning about the unused variable rather than an error.
The text was updated successfully, but these errors were encountered: