]> git.lizzy.rs Git - rust.git/commitdiff
Mark HasSource::source_old as deprecated but allow at all call sites
authorNick Spain <nicholas.spain@stileeducation.com>
Fri, 1 Jan 2021 02:50:50 +0000 (13:50 +1100)
committerNick Spain <nicholas.spain@stileeducation.com>
Sat, 2 Jan 2021 10:53:51 +0000 (21:53 +1100)
15 files changed:
crates/assists/src/handlers/fill_match_arms.rs
crates/assists/src/handlers/fix_visibility.rs
crates/assists/src/utils.rs
crates/completion/src/completions/trait_impl.rs
crates/completion/src/render/const_.rs
crates/completion/src/render/function.rs
crates/completion/src/render/macro_.rs
crates/completion/src/render/type_alias.rs
crates/hir/src/code_model.rs
crates/hir/src/has_source.rs
crates/ide/src/diagnostics/fixes.rs
crates/ide/src/display/navigation_target.rs
crates/ide/src/hover.rs
crates/ide_db/src/search.rs
crates/rust-analyzer/src/cli/analysis_stats.rs

index a8efad6d63456ea283dffb3a1d85a723d77a9b3b..d17c82e18a5316d3fa6039ed602403fbfe3bb134 100644 (file)
@@ -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());
index d8150abd9657daa4a06b66c83822153cd91ee9e6..7d440d4206bdd5fbab0f4422e8c043aea453369c 100644 (file)
@@ -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 offset_target_and_file_id<S, Ast>(
         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;
index 7ee7111aee26ef100a2eda88a77a1347b00fedf8..d15e5a24bec7cc20789b9c37e1b0396818941929 100644 (file)
@@ -98,10 +98,13 @@ fn has_def_name(item: &ast::AssocItem) -> bool {
 
     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 {
index 759253c53d4f4c34cd0ab46e3ad1f6a1b2dbac18..43b3d939f39869cf52adcc6a8322181b06c1067e 100644 (file)
@@ -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());
index a8820a4fe1a16dc32ab19ad7fdfa2fbb2e0cbd1b..648a1afc51c20ae9afd09088ea344f3524c6e82e 100644 (file)
@@ -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 }
     }
index d9ea425a0a0e350b7e5125b3d0d7f90eeb04b07c..4c8996204017f58096dc7c37658ab00d6c062a4b 100644 (file)
@@ -34,6 +34,7 @@ fn new(
         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 }
index 3d13fd9e2f69a84159e88348c306216e2a1fe573..95408ff9af206aefc13d2aa1c7148b452d2d26e7 100644 (file)
@@ -96,6 +96,7 @@ fn banged_name(&self) -> String {
     }
 
     fn detail(&self) -> String {
+        #[allow(deprecated)]
         let ast_node = self.macro_.source_old(self.ctx.db()).value;
         macro_label(&ast_node)
     }
index 4099a5d0e14f83637ecd674ac28316a8fb743c62..276090015e3337df18e0ecb79157b0789e7ba320 100644 (file)
@@ -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 }
     }
index 5020aa196dea693fdd6a4b31fa7f973298d1516e..285905e96c38a9636644d644d7f6a02d9f201135 100644 (file)
@@ -989,6 +989,7 @@ pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
         if self.is_proc_macro() {
             return None;
         }
+        #[allow(deprecated)]
         self.source_old(db).value.name().map(|it| it.as_name())
     }
 
@@ -1378,6 +1379,7 @@ pub fn krate(self, db: &dyn HirDatabase) -> Crate {
     }
 
     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);
index 84fbeca751d549afb5d217007ef38596cc5e520c..8a7306def8826f634f53003514246f4fd5baa8af 100644 (file)
@@ -16,6 +16,7 @@
 
 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>>;
 }
index 702e8239d179cf1f5a202536e8bdc02e577b6786..0b5e0a4c174de24878f436efb16d17089c55418a 100644 (file)
@@ -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()?;
index de4c0fa12ddc0b75ba2785f365676a65f14fc080..efa0418adaae148d17db12c4d120086855d89880 100644 (file)
@@ -285,6 +285,7 @@ impl<D> ToNav for D
     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 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
 
 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 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
 
 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 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
 
 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 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
 
 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 @@ fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
 
 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 {
index 90781ea3420c38b2a969b954f6b9d119afcb7ba8..c192e3ed7f688e88a3f9c113458a0280f9578c46 100644 (file)
@@ -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 from_def_source<A, D>(db: &RootDatabase, def: D, mod_path: Option<String>) ->
         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)
     }
index 2df4894a1e095092e7dfe26b911b21ed4fbd9c8c..e69f9d1410f79a5948dbbb1fdde4fea3c74ddccc 100644 (file)
@@ -120,6 +120,7 @@ fn search_scope(&self, db: &RootDatabase) -> SearchScope {
         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 @@ fn search_scope(&self, db: &RootDatabase) -> SearchScope {
         }
 
         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 {
index 3ee11a8f07d432bf9120e939f771825998d51b7f..bfc7d7b5a67d526963b8c82579aa9e18b4822aca 100644 (file)
@@ -161,6 +161,7 @@ pub fn run(self, verbosity: Verbosity) -> Result<()> {
             }
             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);