mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Forward compat
This commit is contained in:
parent
ca9a5dd165
commit
c1244c853c
8 changed files with 25 additions and 26 deletions
|
@ -236,7 +236,7 @@ impl Index<PatId> for Body {
|
|||
|
||||
impl BodySourceMap {
|
||||
pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> {
|
||||
self.expr_map_back[expr]
|
||||
self.expr_map_back[expr].clone()
|
||||
}
|
||||
|
||||
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
|
||||
|
@ -255,7 +255,7 @@ impl BodySourceMap {
|
|||
}
|
||||
|
||||
pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> {
|
||||
self.pat_map_back[pat]
|
||||
self.pat_map_back[pat].clone()
|
||||
}
|
||||
|
||||
pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> {
|
||||
|
@ -264,6 +264,6 @@ impl BodySourceMap {
|
|||
}
|
||||
|
||||
pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> {
|
||||
self.field_map[&(expr, field)]
|
||||
self.field_map[&(expr, field)].clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ impl ExprCollector<'_> {
|
|||
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> 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<ast::RecordField>) -> 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
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ impl Diagnostic for UnresolvedModule {
|
|||
"unresolved module".to_string()
|
||||
}
|
||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||
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
|
||||
|
|
|
@ -90,7 +90,7 @@ impl AstIdMap {
|
|||
}
|
||||
|
||||
pub(crate) fn get<N: AstNode>(&self, id: FileAstId<N>) -> AstPtr<N> {
|
||||
self.arena[id.raw].cast::<N>().unwrap()
|
||||
self.arena[id.raw].clone().cast::<N>().unwrap()
|
||||
}
|
||||
|
||||
fn alloc(&mut self, item: &SyntaxNode) -> ErasedFileAstId {
|
||||
|
|
|
@ -21,7 +21,7 @@ impl Diagnostic for NoSuchField {
|
|||
}
|
||||
|
||||
fn source(&self) -> InFile<SyntaxNodePtr> {
|
||||
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<SyntaxNodePtr> {
|
||||
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<SyntaxNodePtr> {
|
||||
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<SyntaxNodePtr> {
|
||||
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<SyntaxNodePtr> {
|
||||
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
|
||||
|
|
|
@ -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)) =
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<N: AstNode> {
|
|||
_ty: PhantomData<fn() -> N>,
|
||||
}
|
||||
|
||||
impl<N: AstNode> Copy for AstPtr<N> {}
|
||||
impl<N: AstNode> Clone for AstPtr<N> {
|
||||
fn clone(&self) -> AstPtr<N> {
|
||||
*self
|
||||
AstPtr { raw: self.raw.clone(), _ty: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,13 +78,13 @@ impl<N: AstNode> AstPtr<N> {
|
|||
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<U: AstNode>(self) -> Option<AstPtr<U>> {
|
||||
|
|
Loading…
Reference in a new issue