diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
commit | 631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch) | |
tree | a1b87c8f8cad01cf18f7c5f57a08f102771ed303 /src/tools/rust-analyzer/crates/ide-db | |
parent | Adding debian version 1.69.0+dfsg1-1. (diff) | |
download | rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rust-analyzer/crates/ide-db')
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs | 1 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs | 66 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/defs.rs | 30 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/helpers.rs | 10 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs | 2 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/lib.rs | 12 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/rename.rs | 105 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/search.rs | 50 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/source_change.rs | 8 | ||||
-rw-r--r-- | src/tools/rust-analyzer/crates/ide-db/src/use_trivial_constructor.rs (renamed from src/tools/rust-analyzer/crates/ide-db/src/use_trivial_contructor.rs) | 0 |
10 files changed, 157 insertions, 127 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs b/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs index 2b6b60547..0da4e729a 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/active_parameter.rs @@ -96,6 +96,7 @@ pub fn generic_def_for_node( hir::PathResolution::Def(hir::ModuleDef::Adt(it)) => it.into(), hir::PathResolution::Def(hir::ModuleDef::Function(it)) => it.into(), hir::PathResolution::Def(hir::ModuleDef::Trait(it)) => it.into(), + hir::PathResolution::Def(hir::ModuleDef::TraitAlias(it)) => it.into(), hir::PathResolution::Def(hir::ModuleDef::TypeAlias(it)) => it.into(), hir::PathResolution::Def(hir::ModuleDef::Variant(it)) => it.into(), hir::PathResolution::Def(hir::ModuleDef::BuiltinType(_)) diff --git a/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs b/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs index b1ee9b58d..ea1d9cc49 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/apply_change.rs @@ -71,70 +71,98 @@ impl RootDatabase { base_db::SourceRootQuery base_db::SourceRootCratesQuery - // AstDatabase + // ExpandDatabase hir::db::AstIdMapQuery + hir::db::ParseMacroExpansionQuery + hir::db::InternMacroCallQuery hir::db::MacroArgTextQuery hir::db::MacroDefQuery - hir::db::ParseMacroExpansionQuery hir::db::MacroExpandQuery + hir::db::ExpandProcMacroQuery + hir::db::MacroExpandErrorQuery hir::db::HygieneFrameQuery - hir::db::InternMacroCallQuery // DefDatabase hir::db::FileItemTreeQuery - hir::db::BlockDefMapQuery hir::db::CrateDefMapQueryQuery - hir::db::FieldsAttrsQuery - hir::db::VariantsAttrsQuery - hir::db::FieldsAttrsSourceMapQuery - hir::db::VariantsAttrsSourceMapQuery + hir::db::BlockDefMapQuery hir::db::StructDataQuery + hir::db::StructDataWithDiagnosticsQuery hir::db::UnionDataQuery + hir::db::UnionDataWithDiagnosticsQuery hir::db::EnumDataQuery + hir::db::EnumDataWithDiagnosticsQuery hir::db::ImplDataQuery + hir::db::ImplDataWithDiagnosticsQuery hir::db::TraitDataQuery + hir::db::TraitDataWithDiagnosticsQuery + hir::db::TraitAliasDataQuery hir::db::TypeAliasDataQuery hir::db::FunctionDataQuery hir::db::ConstDataQuery hir::db::StaticDataQuery + hir::db::Macro2DataQuery + hir::db::MacroRulesDataQuery + hir::db::ProcMacroDataQuery hir::db::BodyWithSourceMapQuery hir::db::BodyQuery hir::db::ExprScopesQuery hir::db::GenericParamsQuery + hir::db::VariantsAttrsQuery + hir::db::FieldsAttrsQuery + hir::db::VariantsAttrsSourceMapQuery + hir::db::FieldsAttrsSourceMapQuery hir::db::AttrsQuery hir::db::CrateLangItemsQuery hir::db::LangItemQuery hir::db::ImportMapQuery + hir::db::FieldVisibilitiesQuery + hir::db::FunctionVisibilityQuery + hir::db::ConstVisibilityQuery + hir::db::CrateSupportsNoStdQuery // HirDatabase hir::db::InferQueryQuery + hir::db::MirBodyQuery + hir::db::BorrowckQuery hir::db::TyQuery hir::db::ValueTyQuery hir::db::ImplSelfTyQuery + hir::db::ConstParamTyQuery + hir::db::ConstEvalQuery + hir::db::ConstEvalDiscriminantQuery hir::db::ImplTraitQuery hir::db::FieldTypesQuery + hir::db::LayoutOfAdtQuery + hir::db::TargetDataLayoutQuery hir::db::CallableItemSignatureQuery + hir::db::ReturnTypeImplTraitsQuery hir::db::GenericPredicatesForParamQuery hir::db::GenericPredicatesQuery + hir::db::TraitEnvironmentQuery hir::db::GenericDefaultsQuery hir::db::InherentImplsInCrateQuery - hir::db::TraitEnvironmentQuery + hir::db::InherentImplsInBlockQuery + hir::db::IncoherentInherentImplCratesQuery hir::db::TraitImplsInCrateQuery + hir::db::TraitImplsInBlockQuery hir::db::TraitImplsInDepsQuery - hir::db::AssociatedTyDataQuery + hir::db::InternCallableDefQuery + hir::db::InternLifetimeParamIdQuery + hir::db::InternImplTraitIdQuery + hir::db::InternTypeOrConstParamIdQuery + hir::db::InternClosureQuery + hir::db::InternGeneratorQuery hir::db::AssociatedTyDataQuery hir::db::TraitDatumQuery hir::db::StructDatumQuery hir::db::ImplDatumQuery hir::db::FnDefDatumQuery - hir::db::ReturnTypeImplTraitsQuery - hir::db::InternCallableDefQuery - hir::db::InternTypeOrConstParamIdQuery - hir::db::InternImplTraitIdQuery - hir::db::InternClosureQuery + hir::db::FnDefVarianceQuery + hir::db::AdtVarianceQuery hir::db::AssociatedTyValueQuery hir::db::TraitSolveQueryQuery - hir::db::InternTypeOrConstParamIdQuery + hir::db::ProgramClausesForChalkEnvQuery // SymbolsDatabase crate::symbol_index::ModuleSymbolsQuery @@ -153,8 +181,14 @@ impl RootDatabase { hir::db::InternConstQuery hir::db::InternStaticQuery hir::db::InternTraitQuery + hir::db::InternTraitAliasQuery hir::db::InternTypeAliasQuery hir::db::InternImplQuery + hir::db::InternExternBlockQuery + hir::db::InternBlockQuery + hir::db::InternMacro2Query + hir::db::InternProcMacroQuery + hir::db::InternMacroRulesQuery ]; acc.sort_by_key(|it| std::cmp::Reverse(it.1)); diff --git a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs index ed7f04fd8..4071c490b 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs @@ -9,7 +9,8 @@ use arrayvec::ArrayVec; use hir::{ Adt, AsAssocItem, AssocItem, BuiltinAttr, BuiltinType, Const, Crate, DeriveHelper, Field, Function, GenericParam, HasVisibility, Impl, ItemInNs, Label, Local, Macro, Module, ModuleDef, - Name, PathResolution, Semantics, Static, ToolModule, Trait, TypeAlias, Variant, Visibility, + Name, PathResolution, Semantics, Static, ToolModule, Trait, TraitAlias, TypeAlias, Variant, + Visibility, }; use stdx::impl_from; use syntax::{ @@ -31,6 +32,7 @@ pub enum Definition { Const(Const), Static(Static), Trait(Trait), + TraitAlias(TraitAlias), TypeAlias(TypeAlias), BuiltinType(BuiltinType), SelfType(Impl), @@ -64,6 +66,7 @@ impl Definition { Definition::Const(it) => it.module(db), Definition::Static(it) => it.module(db), Definition::Trait(it) => it.module(db), + Definition::TraitAlias(it) => it.module(db), Definition::TypeAlias(it) => it.module(db), Definition::Variant(it) => it.module(db), Definition::SelfType(it) => it.module(db), @@ -87,6 +90,7 @@ impl Definition { Definition::Const(it) => it.visibility(db), Definition::Static(it) => it.visibility(db), Definition::Trait(it) => it.visibility(db), + Definition::TraitAlias(it) => it.visibility(db), Definition::TypeAlias(it) => it.visibility(db), Definition::Variant(it) => it.visibility(db), Definition::BuiltinType(_) => Visibility::Public, @@ -113,6 +117,7 @@ impl Definition { Definition::Const(it) => it.name(db)?, Definition::Static(it) => it.name(db), Definition::Trait(it) => it.name(db), + Definition::TraitAlias(it) => it.name(db), Definition::TypeAlias(it) => it.name(db), Definition::BuiltinType(it) => it.name(), Definition::SelfType(_) => return None, @@ -300,6 +305,7 @@ impl NameClass { ast::Item::Module(it) => Definition::Module(sema.to_def(&it)?), ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?), ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?), + ast::Item::TraitAlias(it) => Definition::TraitAlias(sema.to_def(&it)?), ast::Item::TypeAlias(it) => Definition::TypeAlias(sema.to_def(&it)?), ast::Item::Enum(it) => Definition::Adt(hir::Adt::Enum(sema.to_def(&it)?)), ast::Item::Struct(it) => Definition::Adt(hir::Adt::Struct(sema.to_def(&it)?)), @@ -321,7 +327,7 @@ impl NameClass { let pat_parent = ident_pat.syntax().parent(); if let Some(record_pat_field) = pat_parent.and_then(ast::RecordPatField::cast) { if record_pat_field.name_ref().is_none() { - if let Some(field) = sema.resolve_record_pat_field(&record_pat_field) { + if let Some((field, _)) = sema.resolve_record_pat_field(&record_pat_field) { return Some(NameClass::PatFieldShorthand { local_def: local, field_ref: field, @@ -463,9 +469,12 @@ impl NameRefClass { match_ast! { match parent { ast::MethodCallExpr(method_call) => { - sema.resolve_method_call(&method_call) - .map(Definition::Function) - .map(NameRefClass::Definition) + sema.resolve_method_call_field_fallback(&method_call) + .map(|it| { + it.map_left(Definition::Function) + .map_right(Definition::Field) + .either(NameRefClass::Definition, NameRefClass::Definition) + }) }, ast::FieldExpr(field_expr) => { sema.resolve_field(&field_expr) @@ -474,6 +483,13 @@ impl NameRefClass { }, ast::RecordPatField(record_pat_field) => { sema.resolve_record_pat_field(&record_pat_field) + .map(|(field, ..)|field) + .map(Definition::Field) + .map(NameRefClass::Definition) + }, + ast::RecordExprField(record_expr_field) => { + sema.resolve_record_field(&record_expr_field) + .map(|(field, ..)|field) .map(Definition::Field) .map(NameRefClass::Definition) }, @@ -542,7 +558,7 @@ impl NameRefClass { } impl_from!( - Field, Module, Function, Adt, Variant, Const, Static, Trait, TypeAlias, BuiltinType, Local, + Field, Module, Function, Adt, Variant, Const, Static, Trait, TraitAlias, TypeAlias, BuiltinType, Local, GenericParam, Label, Macro for Definition ); @@ -599,6 +615,7 @@ impl From<ModuleDef> for Definition { ModuleDef::Const(it) => Definition::Const(it), ModuleDef::Static(it) => Definition::Static(it), ModuleDef::Trait(it) => Definition::Trait(it), + ModuleDef::TraitAlias(it) => Definition::TraitAlias(it), ModuleDef::TypeAlias(it) => Definition::TypeAlias(it), ModuleDef::Macro(it) => Definition::Macro(it), ModuleDef::BuiltinType(it) => Definition::BuiltinType(it), @@ -616,6 +633,7 @@ impl From<Definition> for Option<ItemInNs> { Definition::Const(it) => ModuleDef::Const(it), Definition::Static(it) => ModuleDef::Static(it), Definition::Trait(it) => ModuleDef::Trait(it), + Definition::TraitAlias(it) => ModuleDef::TraitAlias(it), Definition::TypeAlias(it) => ModuleDef::TypeAlias(it), Definition::BuiltinType(it) => ModuleDef::BuiltinType(it), _ => return None, diff --git a/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs b/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs index 6e56efe34..8e3b1eef1 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/helpers.rs @@ -2,8 +2,8 @@ use std::collections::VecDeque; -use base_db::FileId; -use hir::{ItemInNs, ModuleDef, Name, Semantics}; +use base_db::{FileId, SourceDatabaseExt}; +use hir::{Crate, ItemInNs, ModuleDef, Name, Semantics}; use syntax::{ ast::{self, make}, AstToken, SyntaxKind, SyntaxToken, TokenAtOffset, @@ -103,3 +103,9 @@ pub fn lint_eq_or_in_group(lint: &str, lint_is: &str) -> bool { false } } + +pub fn is_editable_crate(krate: Crate, db: &RootDatabase) -> bool { + let root_file = krate.root_file(db); + let source_root_id = db.file_source_root(root_file); + !db.source_root(source_root_id).is_library +} diff --git a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs index 994d48385..b26b0a908 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/imports/import_assets.rs @@ -528,7 +528,7 @@ fn trait_applicable_items( }, ) } else { - trait_candidate.receiver_ty.iterate_method_candidates( + trait_candidate.receiver_ty.iterate_method_candidates_with_traits( db, scope, &trait_candidates, diff --git a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs index 156bbb634..b1df11bf9 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/lib.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/lib.rs @@ -22,7 +22,7 @@ pub mod source_change; pub mod symbol_index; pub mod traits; pub mod ty_filter; -pub mod use_trivial_contructor; +pub mod use_trivial_constructor; pub mod imports { pub mod import_assets; @@ -50,7 +50,7 @@ use base_db::{ AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, }; use hir::{ - db::{AstDatabase, DefDatabase, HirDatabase}, + db::{DefDatabase, ExpandDatabase, HirDatabase}, symbols::FileSymbolKind, }; use stdx::hash::NoHashHashSet; @@ -68,7 +68,7 @@ pub type FxIndexMap<K, V> = #[salsa::database( base_db::SourceDatabaseExtStorage, base_db::SourceDatabaseStorage, - hir::db::AstDatabaseStorage, + hir::db::ExpandDatabaseStorage, hir::db::DefDatabaseStorage, hir::db::HirDatabaseStorage, hir::db::InternDatabaseStorage, @@ -95,8 +95,8 @@ impl fmt::Debug for RootDatabase { } } -impl Upcast<dyn AstDatabase> for RootDatabase { - fn upcast(&self) -> &(dyn AstDatabase + 'static) { +impl Upcast<dyn ExpandDatabase> for RootDatabase { + fn upcast(&self) -> &(dyn ExpandDatabase + 'static) { &*self } } @@ -191,6 +191,7 @@ pub enum SymbolKind { Struct, ToolModule, Trait, + TraitAlias, TypeAlias, TypeParam, Union, @@ -221,6 +222,7 @@ impl From<FileSymbolKind> for SymbolKind { FileSymbolKind::Static => SymbolKind::Static, FileSymbolKind::Struct => SymbolKind::Struct, FileSymbolKind::Trait => SymbolKind::Trait, + FileSymbolKind::TraitAlias => SymbolKind::TraitAlias, FileSymbolKind::TypeAlias => SymbolKind::TypeAlias, FileSymbolKind::Union => SymbolKind::Union, } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/rename.rs b/src/tools/rust-analyzer/crates/ide-db/src/rename.rs index 84d70b258..f710211c8 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/rename.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/rename.rs @@ -119,15 +119,9 @@ impl Definition { Definition::Const(it) => name_range(it, sema), Definition::Static(it) => name_range(it, sema), Definition::Trait(it) => name_range(it, sema), + Definition::TraitAlias(it) => name_range(it, sema), Definition::TypeAlias(it) => name_range(it, sema), - Definition::Local(local) => { - let src = local.source(sema.db); - let name = match &src.value { - Either::Left(bind_pat) => bind_pat.name()?, - Either::Right(_) => return None, - }; - src.with_value(name.syntax()).original_file_range_opt(sema.db) - } + Definition::Local(it) => name_range(it.primary_source(sema.db), sema), Definition::GenericParam(generic_param) => match generic_param { hir::GenericParam::LifetimeParam(lifetime_param) => { let src = lifetime_param.source(sema.db)?; @@ -301,13 +295,7 @@ fn rename_reference( source_change.insert_source_edit(file_id, edit); Ok(()) }; - match def { - Definition::Local(l) => l - .associated_locals(sema.db) - .iter() - .try_for_each(|&local| insert_def_edit(Definition::Local(local))), - def => insert_def_edit(def), - }?; + insert_def_edit(def)?; Ok(source_change) } @@ -470,59 +458,64 @@ fn source_edit_from_def( def: Definition, new_name: &str, ) -> Result<(FileId, TextEdit)> { - let FileRange { file_id, range } = def - .range_for_rename(sema) - .ok_or_else(|| format_err!("No identifier available to rename"))?; - let mut edit = TextEdit::builder(); if let Definition::Local(local) = def { - if let Either::Left(pat) = local.source(sema.db).value { - // special cases required for renaming fields/locals in Record patterns - if let Some(pat_field) = pat.syntax().parent().and_then(ast::RecordPatField::cast) { + let mut file_id = None; + for source in local.sources(sema.db) { + let source = source.source; + file_id = source.file_id.file_id(); + if let Either::Left(pat) = source.value { let name_range = pat.name().unwrap().syntax().text_range(); - if let Some(name_ref) = pat_field.name_ref() { - if new_name == name_ref.text() && pat.at_token().is_none() { - // Foo { field: ref mut local } -> Foo { ref mut field } - // ^^^^^^ delete this - // ^^^^^ replace this with `field` - cov_mark::hit!(test_rename_local_put_init_shorthand_pat); - edit.delete( - name_ref - .syntax() - .text_range() - .cover_offset(pat.syntax().text_range().start()), - ); - edit.replace(name_range, name_ref.text().to_string()); + // special cases required for renaming fields/locals in Record patterns + if let Some(pat_field) = pat.syntax().parent().and_then(ast::RecordPatField::cast) { + if let Some(name_ref) = pat_field.name_ref() { + if new_name == name_ref.text() && pat.at_token().is_none() { + // Foo { field: ref mut local } -> Foo { ref mut field } + // ^^^^^^ delete this + // ^^^^^ replace this with `field` + cov_mark::hit!(test_rename_local_put_init_shorthand_pat); + edit.delete( + name_ref + .syntax() + .text_range() + .cover_offset(pat.syntax().text_range().start()), + ); + edit.replace(name_range, name_ref.text().to_string()); + } else { + // Foo { field: ref mut local @ local 2} -> Foo { field: ref mut new_name @ local2 } + // Foo { field: ref mut local } -> Foo { field: ref mut new_name } + // ^^^^^ replace this with `new_name` + edit.replace(name_range, new_name.to_string()); + } } else { - // Foo { field: ref mut local @ local 2} -> Foo { field: ref mut new_name @ local2 } - // Foo { field: ref mut local } -> Foo { field: ref mut new_name } - // ^^^^^ replace this with `new_name` + // Foo { ref mut field } -> Foo { field: ref mut new_name } + // ^ insert `field: ` + // ^^^^^ replace this with `new_name` + edit.insert( + pat.syntax().text_range().start(), + format!("{}: ", pat_field.field_name().unwrap()), + ); edit.replace(name_range, new_name.to_string()); } } else { - // Foo { ref mut field } -> Foo { field: ref mut new_name } - // ^ insert `field: ` - // ^^^^^ replace this with `new_name` - edit.insert( - pat.syntax().text_range().start(), - format!("{}: ", pat_field.field_name().unwrap()), - ); edit.replace(name_range, new_name.to_string()); } } } + let Some(file_id) = file_id else { bail!("No file available to rename") }; + return Ok((file_id, edit.finish())); } - if edit.is_empty() { - let (range, new_name) = match def { - Definition::GenericParam(hir::GenericParam::LifetimeParam(_)) - | Definition::Label(_) => ( - TextRange::new(range.start() + syntax::TextSize::from(1), range.end()), - new_name.strip_prefix('\'').unwrap_or(new_name).to_owned(), - ), - _ => (range, new_name.to_owned()), - }; - edit.replace(range, new_name); - } + let FileRange { file_id, range } = def + .range_for_rename(sema) + .ok_or_else(|| format_err!("No identifier available to rename"))?; + let (range, new_name) = match def { + Definition::GenericParam(hir::GenericParam::LifetimeParam(_)) | Definition::Label(_) => ( + TextRange::new(range.start() + syntax::TextSize::from(1), range.end()), + new_name.strip_prefix('\'').unwrap_or(new_name).to_owned(), + ), + _ => (range, new_name.to_owned()), + }; + edit.replace(range, new_name); Ok((file_id, edit.finish())) } diff --git a/src/tools/rust-analyzer/crates/ide-db/src/search.rs b/src/tools/rust-analyzer/crates/ide-db/src/search.rs index c18a27f17..12f5e4e2a 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/search.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/search.rs @@ -244,14 +244,14 @@ impl Definition { DefWithBody::Variant(v) => v.source(db).map(|src| src.syntax().cloned()), }; return match def { - Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)), + Some(def) => SearchScope::file_range(def.as_ref().original_file_range_full(db)), None => SearchScope::single_file(file_id), }; } if let Definition::SelfType(impl_) = self { return match impl_.source(db).map(|src| src.syntax().cloned()) { - Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)), + Some(def) => SearchScope::file_range(def.as_ref().original_file_range_full(db)), None => SearchScope::single_file(file_id), }; } @@ -261,13 +261,14 @@ impl Definition { hir::GenericDef::Function(it) => it.source(db).map(|src| src.syntax().cloned()), hir::GenericDef::Adt(it) => it.source(db).map(|src| src.syntax().cloned()), hir::GenericDef::Trait(it) => it.source(db).map(|src| src.syntax().cloned()), + hir::GenericDef::TraitAlias(it) => it.source(db).map(|src| src.syntax().cloned()), hir::GenericDef::TypeAlias(it) => it.source(db).map(|src| src.syntax().cloned()), hir::GenericDef::Impl(it) => it.source(db).map(|src| src.syntax().cloned()), hir::GenericDef::Variant(it) => it.source(db).map(|src| src.syntax().cloned()), hir::GenericDef::Const(it) => it.source(db).map(|src| src.syntax().cloned()), }; return match def { - Some(def) => SearchScope::file_range(def.as_ref().original_file_range(db)), + Some(def) => SearchScope::file_range(def.as_ref().original_file_range_full(db)), None => SearchScope::single_file(file_id), }; } @@ -318,10 +319,6 @@ impl Definition { sema, scope: None, include_self_kw_refs: None, - local_repr: match self { - Definition::Local(local) => Some(local.representative(sema.db)), - _ => None, - }, search_self_mod: false, } } @@ -336,9 +333,6 @@ pub struct FindUsages<'a> { assoc_item_container: Option<hir::AssocItemContainer>, /// whether to search for the `Self` type of the definition include_self_kw_refs: Option<hir::Type>, - /// the local representative for the local definition we are searching for - /// (this is required for finding all local declarations in a or-pattern) - local_repr: Option<hir::Local>, /// whether to search for the `self` module search_self_mod: bool, } @@ -643,19 +637,6 @@ impl<'a> FindUsages<'a> { sink: &mut dyn FnMut(FileId, FileReference) -> bool, ) -> bool { match NameRefClass::classify(self.sema, name_ref) { - Some(NameRefClass::Definition(def @ Definition::Local(local))) - if matches!( - self.local_repr, Some(repr) if repr == local.representative(self.sema.db) - ) => - { - let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax()); - let reference = FileReference { - range, - name: ast::NameLike::NameRef(name_ref.clone()), - category: ReferenceCategory::new(&def, name_ref), - }; - sink(file_id, reference) - } Some(NameRefClass::Definition(def)) if self.def == def // is our def a trait assoc item? then we want to find all assoc items from trait impls of our trait @@ -700,14 +681,16 @@ impl<'a> FindUsages<'a> { } } Some(NameRefClass::FieldShorthand { local_ref: local, field_ref: field }) => { - let field = Definition::Field(field); let FileRange { file_id, range } = self.sema.original_range(name_ref.syntax()); + + let field = Definition::Field(field); + let local = Definition::Local(local); let access = match self.def { Definition::Field(_) if field == self.def => { ReferenceCategory::new(&field, name_ref) } - Definition::Local(_) if matches!(self.local_repr, Some(repr) if repr == local.representative(self.sema.db)) => { - ReferenceCategory::new(&Definition::Local(local), name_ref) + Definition::Local(_) if local == self.def => { + ReferenceCategory::new(&local, name_ref) } _ => return false, }; @@ -751,21 +734,6 @@ impl<'a> FindUsages<'a> { }; sink(file_id, reference) } - Some(NameClass::Definition(def @ Definition::Local(local))) if def != self.def => { - if matches!( - self.local_repr, - Some(repr) if local.representative(self.sema.db) == repr - ) { - let FileRange { file_id, range } = self.sema.original_range(name.syntax()); - let reference = FileReference { - range, - name: ast::NameLike::Name(name.clone()), - category: None, - }; - return sink(file_id, reference); - } - false - } Some(NameClass::Definition(def)) if def != self.def => { match (&self.assoc_item_container, self.def) { // for type aliases we always want to reference the trait def and all the trait impl counterparts diff --git a/src/tools/rust-analyzer/crates/ide-db/src/source_change.rs b/src/tools/rust-analyzer/crates/ide-db/src/source_change.rs index 8e338061d..936354f29 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/source_change.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/source_change.rs @@ -83,6 +83,14 @@ impl From<NoHashHashMap<FileId, TextEdit>> for SourceChange { } } +impl FromIterator<(FileId, TextEdit)> for SourceChange { + fn from_iter<T: IntoIterator<Item = (FileId, TextEdit)>>(iter: T) -> Self { + let mut this = SourceChange::default(); + this.extend(iter); + this + } +} + pub struct SourceChangeBuilder { pub edit: TextEditBuilder, pub file_id: FileId, diff --git a/src/tools/rust-analyzer/crates/ide-db/src/use_trivial_contructor.rs b/src/tools/rust-analyzer/crates/ide-db/src/use_trivial_constructor.rs index 39431bed3..39431bed3 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/use_trivial_contructor.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/use_trivial_constructor.rs |