rust-lang / reference

The Rust Reference
https://doc.rust-lang.org/nightly/reference/
Apache License 2.0
1.25k stars 490 forks source link

Raw lifetimes #1603

Closed compiler-errors closed 2 days ago

compiler-errors commented 2 months ago

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

mattheww commented 2 months ago

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 .

ehuss commented 1 month ago

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

compiler-errors commented 3 weeks ago

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

compiler-errors commented 3 weeks ago

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 commented 3 weeks ago

@rustbot ready

mattheww commented 3 weeks ago

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; }
ehuss commented 3 weeks ago

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

ehuss commented 2 weeks ago

@rustbot author

ehuss commented 1 week ago

@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 commented 1 week ago

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.

compiler-errors commented 2 days ago

LGTM!