Skip to content

Commit c2f1334

Browse files
committed
Auto merge of rust-lang#15912 - Sarrus1:master, r=HKalbasi
chore: remove unused `PhantomData` This PR removes an unused `PhantomData` in `FileItemTreeId`. *Note:* I am not sure how this should be implemented, maybe as a type instead of a wrapper struct? I'd be happy to do so if needed 👍
2 parents 57e9024 + 97dea2c commit c2f1334

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

crates/hir-def/src/item_tree.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ mod tests;
3838
use std::{
3939
fmt::{self, Debug},
4040
hash::{Hash, Hasher},
41-
marker::PhantomData,
4241
ops::Index,
4342
};
4443

@@ -340,34 +339,37 @@ pub trait ItemTreeNode: Clone {
340339
fn id_to_mod_item(id: FileItemTreeId<Self>) -> ModItem;
341340
}
342341

343-
pub struct FileItemTreeId<N: ItemTreeNode> {
344-
index: Idx<N>,
345-
_p: PhantomData<N>,
342+
pub struct FileItemTreeId<N: ItemTreeNode>(Idx<N>);
343+
344+
impl<N: ItemTreeNode> FileItemTreeId<N> {
345+
pub fn index(&self) -> Idx<N> {
346+
self.0
347+
}
346348
}
347349

348350
impl<N: ItemTreeNode> Clone for FileItemTreeId<N> {
349351
fn clone(&self) -> Self {
350-
Self { index: self.index, _p: PhantomData }
352+
Self(self.0)
351353
}
352354
}
353355
impl<N: ItemTreeNode> Copy for FileItemTreeId<N> {}
354356

355357
impl<N: ItemTreeNode> PartialEq for FileItemTreeId<N> {
356358
fn eq(&self, other: &FileItemTreeId<N>) -> bool {
357-
self.index == other.index
359+
self.0 == other.0
358360
}
359361
}
360362
impl<N: ItemTreeNode> Eq for FileItemTreeId<N> {}
361363

362364
impl<N: ItemTreeNode> Hash for FileItemTreeId<N> {
363365
fn hash<H: Hasher>(&self, state: &mut H) {
364-
self.index.hash(state)
366+
self.0.hash(state)
365367
}
366368
}
367369

368370
impl<N: ItemTreeNode> fmt::Debug for FileItemTreeId<N> {
369371
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
370-
self.index.fmt(f)
372+
self.0.fmt(f)
371373
}
372374
}
373375

@@ -548,7 +550,7 @@ impl Index<RawVisibilityId> for ItemTree {
548550
impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
549551
type Output = N;
550552
fn index(&self, id: FileItemTreeId<N>) -> &N {
551-
N::lookup(self, id.index)
553+
N::lookup(self, id.index())
552554
}
553555
}
554556

@@ -925,23 +927,23 @@ impl ModItem {
925927

926928
pub fn ast_id(&self, tree: &ItemTree) -> FileAstId<ast::Item> {
927929
match self {
928-
ModItem::Use(it) => tree[it.index].ast_id().upcast(),
929-
ModItem::ExternCrate(it) => tree[it.index].ast_id().upcast(),
930-
ModItem::ExternBlock(it) => tree[it.index].ast_id().upcast(),
931-
ModItem::Function(it) => tree[it.index].ast_id().upcast(),
932-
ModItem::Struct(it) => tree[it.index].ast_id().upcast(),
933-
ModItem::Union(it) => tree[it.index].ast_id().upcast(),
934-
ModItem::Enum(it) => tree[it.index].ast_id().upcast(),
935-
ModItem::Const(it) => tree[it.index].ast_id().upcast(),
936-
ModItem::Static(it) => tree[it.index].ast_id().upcast(),
937-
ModItem::Trait(it) => tree[it.index].ast_id().upcast(),
938-
ModItem::TraitAlias(it) => tree[it.index].ast_id().upcast(),
939-
ModItem::Impl(it) => tree[it.index].ast_id().upcast(),
940-
ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
941-
ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
942-
ModItem::MacroCall(it) => tree[it.index].ast_id().upcast(),
943-
ModItem::MacroRules(it) => tree[it.index].ast_id().upcast(),
944-
ModItem::MacroDef(it) => tree[it.index].ast_id().upcast(),
930+
ModItem::Use(it) => tree[it.index()].ast_id().upcast(),
931+
ModItem::ExternCrate(it) => tree[it.index()].ast_id().upcast(),
932+
ModItem::ExternBlock(it) => tree[it.index()].ast_id().upcast(),
933+
ModItem::Function(it) => tree[it.index()].ast_id().upcast(),
934+
ModItem::Struct(it) => tree[it.index()].ast_id().upcast(),
935+
ModItem::Union(it) => tree[it.index()].ast_id().upcast(),
936+
ModItem::Enum(it) => tree[it.index()].ast_id().upcast(),
937+
ModItem::Const(it) => tree[it.index()].ast_id().upcast(),
938+
ModItem::Static(it) => tree[it.index()].ast_id().upcast(),
939+
ModItem::Trait(it) => tree[it.index()].ast_id().upcast(),
940+
ModItem::TraitAlias(it) => tree[it.index()].ast_id().upcast(),
941+
ModItem::Impl(it) => tree[it.index()].ast_id().upcast(),
942+
ModItem::TypeAlias(it) => tree[it.index()].ast_id().upcast(),
943+
ModItem::Mod(it) => tree[it.index()].ast_id().upcast(),
944+
ModItem::MacroCall(it) => tree[it.index()].ast_id().upcast(),
945+
ModItem::MacroRules(it) => tree[it.index()].ast_id().upcast(),
946+
ModItem::MacroDef(it) => tree[it.index()].ast_id().upcast(),
945947
}
946948
}
947949
}

crates/hir-def/src/item_tree/lower.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
use super::*;
1414

1515
fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
16-
FileItemTreeId { index, _p: PhantomData }
16+
FileItemTreeId(index)
1717
}
1818

1919
pub(super) struct Ctx<'a> {

0 commit comments

Comments
 (0)