Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement raw lifetimes and labels ('r#ident) #126452

Merged
merged 6 commits into from
Sep 8, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jun 14, 2024

This PR does two things:

  1. Reserve lifetime prefixes, e.g. 'prefix#lt in edition 2021.
  2. Implements raw lifetimes, e.g. 'r#async in edition 2021.

This PR additionally extends the keyword_idents_2024 lint to also check lifetimes.

cc @traviscross
r? parser

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 14, 2024
@compiler-errors
Copy link
Member Author

compiler-errors commented Jun 14, 2024

The only theoretical breakage is this:

macro_rules! lt {
    ($lt:lifetime # $id:ident) => {}
}

lt!('r#a);

edit: whoops, @fmease also notes that it breaks:

#[cfg(any())] fn f<'async>(_: &'async ()) {}

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

Also, this doesn't reserve all prefixed lifetimes -- it just implements 'r#. Not sure if T-lang wants all prefixes to be reserved as well.

@compiler-errors compiler-errors added the I-lang-nominated Nominated for discussion during a lang team meeting. label Jun 14, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2024

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@compiler-errors
Copy link
Member Author

r-a and rustfmt changes are required due to changes to lexer and parser, respectively.

@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Jun 14, 2024

⌛ Trying commit 0129478 with merge d9cbfeb...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 14, 2024
Implement raw lifetimes and labels (`'r#ident`)

This PR implements a syntax for raw lifetimes and labels as requested in rust-lang#126335.

This PR also moves keyword lifetime validation (i.e. checking that we don't have something like `'async`) from ast validation to the parser, similar to how we handle raw identifiers, since we don't distinguish raw identifiers after parsing.

This PR additionally extends the `keyword_idents_2024` lint to also check identifiers.

cc `@traviscross`
r? parser
@bors
Copy link
Contributor

bors commented Jun 14, 2024

☀️ Try build successful - checks-actions
Build commit: d9cbfeb (d9cbfeb054d7bd02cf942e6d32c1c0a91f042ce9)

@compiler-errors
Copy link
Member Author

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-126452 created and queued.
🤖 Automatically detected try build d9cbfeb
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 14, 2024
@craterbot
Copy link
Collaborator

🚧 Experiment pr-126452 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-126452 is completed!
📊 11 regressed and 2 fixed (472186 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jun 16, 2024
@compiler-errors
Copy link
Member Author

There's a crate that specifically abuses 'ref which is a keyword lifetime. Might have to find a workaround for this.

@danielhenrymantilla
Copy link
Contributor

FWIW, as documented over https://docs.rs/with_locals/0.3.2/with_locals/index.html#remarks, the 'ref lifetime choice is just a default one. Users can always provide their own lifetime marker instead. This means that it is possible for users to adjust their code to the change of this PR if needs be.

  • (if we could afford the wait, I could even patch the crate to start warning about the direct 'ref usage (DIY FCW, sort of))

@traviscross
Copy link
Contributor

@rustbot labels -I-lang-nominated

We discussed this in the lang triage call today.

We confirmed that we mean for all prefixed lifetimes to be reserved, not just 'r# ones. We view both the missing reservation and the missing support for 'r# as bug fixes consistent with the intent of RFC 3101. The result of this reservation is that these prefixed lifetimes will be parsed as single tokens rather than as many.

Secondly, we confirmed that we're OK with moving the validation of keywords in lifetimes to pre-expansion from post-expansion. We similarly consider this a bug fix. While the breakage of the convenience feature of the with_locals crate that relies on this is unfortunate, and we wish we had not overlooked this earlier for that reason, we're fortunate that the breakage is contained to only one crate, and we're going to accept this breakage as the extra complexity we'd need to carry in the compiler to work around this isn't deemed worth it.

Thanks in particular to @danielhenrymantilla for being responsive on this and understanding of the situation.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Jun 19, 2024
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 5, 2024
@compiler-errors

This comment was marked as outdated.

@compiler-errors compiler-errors force-pushed the raw-lifetimes branch 2 times, most recently from 6a25348 to 8567b59 Compare September 5, 2024 11:17
Copy link
Member

@spastorino spastorino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a very tiny and minor nit, that I'm fine with addressing or leaving it as is :).

r=me once you decide what to do with that.

compiler/rustc_ast/src/mut_visit.rs Outdated Show resolved Hide resolved
@compiler-errors
Copy link
Member Author

@bors r=spastorino

@bors
Copy link
Contributor

bors commented Sep 6, 2024

📌 Commit b6a86be has been approved by spastorino

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 7, 2024
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#126452 (Implement raw lifetimes and labels (`'r#ident`))
 - rust-lang#129555 (stabilize const_float_bits_conv)
 - rust-lang#129594 (explain the options bootstrap passes to curl)
 - rust-lang#129677 (Don't build by-move body when async closure is tainted)
 - rust-lang#129847 (Do not call query to compute coroutine layout for synthetic body of async closure)
 - rust-lang#129869 (add a few more crashtests)
 - rust-lang#130009 (rustdoc-search: allow trailing `Foo ->` arg search)
 - rust-lang#130046 (str: make as_mut_ptr and as_bytes_mut unstably const)
 - rust-lang#130047 (Win: Add dbghelp to the list of import libraries)
 - rust-lang#130059 (Remove the unused  `llvm-skip-rebuild` option from x.py)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ccf3f6e into rust-lang:master Sep 8, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2024
Rollup merge of rust-lang#126452 - compiler-errors:raw-lifetimes, r=spastorino

Implement raw lifetimes and labels (`'r#ident`)

This PR does two things:
1. Reserve lifetime prefixes, e.g. `'prefix#lt` in edition 2021.
2. Implements raw lifetimes, e.g. `'r#async` in edition 2021.

This PR additionally extends the `keyword_idents_2024` lint to also check lifetimes.

cc `@traviscross`
r? parser
@compiler-errors compiler-errors added the relnotes Marks issues that should be documented in the release notes of the next release. label Sep 8, 2024
mattheww added a commit to mattheww/lexeywan that referenced this pull request Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants