mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
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:
parent
91aa3f46b3
commit
9d3368f2c2
179 changed files with 2485 additions and 1250 deletions
|
@ -34,19 +34,20 @@ pub fn get_missing_assoc_items(
|
|||
// may share the same name as a function or constant.
|
||||
let mut impl_fns_consts = FxHashSet::default();
|
||||
let mut impl_type = FxHashSet::default();
|
||||
let edition = imp.module(sema.db).krate().edition(sema.db);
|
||||
|
||||
for item in imp.items(sema.db) {
|
||||
match item {
|
||||
hir::AssocItem::Function(it) => {
|
||||
impl_fns_consts.insert(it.name(sema.db).display(sema.db).to_string());
|
||||
impl_fns_consts.insert(it.name(sema.db).display(sema.db, edition).to_string());
|
||||
}
|
||||
hir::AssocItem::Const(it) => {
|
||||
if let Some(name) = it.name(sema.db) {
|
||||
impl_fns_consts.insert(name.display(sema.db).to_string());
|
||||
impl_fns_consts.insert(name.display(sema.db, edition).to_string());
|
||||
}
|
||||
}
|
||||
hir::AssocItem::TypeAlias(it) => {
|
||||
impl_type.insert(it.name(sema.db).display(sema.db).to_string());
|
||||
impl_type.insert(it.name(sema.db).display(sema.db, edition).to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,15 +57,14 @@ pub fn get_missing_assoc_items(
|
|||
.items(sema.db)
|
||||
.into_iter()
|
||||
.filter(|i| match i {
|
||||
hir::AssocItem::Function(f) => {
|
||||
!impl_fns_consts.contains(&f.name(sema.db).display(sema.db).to_string())
|
||||
}
|
||||
hir::AssocItem::Function(f) => !impl_fns_consts
|
||||
.contains(&f.name(sema.db).display(sema.db, edition).to_string()),
|
||||
hir::AssocItem::TypeAlias(t) => {
|
||||
!impl_type.contains(&t.name(sema.db).display(sema.db).to_string())
|
||||
!impl_type.contains(&t.name(sema.db).display(sema.db, edition).to_string())
|
||||
}
|
||||
hir::AssocItem::Const(c) => c
|
||||
.name(sema.db)
|
||||
.map(|n| !impl_fns_consts.contains(&n.display(sema.db).to_string()))
|
||||
.map(|n| !impl_fns_consts.contains(&n.display(sema.db, edition).to_string()))
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
.collect()
|
||||
|
@ -116,6 +116,7 @@ mod tests {
|
|||
use expect_test::{expect, Expect};
|
||||
use hir::FilePosition;
|
||||
use hir::Semantics;
|
||||
use span::Edition;
|
||||
use syntax::ast::{self, AstNode};
|
||||
use test_fixture::ChangeFixture;
|
||||
|
||||
|
@ -140,7 +141,7 @@ mod tests {
|
|||
sema.find_node_at_offset_with_descend(file.syntax(), position.offset).unwrap();
|
||||
let trait_ = crate::traits::resolve_target_trait(&sema, &impl_block);
|
||||
let actual = match trait_ {
|
||||
Some(trait_) => trait_.name(&db).display(&db).to_string(),
|
||||
Some(trait_) => trait_.name(&db).display(&db, Edition::CURRENT).to_string(),
|
||||
None => String::new(),
|
||||
};
|
||||
expect.assert_eq(&actual);
|
||||
|
@ -155,7 +156,7 @@ mod tests {
|
|||
let items = crate::traits::get_missing_assoc_items(&sema, &impl_block);
|
||||
let actual = items
|
||||
.into_iter()
|
||||
.map(|item| item.name(&db).unwrap().display(&db).to_string())
|
||||
.map(|item| item.name(&db).unwrap().display(&db, Edition::CURRENT).to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
expect.assert_eq(&actual);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue