From ea4708c444509449b86c50b7b1b23f9ff5af4e97 Mon Sep 17 00:00:00 2001
From: Nick Spain <nicholas.spain@stileeducation.com>
Date: Fri, 1 Jan 2021 13:50:50 +1100
Subject: [PATCH] Mark HasSource::source_old as deprecated but allow at all
 call sites

---
 crates/assists/src/handlers/fill_match_arms.rs  |  1 +
 crates/assists/src/handlers/fix_visibility.rs   |  2 ++
 crates/assists/src/utils.rs                     | 11 +++++++----
 crates/completion/src/completions/trait_impl.rs |  2 ++
 crates/completion/src/render/const_.rs          |  1 +
 crates/completion/src/render/function.rs        |  1 +
 crates/completion/src/render/macro_.rs          |  1 +
 crates/completion/src/render/type_alias.rs      |  1 +
 crates/hir/src/code_model.rs                    |  2 ++
 crates/hir/src/has_source.rs                    |  1 +
 crates/ide/src/diagnostics/fixes.rs             |  3 +++
 crates/ide/src/display/navigation_target.rs     |  6 ++++++
 crates/ide/src/hover.rs                         |  4 ++++
 crates/ide_db/src/search.rs                     |  2 ++
 crates/rust-analyzer/src/cli/analysis_stats.rs  |  1 +
 15 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/crates/assists/src/handlers/fill_match_arms.rs b/crates/assists/src/handlers/fill_match_arms.rs
index a8efad6d634..d17c82e18a5 100644
--- a/crates/assists/src/handlers/fill_match_arms.rs
+++ b/crates/assists/src/handlers/fill_match_arms.rs
@@ -196,6 +196,7 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::Variant) -> Optio
     let path = mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var))?);
 
     // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
+    #[allow(deprecated)]
     let pat: ast::Pat = match var.source_old(db).value.kind() {
         ast::StructKind::Tuple(field_list) => {
             let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count());
diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs
index d8150abd965..7d440d4206b 100644
--- a/crates/assists/src/handlers/fix_visibility.rs
+++ b/crates/assists/src/handlers/fix_visibility.rs
@@ -97,6 +97,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) ->
     let parent_name = parent.name(ctx.db());
     let target_module = parent.module(ctx.db());
 
