I was doing the scrabble score exercise from Exercism and I noticed that the error the compiler was giving wasn't really the error it should be giving.
error[E0308]: mismatched types
--> src/lib.rs:6:17
|
5 | match c.make_ascii_uppercase() {
| ------------------------ this expression has type `()`
6 | 'A' => 1,
| ^^^ expected `()`, found `char`
error: aborting due to previous error
but the actual error is that c is immutable and make_ascii_uppercase() takes &mut self.
I consider that the compiler is giving me the wrong error, am I correct in assuming that?
Nope; the compiler is doing type checking before mutability checking. As you stated, char::make_ascii_uppercase takes the char by mutable reference, and does not return it. Therefore, the function returns () and that's where the compiler gets mad, and stops compiling.
Hmm, it still doesn't make 100% sense to me. How come that the immutable version returns a () instead of a char if the mutability doesn't come into play if "it hasn't been checked"?
In other words
let temp_2 = char::make_ascii_uppercase(temp);
How did the compiler determine the type of temp_2 without checking the mutability? It looks to me that mutability did come into play, since changing the mutability apparently changes the type.