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

fix: Properly account for editions in names #17905

Merged

Conversation

ChayimFriedman2
Copy link
Contributor

@ChayimFriedman2 ChayimFriedman2 commented Aug 16, 2024

This PR touches a lot of parts. But the main changes are changing hir_expand::Name to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing is_keyword() and is_raw_identifier() to be edition-aware (this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now.

The rules of thumb are:

  • If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code.
  • For tests, I chose Edition::CURRENT (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn).
  • For debugging tools (helper methods and logs), I used Edition::LATEST.

Reviewing notes:

This is a really big PR but most of it is mechanical translation. I changed Name displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in ide-assists, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). ide-completions and ide-diagnostics were solved pretty easily by introducing an edition field to their context. ide contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file.

I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to Name), some were changed to a new method is_any_identifier() because they really want any possible keyword.

Fixes #17895.
Fixes #17774.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 16, 2024
@ChayimFriedman2 ChayimFriedman2 changed the title Properly account for editions in names fix: Properly account for editions in names Aug 16, 2024
@ChayimFriedman2 ChayimFriedman2 force-pushed the edition-dependent-raw-keyword branch from a7462d0 to 9d3cd5a Compare August 16, 2024 03:06
@ChayimFriedman2
Copy link
Contributor Author

I didn't know we run Clippy!

crates/hir-def/src/import_map.rs Outdated Show resolved Hide resolved
crates/hir-def/src/import_map.rs Outdated Show resolved Hide resolved
crates/hir-expand/src/name.rs Outdated Show resolved Hide resolved
crates/hir-ty/src/diagnostics/decl_check.rs Outdated Show resolved Hide resolved
crates/ide-completion/src/completions/flyimport.rs Outdated Show resolved Hide resolved
crates/ide-completion/src/tests/flyimport.rs Outdated Show resolved Hide resolved
crates/ide/src/inlay_hints/param_name.rs Outdated Show resolved Hide resolved
crates/ide/src/rename.rs Outdated Show resolved Hide resolved
crates/syntax-bridge/src/lib.rs Outdated Show resolved Hide resolved
@ChayimFriedman2 ChayimFriedman2 force-pushed the edition-dependent-raw-keyword branch 2 times, most recently from 3ef8fe7 to 28f004a Compare August 16, 2024 12:42
@ChayimFriedman2
Copy link
Contributor Author

Fixed all comments.

@ChayimFriedman2 ChayimFriedman2 force-pushed the edition-dependent-raw-keyword branch from 28f004a to e610a81 Compare August 16, 2024 12:44
@Veykril
Copy link
Member

Veykril commented Aug 16, 2024

r=me with that last thing fixed, thanks!
@bors delegate+

@bors
Copy link
Contributor

bors commented Aug 16, 2024

✌️ @ChayimFriedman2, you can now approve this pull request!

If @Veykril told you to "r=me" after making some further change, please make that change, then do @bors r=@Veykril

This PR touches a lot of parts. But the main changes are changing
`hir_expand::Name` to be raw edition-dependently and only when necessary
(unrelated to how the user originally wrote the identifier),
and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware
(this was done in rust-lang#17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly
escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined
   by the edition of the edited crate. This is nice for IDE features,
   but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update
   tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
@ChayimFriedman2 ChayimFriedman2 force-pushed the edition-dependent-raw-keyword branch from e610a81 to 9d3368f Compare August 16, 2024 13:48
@ChayimFriedman2
Copy link
Contributor Author

@bors r=@Veykril

@bors
Copy link
Contributor

bors commented Aug 16, 2024

📌 Commit 9d3368f has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 16, 2024

⌛ Testing commit 9d3368f with merge c9ee892...

@bors
Copy link
Contributor

bors commented Aug 16, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing c9ee892 to master...

@bors bors merged commit c9ee892 into rust-lang:master Aug 16, 2024
11 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the edition-dependent-raw-keyword branch August 16, 2024 15:10
@Veykril
Copy link
Member

Veykril commented Aug 22, 2024

There should be a convenience method on HirFileId now via HirFileExt::edition for this

Turns out I was dumb, that function is something I introduced in a non yet merged branch of mine 🙃 apologies for that confusion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rust-analyzer completes r#gen even before edition 2024 Name escaping is not edition aware
4 participants