reference icon indicating copy to clipboard operation
reference copied to clipboard

Raw lifetimes

Open compiler-errors opened this issue 1 year ago • 1 comments
trafficstars

See https://github.com/rust-lang/rust/pull/126452

compiler-errors avatar Sep 08 '24 03:09 compiler-errors

The

(not immediately followed by ')

bit is there in LIFETIME_OR_LABEL as a way to say that 'xxx'yyy is rejected (rather than being interpreted as two lifetimes).

But (after rust-lang/rust#126452) 'r#xxx'yyy is interpreted as two lifetimes. So I think that bit should be left out of the RAW_LIFETIME rule.

(There's no need to say anything special to indicate that 'r#kw' is rejected: that's true because ' on its own isn't a token, and character literals can't have more than one character between the quotes.)

Alternatively, it might be worth considering changing the implementation to reject 'r#xxx'yyy for consistency with the non-raw case.

Note that allowing that form would close the door to delaying the rejection of overlong character literals to post-expansion, which was being considered late last year at rust-lang/rust#118699 .

mattheww avatar Sep 09 '24 22:09 mattheww

@compiler-errors Just checking if you'll be able to look at the requested changes?

ehuss avatar Oct 22 '24 21:10 ehuss

I believe I addressed the comments, but please look closely because markdown is not my thing.

compiler-errors avatar Oct 30 '24 00:10 compiler-errors

Well, except for:

Alternatively, it might be worth considering changing the implementation to reject 'r#xxx'yyy for consistency with the non-raw case.

Which I think I will open a rustc PR to implement.

compiler-errors avatar Oct 30 '24 00:10 compiler-errors

@rustbot ready

compiler-errors avatar Oct 30 '24 03:10 compiler-errors

Do we need changes outside the Lexical structure chapter?

As far as I can see nothing is saying that r#a and 'a are treated as equivalent when used as a lifetime or label.

That is, I don't think the Reference is saying that these are now accepted:

fn foo<'r#a>(s: &'a str) {}
    'r#a: { break 'a; }

mattheww avatar Oct 30 '24 15:10 mattheww

Posted https://github.com/rust-lang/edition-guide/pull/330 as the companion for the edition.

ehuss avatar Oct 30 '24 17:10 ehuss

@rustbot author

ehuss avatar Nov 05 '24 22:11 ehuss

@compiler-errors I pushed a change for the validation, and also rebased since we made a slight change in the definition of the lifetime token in https://github.com/rust-lang/reference/pull/1668.

Please let me know if you think the current version looks good.

ehuss avatar Nov 14 '24 17:11 ehuss

I pushed a commit specifying that 'r#_ will generate an error (and similarly for r#_).

This is a bit of an awkward issue around whether or not _ is an identifier. Currently the reference does not define it that way (intentionally), even though internally rustc allows that (but quickly rejects it). IIRC, there are some issues around that and proc-macros, but I did not look into that.

I did not want to define an identifier token that allowed _, because then I would have to define separate identifier tokens that exclude it, and this _ identifier would only be used by these raw tokens.

ehuss avatar Nov 15 '24 04:11 ehuss

LGTM!

compiler-errors avatar Nov 20 '24 04:11 compiler-errors