diff options
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/ast_id_map.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 2 | ||||
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 17 |
8 files changed, 25 insertions, 26 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 5f9d53ecb..e09996c6f 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -236,7 +236,7 @@ impl Index<PatId> for Body { | |||
236 | 236 | ||
237 | impl BodySourceMap { | 237 | impl BodySourceMap { |
238 | pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> { | 238 | pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> { |
239 | self.expr_map_back[expr] | 239 | self.expr_map_back[expr].clone() |
240 | } | 240 | } |
241 | 241 | ||
242 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { | 242 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { |
@@ -255,7 +255,7 @@ impl BodySourceMap { | |||
255 | } | 255 | } |
256 | 256 | ||
257 | pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { | 257 | pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { |
258 | self.pat_map_back[pat] | 258 | self.pat_map_back[pat].clone() |
259 | } | 259 | } |
260 | 260 | ||
261 | pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { | 261 | pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { |
@@ -264,6 +264,6 @@ impl BodySourceMap { | |||
264 | } | 264 | } |
265 | 265 | ||
266 | pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { | 266 | pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { |
267 | self.field_map[&(expr, field)] | 267 | self.field_map[&(expr, field)].clone() |
268 | } | 268 | } |
269 | } | 269 | } |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 0855c1d3a..9d6ee095e 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -106,7 +106,7 @@ impl ExprCollector<'_> { | |||
106 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 106 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
107 | let ptr = Either::Left(ptr); | 107 | let ptr = Either::Left(ptr); |
108 | let src = self.expander.to_source(ptr); | 108 | let src = self.expander.to_source(ptr); |
109 | let id = self.make_expr(expr, Ok(src)); | 109 | let id = self.make_expr(expr, Ok(src.clone())); |
110 | self.source_map.expr_map.insert(src, id); | 110 | self.source_map.expr_map.insert(src, id); |
111 | id | 111 | id |
112 | } | 112 | } |
@@ -118,7 +118,7 @@ impl ExprCollector<'_> { | |||
118 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { | 118 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { |
119 | let ptr = Either::Right(ptr); | 119 | let ptr = Either::Right(ptr); |
120 | let src = self.expander.to_source(ptr); | 120 | let src = self.expander.to_source(ptr); |
121 | let id = self.make_expr(expr, Ok(src)); | 121 | let id = self.make_expr(expr, Ok(src.clone())); |
122 | self.source_map.expr_map.insert(src, id); | 122 | self.source_map.expr_map.insert(src, id); |
123 | id | 123 | id |
124 | } | 124 | } |
@@ -136,7 +136,7 @@ impl ExprCollector<'_> { | |||
136 | 136 | ||
137 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { | 137 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { |
138 | let src = self.expander.to_source(ptr); | 138 | let src = self.expander.to_source(ptr); |
139 | let id = self.make_pat(pat, Ok(src)); | 139 | let id = self.make_pat(pat, Ok(src.clone())); |
140 | self.source_map.pat_map.insert(src, id); | 140 | self.source_map.pat_map.insert(src, id); |
141 | id | 141 | id |
142 | } | 142 | } |
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 095498429..cfa0f2f76 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -20,7 +20,7 @@ impl Diagnostic for UnresolvedModule { | |||
20 | "unresolved module".to_string() | 20 | "unresolved module".to_string() |
21 | } | 21 | } |
22 | fn source(&self) -> InFile<SyntaxNodePtr> { | 22 | fn source(&self) -> InFile<SyntaxNodePtr> { |
23 | InFile { file_id: self.file, value: self.decl.into() } | 23 | InFile { file_id: self.file, value: self.decl.clone().into() } |
24 | } | 24 | } |
25 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 25 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
26 | self | 26 | self |
diff --git a/crates/ra_hir_expand/src/ast_id_map.rs b/crates/ra_hir_expand/src/ast_id_map.rs index 5643ecdce..a3ca302c2 100644 --- a/crates/ra_hir_expand/src/ast_id_map.rs +++ b/crates/ra_hir_expand/src/ast_id_map.rs | |||
@@ -90,7 +90,7 @@ impl AstIdMap { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | pub(crate) fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> { | 92 | pub(crate) fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> { |
93 | self.arena[id.raw].cast::<N>().unwrap() | 93 | self.arena[id.raw].clone().cast::<N>().unwrap() |
94 | } | 94 | } |
95 | 95 | ||
96 | fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { | 96 | fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId { |
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 3f18acf1d..927896d6f 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -21,7 +21,7 @@ impl Diagnostic for NoSuchField { | |||
21 | } | 21 | } |
22 | 22 | ||
23 | fn source(&self) -> InFile<SyntaxNodePtr> { | 23 | fn source(&self) -> InFile<SyntaxNodePtr> { |
24 | InFile { file_id: self.file, value: self.field.into() } | 24 | InFile { file_id: self.file, value: self.field.clone().into() } |
25 | } | 25 | } |
26 | 26 | ||
27 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 27 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
@@ -45,7 +45,7 @@ impl Diagnostic for MissingFields { | |||
45 | buf | 45 | buf |
46 | } | 46 | } |
47 | fn source(&self) -> InFile<SyntaxNodePtr> { | 47 | fn source(&self) -> InFile<SyntaxNodePtr> { |
48 | InFile { file_id: self.file, value: self.field_list.into() } | 48 | InFile { file_id: self.file, value: self.field_list.clone().into() } |
49 | } | 49 | } |
50 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 50 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
51 | self | 51 | self |
@@ -78,7 +78,7 @@ impl Diagnostic for MissingPatFields { | |||
78 | buf | 78 | buf |
79 | } | 79 | } |
80 | fn source(&self) -> InFile<SyntaxNodePtr> { | 80 | fn source(&self) -> InFile<SyntaxNodePtr> { |
81 | InFile { file_id: self.file, value: self.field_list.into() } | 81 | InFile { file_id: self.file, value: self.field_list.clone().into() } |
82 | } | 82 | } |
83 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 83 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
84 | self | 84 | self |
@@ -97,7 +97,7 @@ impl Diagnostic for MissingMatchArms { | |||
97 | String::from("Missing match arm") | 97 | String::from("Missing match arm") |
98 | } | 98 | } |
99 | fn source(&self) -> InFile<SyntaxNodePtr> { | 99 | fn source(&self) -> InFile<SyntaxNodePtr> { |
100 | InFile { file_id: self.file, value: self.match_expr.into() } | 100 | InFile { file_id: self.file, value: self.match_expr.clone().into() } |
101 | } | 101 | } |
102 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 102 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
103 | self | 103 | self |
@@ -115,7 +115,7 @@ impl Diagnostic for MissingOkInTailExpr { | |||
115 | "wrap return expression in Ok".to_string() | 115 | "wrap return expression in Ok".to_string() |
116 | } | 116 | } |
117 | fn source(&self) -> InFile<SyntaxNodePtr> { | 117 | fn source(&self) -> InFile<SyntaxNodePtr> { |
118 | InFile { file_id: self.file, value: self.expr.into() } | 118 | InFile { file_id: self.file, value: self.expr.clone().into() } |
119 | } | 119 | } |
120 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 120 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
121 | self | 121 | self |
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index a7c8d74ab..827b687de 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -89,7 +89,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
89 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 89 | let (_, source_map) = db.body_with_source_map(self.func.into()); |
90 | 90 | ||
91 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 91 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
92 | if let Some(expr) = source_ptr.value.left() { | 92 | if let Some(expr) = source_ptr.value.as_ref().left() { |
93 | let root = source_ptr.file_syntax(db.upcast()); | 93 | let root = source_ptr.file_syntax(db.upcast()); |
94 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { | 94 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { |
95 | if let Some(field_list) = record_lit.record_field_list() { | 95 | if let Some(field_list) = record_lit.record_field_list() { |
@@ -120,7 +120,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
120 | let (_, source_map) = db.body_with_source_map(self.func.into()); | 120 | let (_, source_map) = db.body_with_source_map(self.func.into()); |
121 | 121 | ||
122 | if let Ok(source_ptr) = source_map.pat_syntax(id) { | 122 | if let Ok(source_ptr) = source_map.pat_syntax(id) { |
123 | if let Some(expr) = source_ptr.value.left() { | 123 | if let Some(expr) = source_ptr.value.as_ref().left() { |
124 | let root = source_ptr.file_syntax(db.upcast()); | 124 | let root = source_ptr.file_syntax(db.upcast()); |
125 | if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { | 125 | if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { |
126 | if let Some(field_list) = record_pat.record_field_pat_list() { | 126 | if let Some(field_list) = record_pat.record_field_pat_list() { |
@@ -205,7 +205,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
205 | } | 205 | } |
206 | 206 | ||
207 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 207 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
208 | if let Some(expr) = source_ptr.value.left() { | 208 | if let Some(expr) = source_ptr.value.as_ref().left() { |
209 | let root = source_ptr.file_syntax(db.upcast()); | 209 | let root = source_ptr.file_syntax(db.upcast()); |
210 | if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { | 210 | if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { |
211 | if let (Some(match_expr), Some(arms)) = | 211 | if let (Some(match_expr), Some(arms)) = |
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 47a7b9ffd..54e31602f 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -87,7 +87,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | |||
87 | } | 87 | } |
88 | Err(SyntheticSyntax) => continue, | 88 | Err(SyntheticSyntax) => continue, |
89 | }; | 89 | }; |
90 | types.push((syntax_ptr, ty)); | 90 | types.push((syntax_ptr.clone(), ty)); |
91 | if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr) { | 91 | if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr) { |
92 | mismatches.push((syntax_ptr, mismatch)); | 92 | mismatches.push((syntax_ptr, mismatch)); |
93 | } | 93 | } |
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index db6230aab..bc48a2e71 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -10,7 +10,7 @@ use crate::{AstNode, SyntaxKind, SyntaxNode, TextRange}; | |||
10 | 10 | ||
11 | /// A pointer to a syntax node inside a file. It can be used to remember a | 11 | /// A pointer to a syntax node inside a file. It can be used to remember a |
12 | /// specific node across reparses of the same file. | 12 | /// specific node across reparses of the same file. |
13 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 13 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
14 | pub struct SyntaxNodePtr { | 14 | pub struct SyntaxNodePtr { |
15 | pub(crate) range: TextRange, | 15 | pub(crate) range: TextRange, |
16 | kind: SyntaxKind, | 16 | kind: SyntaxKind, |
@@ -21,7 +21,7 @@ impl SyntaxNodePtr { | |||
21 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } | 21 | SyntaxNodePtr { range: node.text_range(), kind: node.kind() } |
22 | } | 22 | } |
23 | 23 | ||
24 | pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { | 24 | pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { |
25 | assert!(root.parent().is_none()); | 25 | assert!(root.parent().is_none()); |
26 | successors(Some(root.clone()), |node| { | 26 | successors(Some(root.clone()), |node| { |
27 | node.children().find(|it| self.range.is_subrange(&it.text_range())) | 27 | node.children().find(|it| self.range.is_subrange(&it.text_range())) |
@@ -30,11 +30,11 @@ impl SyntaxNodePtr { | |||
30 | .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) | 30 | .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) |
31 | } | 31 | } |
32 | 32 | ||
33 | pub fn range(self) -> TextRange { | 33 | pub fn range(&self) -> TextRange { |
34 | self.range | 34 | self.range |
35 | } | 35 | } |
36 | 36 | ||
37 | pub fn kind(self) -> SyntaxKind { | 37 | pub fn kind(&self) -> SyntaxKind { |
38 | self.kind | 38 | self.kind |
39 | } | 39 | } |
40 | 40 | ||
@@ -53,10 +53,9 @@ pub struct AstPtr<N: AstNode> { | |||
53 | _ty: PhantomData<fn() -> N>, | 53 | _ty: PhantomData<fn() -> N>, |
54 | } | 54 | } |
55 | 55 | ||
56 | impl<N: AstNode> Copy for AstPtr<N> {} | ||
57 | impl<N: AstNode> Clone for AstPtr<N> { | 56 | impl<N: AstNode> Clone for AstPtr<N> { |
58 | fn clone(&self) -> AstPtr<N> { | 57 | fn clone(&self) -> AstPtr<N> { |
59 | *self | 58 | AstPtr { raw: self.raw.clone(), _ty: PhantomData } |
60 | } | 59 | } |
61 | } | 60 | } |
62 | 61 | ||
@@ -79,13 +78,13 @@ impl<N: AstNode> AstPtr<N> { | |||
79 | AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } | 78 | AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } |
80 | } | 79 | } |
81 | 80 | ||
82 | pub fn to_node(self, root: &SyntaxNode) -> N { | 81 | pub fn to_node(&self, root: &SyntaxNode) -> N { |
83 | let syntax_node = self.raw.to_node(root); | 82 | let syntax_node = self.raw.to_node(root); |
84 | N::cast(syntax_node).unwrap() | 83 | N::cast(syntax_node).unwrap() |
85 | } | 84 | } |
86 | 85 | ||
87 | pub fn syntax_node_ptr(self) -> SyntaxNodePtr { | 86 | pub fn syntax_node_ptr(&self) -> SyntaxNodePtr { |
88 | self.raw | 87 | self.raw.clone() |
89 | } | 88 | } |
90 | 89 | ||
91 | pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> { | 90 | pub fn cast<U: AstNode>(self) -> Option<AstPtr<U>> { |