From 27cadcd531c017aa7c78c6f7a36f2b7f2ce8a196 Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 13:05:28 +1100 Subject: HasSource::source -> HasSource::source_old To start migrating HasSource::source to return an Option. --- crates/hir/src/code_model.rs | 4 ++-- crates/hir/src/has_source.rs | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 97b7a8b5f..5020aa196 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -989,7 +989,7 @@ impl MacroDef { if self.is_proc_macro() { return None; } - self.source(db).value.name().map(|it| it.as_name()) + self.source_old(db).value.name().map(|it| it.as_name()) } /// Indicate it is a proc-macro @@ -1378,7 +1378,7 @@ impl Impl { } pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option> { - let src = self.source(db); + let src = self.source_old(db); let item = src.file_id.is_builtin_derive(db.upcast())?; let hygenic = hir_expand::hygiene::Hygiene::new(db.upcast(), item.file_id); diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index dd7c0c570..a8256c181 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -16,7 +16,7 @@ use crate::{ pub trait HasSource { type Ast; - fn source(self, db: &dyn HirDatabase) -> InFile; + fn source_old(self, db: &dyn HirDatabase) -> InFile; } /// NB: Module is !HasSource, because it has two source nodes at the same time: @@ -46,7 +46,7 @@ impl Module { impl HasSource for Field { type Ast = FieldSource; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { let var = VariantId::from(self.parent); let src = var.child_source(db.upcast()); src.map(|it| match it[self.id].clone() { @@ -57,61 +57,61 @@ impl HasSource for Field { } impl HasSource for Struct { type Ast = ast::Struct; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Union { type Ast = ast::Union; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Enum { type Ast = ast::Enum; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Variant { type Ast = ast::Variant; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.parent.id.child_source(db.upcast()).map(|map| map[self.id].clone()) } } impl HasSource for Function { type Ast = ast::Fn; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Const { type Ast = ast::Const; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Static { type Ast = ast::Static; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for Trait { type Ast = ast::Trait; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for TypeAlias { type Ast = ast::TypeAlias; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for MacroDef { type Ast = ast::Macro; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { InFile { file_id: self.id.ast_id.expect("MacroDef without ast_id").file_id, value: self.id.ast_id.expect("MacroDef without ast_id").to_node(db.upcast()), @@ -120,14 +120,14 @@ impl HasSource for MacroDef { } impl HasSource for Impl { type Ast = ast::Impl; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { self.id.lookup(db.upcast()).source(db.upcast()) } } impl HasSource for TypeParam { type Ast = Either; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { let child_source = self.id.parent.child_source(db.upcast()); child_source.map(|it| it[self.id.local_id].clone()) } @@ -135,7 +135,7 @@ impl HasSource for TypeParam { impl HasSource for LifetimeParam { type Ast = ast::LifetimeParam; - fn source(self, db: &dyn HirDatabase) -> InFile { + fn source_old(self, db: &dyn HirDatabase) -> InFile { let child_source = self.id.parent.child_source(db.upcast()); child_source.map(|it| it[self.id.local_id].clone()) } -- cgit v1.2.3