Error message for vec!['1','2,'3']

I meant to type

  let mut a = ['1','2','3'];

but I left off the ' after the 2 and got an error message about lifetimes. It makes sense, but in context, it might be useful to warn about a missing quote.

1 Like

Probably worth filing a diagnostics bug against rust-lang/rust!

1 Like

For context for other readers, the error message is

error: lifetimes cannot start with a number
 --> src/main.rs:2:22
  |
2 |     let mut a = ['1','2,'3'];
  |                      ^^

error: expected `while`, `for`, `loop` or `{` after a label
 --> src/main.rs:2:24
  |
2 |     let mut a = ['1','2,'3'];
  |                        ^ expected `while`, `for`, `loop` or `{` after a label

which is not necessarily the most typical thing that I would call an "error about lifetimes" but rather an "error about lifetimes syntax", but adding some help mentioning character literals seems useful nonetheless, for both of the error messages above (in particular the second one since that second error is only error you get in case the char isn't a number but a letter, i. e. a syntactically valid lifetime or label).

6 Likes