Properly account for editions in names

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`.
This commit is contained in:
Chayim Refael Friedman 2024-08-16 02:36:24 +03:00
parent 91aa3f46b3
commit 9d3368f2c2
179 changed files with 2485 additions and 1250 deletions

View file

@ -8630,3 +8630,75 @@ fn main() {
"#]],
);
}
#[test]
fn raw_keyword_different_editions() {
check(
r#"
//- /lib1.rs crate:with_edition_2015 edition:2015
pub fn dyn() {}
//- /lib2.rs crate:with_edition_2018 edition:2018 deps:with_edition_2015 new_source_root:local
fn foo() {
with_edition_2015::r#dyn$0();
}
"#,
expect![[r#"
*r#dyn*
```rust
with_edition_2015
```
```rust
pub fn r#dyn()
```
"#]],
);
check(
r#"
//- /lib1.rs crate:with_edition_2018 edition:2018
pub fn r#dyn() {}
//- /lib2.rs crate:with_edition_2015 edition:2015 deps:with_edition_2018 new_source_root:local
fn foo() {
with_edition_2018::dyn$0();
}
"#,
expect![[r#"
*dyn*
```rust
with_edition_2018
```
```rust
pub fn dyn()
```
"#]],
);
check(
r#"
//- /lib1.rs crate:escaping_needlessly edition:2015
pub fn r#dyn() {}
//- /lib2.rs crate:dependent edition:2015 deps:escaping_needlessly new_source_root:local
fn foo() {
escaping_needlessly::dyn$0();
}
"#,
expect![[r#"
*dyn*
```rust
escaping_needlessly
```
```rust
pub fn dyn()
```
"#]],
);
}