Identifier starting with decimal digit

Why is r#3D_CONSTANT not allowed?

fn main() {
    let r#0 = 10;
}

Error:

error: found invalid character; only `#` is allowed in raw string delimitation: 0

The only affect r# has is to stop an identifier being parsed as a keyword (except some special keywords it appears, I didn't realise it had some limitations), it doesn't change the allowed syntax. Identifier syntax doesn't allow a digit in the first position.

There was some discussion in the RFC of an even more lenient syntax that would drop all restrictions and allow using even things like spaces in an identifier. IIRC the reason this wasn't done is that it's not necessary for the main motivation, which is allowing editions to reserve new keywords and still have code interoperate between editions.

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.