Change:
<ins> error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:11:5 | LL | fn test_if() -> i32 { |                 --- expected `i32` because of return type ... LL |     x |     ^ expected `i32`, found `()` | help: remove this semicolon to return this value | LL -         3; LL +         3 | help: remove this semicolon to return this value | LL -         4; LL +         4 | error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:15:13 | LL |       if true { |  _____________^ LL | |         eprintln!("hello"); LL | |         3; | |          - help: remove this semicolon to return this value LL | |     } | |_____^ expected `i32`, found `()` error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:19:10 | LL |       else { |  __________^ LL | |         4; | |          - help: remove this semicolon to return this value LL | |     } | |_____^ expected `i32`, found `()` error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:30:5 | LL | fn test_match() -> i32 { |                    --- expected `i32` because of return type ... LL |     res |     ^^^ expected `i32`, found `()` | help: remove this semicolon to return this value | LL -         1 => { 1; } LL +         1 => { 1 } | help: remove this semicolon to return this value | LL -         _ => { 2; } LL +         _ => { 2 } | error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:36:14 | LL |         1 => { 1; } |              ^^^-^^ |              |  | |              |  help: remove this semicolon to return this value |              expected `i32`, found `()` error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:37:14 | LL |         _ => { 2; } |              ^^^-^^ |              |  | |              |  help: remove this semicolon to return this value |              expected `i32`, found `()` error[E0308]: `match` arms have incompatible types --> $DIR/stmts-as-exp-105431.rs:45:16 | LL |       let res = match v { |  _______________- LL | |         1 => { if 1 < 2 { 1 } else { 2 } } | |                ------------------------- this is found to be of type `{integer}` LL | |         _ => { 2; } | |                ^- | |                || | |                |help: consider removing this semicolon | |                expected integer, found `()` LL | |     }; | |_____- `match` arms have incompatible types error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:59:5 | LL | fn test_if_match_mixed() -> i32 { |                             --- expected `i32` because of return type ... LL |     x |     ^ expected `i32`, found `()` | help: remove this semicolon to return this value | LL -         3; LL +         3 | help: remove this semicolon to return this value | LL -         }; LL +         } | error[E0308]: mismatched types --> $DIR/stmts-as-exp-105431.rs:72:5 | LL | fn test_if_match_mixed_failed() -> i32 { |                                    --- expected `i32` because of return type LL |     let x = if true { LL |         3; |          - help: remove this semicolon to return this value ... LL |     x |     ^ expected `i32`, found `()` error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0308`. </ins>

Discussion:
The code below has superfluous semicolons in the branches of the if expression: The error message that results is: This can be confusing to beginners, who may not understand unit type. However, since the expressions and can be shown to have no side effects, the code (as is) can't be what the user intended. Could the compiler produce a more targeted error message that mentions the superfluous semicolon? <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
label T-compiler A-diagnostics D-newcomer-roadblock D-terse
claim
Thinking more about this, I don't think we should extend the "remove semicolon to make tail expression" suggestion to cover this case, since we don't know the expected type of at the point at which the suggestion would be made. For example, we don't make the suggestion to change to here: But that's just a guess based on my limited knowledge of type mismatch suggestions. Maybe someone else could weigh in?