1

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`
Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
sgldiv
  • 623
  • 6
  • 16

1 Answers1

2

In your function the type parameter bool shadows the builtin type bool. So your function declaration is essentially the same as

fn is_fail<T>() -> T { false }

which clearly isn't well-typed.

starblue
  • 55,348
  • 14
  • 97
  • 151