discord-mods-bot icon indicating copy to clipboard operation
discord-mods-bot copied to clipboard

`?eval` command produces less than ideal error messages due to the way the code is generated

Open ilyvion opened this issue 2 years ago • 0 comments

Because it puts everything on the same line, you get the "irrelevant" surrounding code as part of your error message.

?eval `let () = 1;`
error[E0308]: mismatched types
 --> src/main.rs:1:34
  |
1 | fn main(){ println!("{:?}",{ let () = 1; 
  |                                  ^^   - this expression has type `{integer}`
  |                                  |
  |                                  expected integer, found `()`

The fn main(){ println!("{:?}",{ is irrelevant to my mistake and is just noise when you're trying to parse the error output. By putting the provided code on its own line, you could instead get an error message like

error[E0308]: mismatched types
 --> src/main.rs:2:5
  |
2 | let () = 1;
  |     ^^   - this expression has type `{integer}`
  |     |
  |     expected integer, found `()`

(I produced this second output by doing ?eval with a code block with a blank line before the code itself.)

ilyvion avatar Jan 05 '23 07:01 ilyvion