diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-06 20:28:28 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-06 20:28:28 +0000 |
commit | f18b7e18c479144325ec150be00837aae3329ae2 (patch) | |
tree | 2c8fbda35c5d9f43b70fe3c6e91ce3e4a8bb3226 /crates/ra_syntax/src | |
parent | d3702c02cdff158f05d2af1bd7106cca8a3e4ba9 (diff) | |
parent | 8c86963d47953045f2f33ee6620d305a6589641e (diff) |
Merge #2484
2484: DynMap r=matklad a=matklad
Implement a `DynMap` a semi-dynamic, semi-static map, which helps to thread heterogeneously typed info in a uniform way. Totally inspired by https://github.com/JetBrains/kotlin/blob/df3bee30384787d8951ea548a4257c2cb52a16a3/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java.
@flodiebold wdyt? Seems like a potentially useful pattern for various source-map-like things.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index e049fce61..db6230aab 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -1,6 +1,10 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use std::{iter::successors, marker::PhantomData}; | 3 | use std::{ |
4 | hash::{Hash, Hasher}, | ||
5 | iter::successors, | ||
6 | marker::PhantomData, | ||
7 | }; | ||
4 | 8 | ||
5 | use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange}; | 9 | use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange}; |
6 | 10 | ||
@@ -43,7 +47,7 @@ impl SyntaxNodePtr { | |||
43 | } | 47 | } |
44 | 48 | ||
45 | /// Like `SyntaxNodePtr`, but remembers the type of node | 49 | /// Like `SyntaxNodePtr`, but remembers the type of node |
46 | #[derive(Debug, Hash)] | 50 | #[derive(Debug)] |
47 | pub struct AstPtr<N: AstNode> { | 51 | pub struct AstPtr<N: AstNode> { |
48 | raw: SyntaxNodePtr, | 52 | raw: SyntaxNodePtr, |
49 | _ty: PhantomData<fn() -> N>, | 53 | _ty: PhantomData<fn() -> N>, |
@@ -64,6 +68,12 @@ impl<N: AstNode> PartialEq for AstPtr<N> { | |||
64 | } | 68 | } |
65 | } | 69 | } |
66 | 70 | ||
71 | impl<N: AstNode> Hash for AstPtr<N> { | ||
72 | fn hash<H: Hasher>(&self, state: &mut H) { | ||
73 | self.raw.hash(state) | ||
74 | } | ||
75 | } | ||
76 | |||
67 | impl<N: AstNode> AstPtr<N> { | 77 | impl<N: AstNode> AstPtr<N> { |
68 | pub fn new(node: &N) -> AstPtr<N> { | 78 | pub fn new(node: &N) -> AstPtr<N> { |
69 | AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } | 79 | AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } |