From c1244c853c6bdc42bf91a77768963c0d287093ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 00:27:00 +0200 Subject: Forward compat --- crates/ra_hir_def/src/body.rs | 6 +++--- crates/ra_hir_def/src/body/lower.rs | 6 +++--- crates/ra_hir_def/src/diagnostics.rs | 2 +- crates/ra_hir_expand/src/ast_id_map.rs | 2 +- crates/ra_hir_ty/src/diagnostics.rs | 10 +++++----- crates/ra_hir_ty/src/expr.rs | 6 +++--- crates/ra_hir_ty/src/tests.rs | 2 +- crates/ra_syntax/src/ptr.rs | 17 ++++++++--------- 8 files changed, 25 insertions(+), 26 deletions(-) (limited to 'crates') 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 for Body { impl BodySourceMap { pub fn expr_syntax(&self, expr: ExprId) -> Result { - self.expr_map_back[expr] + self.expr_map_back[expr].clone() } pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option { @@ -255,7 +255,7 @@ impl BodySourceMap { } pub fn pat_syntax(&self, pat: PatId) -> Result { - self.pat_map_back[pat] + self.pat_map_back[pat].clone() } pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option { @@ -264,6 +264,6 @@ impl BodySourceMap { } pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr { - self.field_map[&(expr, field)] + self.field_map[&(expr, field)].clone() } } 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<'_> { fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { let ptr = Either::Left(ptr); let src = self.expander.to_source(ptr); - let id = self.make_expr(expr, Ok(src)); + let id = self.make_expr(expr, Ok(src.clone())); self.source_map.expr_map.insert(src, id); id } @@ -118,7 +118,7 @@ impl ExprCollector<'_> { fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { let ptr = Either::Right(ptr); let src = self.expander.to_source(ptr); - let id = self.make_expr(expr, Ok(src)); + let id = self.make_expr(expr, Ok(src.clone())); self.source_map.expr_map.insert(src, id); id } @@ -136,7 +136,7 @@ impl ExprCollector<'_> { fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { let src = self.expander.to_source(ptr); - let id = self.make_pat(pat, Ok(src)); + let id = self.make_pat(pat, Ok(src.clone())); self.source_map.pat_map.insert(src, id); id } 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 { "unresolved module".to_string() } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.decl.into() } + InFile { file_id: self.file, value: self.decl.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { 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 { } pub(crate) fn get(&self, id: FileAstId) -> AstPtr { - self.arena[id.raw].cast::().unwrap() + self.arena[id.raw].clone().cast::().unwrap() } 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 { } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.field.into() } + InFile { file_id: self.file, value: self.field.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { @@ -45,7 +45,7 @@ impl Diagnostic for MissingFields { buf } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.field_list.into() } + InFile { file_id: self.file, value: self.field_list.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self @@ -78,7 +78,7 @@ impl Diagnostic for MissingPatFields { buf } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.field_list.into() } + InFile { file_id: self.file, value: self.field_list.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self @@ -97,7 +97,7 @@ impl Diagnostic for MissingMatchArms { String::from("Missing match arm") } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.match_expr.into() } + InFile { file_id: self.file, value: self.match_expr.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { self @@ -115,7 +115,7 @@ impl Diagnostic for MissingOkInTailExpr { "wrap return expression in Ok".to_string() } fn source(&self) -> InFile { - InFile { file_id: self.file, value: self.expr.into() } + InFile { file_id: self.file, value: self.expr.clone().into() } } fn as_any(&self) -> &(dyn Any + Send + 'static) { 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> { let (_, source_map) = db.body_with_source_map(self.func.into()); if let Ok(source_ptr) = source_map.expr_syntax(id) { - if let Some(expr) = source_ptr.value.left() { + if let Some(expr) = source_ptr.value.as_ref().left() { let root = source_ptr.file_syntax(db.upcast()); if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { if let Some(field_list) = record_lit.record_field_list() { @@ -120,7 +120,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { let (_, source_map) = db.body_with_source_map(self.func.into()); if let Ok(source_ptr) = source_map.pat_syntax(id) { - if let Some(expr) = source_ptr.value.left() { + if let Some(expr) = source_ptr.value.as_ref().left() { let root = source_ptr.file_syntax(db.upcast()); if let ast::Pat::RecordPat(record_pat) = expr.to_node(&root) { if let Some(field_list) = record_pat.record_field_pat_list() { @@ -205,7 +205,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { } if let Ok(source_ptr) = source_map.expr_syntax(id) { - if let Some(expr) = source_ptr.value.left() { + if let Some(expr) = source_ptr.value.as_ref().left() { let root = source_ptr.file_syntax(db.upcast()); if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { 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 { } Err(SyntheticSyntax) => continue, }; - types.push((syntax_ptr, ty)); + types.push((syntax_ptr.clone(), ty)); if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr) { mismatches.push((syntax_ptr, mismatch)); } 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}; /// A pointer to a syntax node inside a file. It can be used to remember a /// specific node across reparses of the same file. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SyntaxNodePtr { pub(crate) range: TextRange, kind: SyntaxKind, @@ -21,7 +21,7 @@ impl SyntaxNodePtr { SyntaxNodePtr { range: node.text_range(), kind: node.kind() } } - pub fn to_node(self, root: &SyntaxNode) -> SyntaxNode { + pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode { assert!(root.parent().is_none()); successors(Some(root.clone()), |node| { node.children().find(|it| self.range.is_subrange(&it.text_range())) @@ -30,11 +30,11 @@ impl SyntaxNodePtr { .unwrap_or_else(|| panic!("can't resolve local ptr to SyntaxNode: {:?}", self)) } - pub fn range(self) -> TextRange { + pub fn range(&self) -> TextRange { self.range } - pub fn kind(self) -> SyntaxKind { + pub fn kind(&self) -> SyntaxKind { self.kind } @@ -53,10 +53,9 @@ pub struct AstPtr { _ty: PhantomData N>, } -impl Copy for AstPtr {} impl Clone for AstPtr { fn clone(&self) -> AstPtr { - *self + AstPtr { raw: self.raw.clone(), _ty: PhantomData } } } @@ -79,13 +78,13 @@ impl AstPtr { AstPtr { raw: SyntaxNodePtr::new(node.syntax()), _ty: PhantomData } } - pub fn to_node(self, root: &SyntaxNode) -> N { + pub fn to_node(&self, root: &SyntaxNode) -> N { let syntax_node = self.raw.to_node(root); N::cast(syntax_node).unwrap() } - pub fn syntax_node_ptr(self) -> SyntaxNodePtr { - self.raw + pub fn syntax_node_ptr(&self) -> SyntaxNodePtr { + self.raw.clone() } pub fn cast(self) -> Option> { -- cgit v1.2.3