This question already has an answer here:
I was trying to get a piece of Rust generic code to compile, and after mucking around for while narrowed it down to failure of this code to compile. I am not sure what exactly is breaking down here (E0308 doesn't help me much) -- I must be missing something silly:
fn is_fail<bool>() -> bool { false }
fn main(){
let failure:bool = is_fail();
//if ! failure {
println!("{}", failure);
//}
}
The error is:
error: mismatched types [--explain E0308]
--> <anon>:1:30
1 |> fn is_fail<bool>() -> bool { false }
|> ^^^^^ expected type parameter, found bool
note: expected type `bool`
note: found type `bool`
In your function the type parameter
bool
shadows the builtin typebool
. So your function declaration is essentially the same aswhich clearly isn't well-typed.