You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unterminated char literal complains about lifetimes #101278
error: lifetimes cannot start with a number
--> src/main.rs:2:18
|
2 | let _ = ['1','2,'3'];
| ^^
error: expected `while`, `for`, `loop` or `{` after a label
--> src/main.rs:2:20
|
2 | let _ = ['1','2,'3'];
| ^ expected `while`, `for`, `loop` or `{` after a label
It should instead recognize that a char literal was intended:
error: unterminated char literal
--> src/main.rs:2:18
|
2 | let _ = ['1','2,'3'];
| ^^
help: add a closing `'`
|
2 | let _ = ['1','2','3'];
| +
Note that users might deliberately try naming lifetimes '1 or '2, too, in other cases; especially given that some error messages introduce lifetimes with such stand-in names, e.g.
[snip]
3 | fn f(x: Cell<(&i32, &i32)>) {
| - - let's call the lifetime of this reference `'1`
| |
| let's call the lifetime of this reference `'2`
4 | g(x)
| ^^^^ argument requires that `'1` must outlive `'2`
Reacted by Esteban Kuber and Chayim Refael Friedman
Activity
steffahn commentedon Sep 1, 2022
Note that users might deliberately try naming lifetimes
'1or'2, too, in other cases; especially given that some error messages introduce lifetimes with such stand-in names, e.g.estebank commentedon Sep 1, 2022
Yes, the error recovery should be constricted to places where a char literal would be completely valid.
compiler-errors commentedon Sep 1, 2022
I think we can do this with a stashed diagnostic.
estebank commentedon Sep 1, 2022
I think a limited lookahead (and maybe some passed down info) that checks whether a literal is acceptable there.
ChayimFriedman2 commentedon Sep 1, 2022
Are they even accepted in the same positions? Lifetimes are only in generic parameter lists and chars are only in expressions, no?
Edit: Oh, but labels.
compiler-errors commentedon Sep 1, 2022
Lifetimes can also be labels that start blocks
ChayimFriedman2 commentedon Sep 1, 2022
So "if not followed by colon" can be a pretty good estimation. We can also restrict even more to "colon then brace or
looporwhileorfor".Rollup merge of rust-lang#101293 - compiler-errors:lt-is-actually-cha…