Mark HasSource::source_old as deprecated but allow at all call sites

This commit is contained in:
Nick Spain 2021-01-01 13:50:50 +11:00
parent 2de2b1eca3
commit ea4708c444
15 changed files with 35 additions and 4 deletions

View 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());

View 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 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;

View File

@ -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 {

View 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());

View 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 }
}

View File

@ -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 }

View File

@ -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)
}

View 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 }
}

View File

@ -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);

View File

@ -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>>;
}

View 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()?;

View File

@ -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 {

View 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 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)
}

View File

@ -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 {

View File

@ -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);