+    #[allow(deprecated)]
     let in_file_source = record_field_def.source_old(ctx.db());
     let (offset, current_visibility, target) = match in_file_source.value {
         hir::FieldSource::Named(it) => {
@@ -150,6 +151,7 @@ fn target_data_for_def(
         S: HasSource<Ast = Ast>,
         Ast: AstNode + ast::VisibilityOwner,
     {
+        #[allow(deprecated)]
         let source = x.source_old(db);
         let in_file_syntax = source.syntax();
         let file_id = in_file_syntax.file_id;
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs
index 7ee7111aee2..d15e5a24bec 100644
--- a/crates/assists/src/utils.rs
+++ b/crates/assists/src/utils.rs
@@ -98,10 +98,13 @@ pub fn filter_assoc_items(
 
     items
         .iter()
-        .map(|i| match i {
-            hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source_old(db).value),
-            hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source_old(db).value),
-            hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source_old(db).value),
+        .map(|i| {
+            #[allow(deprecated)]
+            match i {
+                hir::AssocItem::Function(i) => ast::AssocItem::Fn(i.source_old(db).value),
+                hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAlias(i.source_old(db).value),
+                hir::AssocItem::Const(i) => ast::AssocItem::Const(i.source_old(db).value),
+            }
         })
         .filter(has_def_name)
         .filter(|it| match it {
diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs
index 759253c53d4..43b3d939f39 100644
--- a/crates/completion/src/completions/trait_impl.rs
+++ b/crates/completion/src/completions/trait_impl.rs
@@ -156,6 +156,7 @@ fn add_function_impl(
     };
     let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
 
+    #[allow(deprecated)]
     let function_decl = function_declaration(&func.source_old(ctx.db).value);
     match ctx.config.snippet_cap {
         Some(cap) => {
@@ -200,6 +201,7 @@ fn add_const_impl(
     let const_name = const_.name(ctx.db).map(|n| n.to_string());
 
     if let Some(const_name) = const_name {
+        #[allow(deprecated)]
         let snippet = make_const_compl_syntax(&const_.source_old(ctx.db).value);
 
         let range = TextRange::new(const_def_node.text_range().start(), ctx.source_range().end());
diff --git a/crates/completion/src/render/const_.rs b/crates/completion/src/render/const_.rs
index a8820a4fe1a..648a1afc51c 100644
--- a/crates/completion/src/render/const_.rs
+++ b/crates/completion/src/render/const_.rs
@@ -27,6 +27,7 @@ struct ConstRender<'a> {
 
 impl<'a> ConstRender<'a> {
     fn new(ctx: RenderContext<'a>, const_: hir::Const) -> ConstRender<'a> {
+        #[allow(deprecated)]
         let ast_node = const_.source_old(ctx.db()).value;
         ConstRender { ctx, const_, ast_node }
     }
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs
index d9ea425a0a0..4c899620401 100644
--- a/crates/completion/src/render/function.rs
+++ b/crates/completion/src/render/function.rs
@@ -34,6 +34,7 @@ impl<'a> FunctionRender<'a> {
         fn_: hir::Function,
     ) -> FunctionRender<'a> {
         let name = local_name.unwrap_or_else(|| fn_.name(ctx.db()).to_string());
+        #[allow(deprecated)]
         let ast_node = fn_.source_old(ctx.db()).value;
 
         FunctionRender { ctx, name, func: fn_, ast_node }
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs
index 3d13fd9e2f6..95408ff9af2 100644
--- a/crates/completion/src/render/macro_.rs
+++ b/crates/completion/src/render/macro_.rs
@@ -96,6 +96,7 @@ impl<'a> MacroRender<'a> {
     }
 
     fn detail(&self) -> String {
+        #[allow(deprecated)]
         let ast_node = self.macro_.source_old(self.ctx.db()).value;
         macro_label(&ast_node)
     }
diff --git a/crates/completion/src/render/type_alias.rs b/crates/completion/src/render/type_alias.rs
index 4099a5d0e14..276090015e3 100644
--- a/crates/completion/src/render/type_alias.rs
+++ b/crates/completion/src/render/type_alias.rs
@@ -27,6 +27,7 @@ struct TypeAliasRender<'a> {
 
 impl<'a> TypeAliasRender<'a> {
     fn new(ctx: RenderContext<'a>, type_alias: hir::TypeAlias) -> TypeAliasRender<'a> {
+        #[allow(deprecated)]
         let ast_node = type_alias.source_old(ctx.db()).value;
         TypeAliasRender { ctx, type_alias, ast_node }
     }
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 5020aa196de..285905e96c3 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -989,6 +989,7 @@ impl MacroDef {
         if self.is_proc_macro() {
             return None;
         }
+        #[allow(deprecated)]
         self.source_old(db).value.name().map(|it| it.as_name())
     }
 
@@ -1378,6 +1379,7 @@ impl Impl {
     }
 
     pub fn is_builtin_derive(self, db: &dyn HirDatabase) -> Option<InFile<ast::Attr>> {
+        #[allow(deprecated)]
         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 84fbeca751d..8a7306def88 100644
--- a/crates/hir/src/has_source.rs
+++ b/crates/hir/src/has_source.rs
@@ -16,6 +16,7 @@ use crate::{
 
 pub trait HasSource {
     type Ast;
+    #[deprecated = "migrating to source() method that returns an Option"]
     fn source_old(self, db: &dyn HirDatabase) -> InFile<Self::Ast>;
     fn source(self, db: &dyn HirDatabase) -> Option<InFile<Self::Ast>>;
 }
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs
index 702e8239d17..0b5e0a4c174 100644
--- a/crates/ide/src/diagnostics/fixes.rs
+++ b/crates/ide/src/diagnostics/fixes.rs
@@ -156,6 +156,7 @@ fn missing_record_expr_field_fix(
     let record_fields = match VariantDef::from(def_id) {
         VariantDef::Struct(s) => {
             module = s.module(sema.db);
+            #[allow(deprecated)]
             let source = s.source_old(sema.db);
             def_file_id = source.file_id;
             let fields = source.value.field_list()?;
@@ -163,12 +164,14 @@ fn missing_record_expr_field_fix(
         }
         VariantDef::Union(u) => {
             module = u.module(sema.db);
+            #[allow(deprecated)]
             let source = u.source_old(sema.db);
             def_file_id = source.file_id;
             source.value.record_field_list()?
         }
         VariantDef::Variant(e) => {
             module = e.module(sema.db);
+            #[allow(deprecated)]
             let source = e.source_old(sema.db);
             def_file_id = source.file_id;
             let fields = source.value.field_list()?;
diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs
index de4c0fa12dd..efa0418adaa 100644
--- a/crates/ide/src/display/navigation_target.rs
+++ b/crates/ide/src/display/navigation_target.rs
@@ -285,6 +285,7 @@ where
     D::Ast: ast::NameOwner + ShortLabel,
 {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
+        #[allow(deprecated)]
         let src = self.source_old(db);
         let mut res = NavigationTarget::from_named(
             db,
@@ -314,6 +315,7 @@ impl ToNav for hir::Module {
 
 impl ToNav for hir::Impl {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
+        #[allow(deprecated)]
         let src = self.source_old(db);
         let derive_attr = self.is_builtin_derive(db);
         let frange = if let Some(item) = &derive_attr {
@@ -339,6 +341,7 @@ impl ToNav for hir::Impl {
 
 impl ToNav for hir::Field {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
+        #[allow(deprecated)]
         let src = self.source_old(db);
 
         match &src.value {
@@ -365,6 +368,7 @@ impl ToNav for hir::Field {
 
 impl ToNav for hir::MacroDef {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
+        #[allow(deprecated)]
         let src = self.source_old(db);
         log::debug!("nav target {:#?}", src.value.syntax());
         let mut res = NavigationTarget::from_named(
@@ -448,6 +452,7 @@ impl ToNav for hir::Label {
 
 impl ToNav for hir::TypeParam {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
+        #[allow(deprecated)]
         let src = self.source_old(db);
         let full_range = match &src.value {
             Either::Left(it) => it.syntax().text_range(),
@@ -472,6 +477,7 @@ impl ToNav for hir::TypeParam {
 
 impl ToNav for hir::LifetimeParam {
     fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
+        #[allow(deprecated)]
         let src = self.source_old(db);
         let full_range = src.value.syntax().text_range();
         NavigationTarget {
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 90781ea3420..c192e3ed7f6 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -206,6 +206,7 @@ fn runnable_action(
                 _ => None,
             },
             ModuleDef::Function(it) => {
+                #[allow(deprecated)]
                 let src = it.source_old(sema.db);
                 if src.file_id != file_id.into() {
                     mark::hit!(hover_macro_generated_struct_fn_doc_comment);
@@ -332,10 +333,12 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
             if it.is_proc_macro() {
                 return None;
             }
+            #[allow(deprecated)]
             let label = macro_label(&it.source_old(db).value);
             from_def_source_labeled(db, it, Some(label), mod_path)
         }
         Definition::Field(def) => {
+            #[allow(deprecated)]
             let src = def.source_old(db).value;
             if let FieldSource::Named(it) = src {
                 from_def_source_labeled(db, def, it.short_label(), mod_path)
@@ -385,6 +388,7 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
         D: HasSource<Ast = A> + HasAttrs + Copy,
         A: ShortLabel,
     {
+        #[allow(deprecated)]
         let short_label = def.source_old(db).value.short_label();
         from_def_source_labeled(db, def, short_label, mod_path)
     }
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs
index 2df4894a1e0..e69f9d1410f 100644
--- a/crates/ide_db/src/search.rs
+++ b/crates/ide_db/src/search.rs
@@ -120,6 +120,7 @@ impl Definition {
         let file_id = module_src.file_id.original_file(db);
 
         if let Definition::Local(var) = self {
+            #[allow(deprecated)]
             let range = match var.parent(db) {
                 DefWithBody::Function(f) => f.source_old(db).value.syntax().text_range(),
                 DefWithBody::Const(c) => c.source_old(db).value.syntax().text_range(),
@@ -131,6 +132,7 @@ impl Definition {
         }
 
         if let Definition::LifetimeParam(param) = self {
+            #[allow(deprecated)]
             let range = match param.parent(db) {
                 hir::GenericDef::Function(it) => it.source_old(db).value.syntax().text_range(),
                 hir::GenericDef::Adt(it) => match it {
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 3ee11a8f07d..bfc7d7b5a67 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -161,6 +161,7 @@ impl AnalysisStatsCmd {
             }
             let mut msg = format!("processing: {}", full_name);
             if verbosity.is_verbose() {
+                #[allow(deprecated)]
                 let src = f.source_old(db);
                 let original_file = src.file_id.original_file(db);
                 let path = vfs.file_path(original_file);