From b1830a5fe64d50cb819830400c51ccac558bbdf4 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 22 May 2024 14:28:07 +0200 Subject: [PATCH] Update assists test fixtures --- .../crates/hir/src/term_search/expr.rs | 18 +----------------- .../ide-assists/src/handlers/bool_to_enum.rs | 4 ++-- .../convert_tuple_return_type_to_struct.rs | 2 +- .../extract_struct_from_enum_variant.rs | 2 +- .../crates/ide-db/src/imports/import_assets.rs | 18 +++++++++++------- .../ide-diagnostics/src/handlers/typed_hole.rs | 3 ++- 6 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs b/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs index 45c0dd8da75fb..3cbe0d217c28a 100644 --- a/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs +++ b/src/tools/rust-analyzer/crates/hir/src/term_search/expr.rs @@ -1,6 +1,5 @@ //! Type tree for term search -use hir_def::find_path::PrefixKind; use hir_expand::mod_path::ModPath; use hir_ty::{ db::HirDatabase, @@ -21,23 +20,8 @@ fn mod_item_path( prefer_prelude: bool, ) -> Option { let db = sema_scope.db; - // Account for locals shadowing items from module - let name_hit_count = def.name(db).map(|def_name| { - let mut name_hit_count = 0; - sema_scope.process_all_names(&mut |name, _| { - if name == def_name { - name_hit_count += 1; - } - }); - name_hit_count - }); - let m = sema_scope.module(); - let prefix = match name_hit_count { - Some(0..=1) | None => PrefixKind::Plain, - Some(_) => PrefixKind::ByCrate, - }; - m.find_use_path(db.upcast(), *def, prefix, prefer_no_std, prefer_prelude) + m.find_path(db.upcast(), *def, prefer_no_std, prefer_prelude) } /// Helper function to get path to `ModuleDef` as string diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs index df87e2d044985..934d1f3b65bac 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs @@ -1521,7 +1521,7 @@ mod foo { } "#, r#" -use crate::foo::Bool; +use foo::Bool; fn main() { use foo::FOO; @@ -1602,7 +1602,7 @@ pub mod bar { "#, r#" //- /main.rs -use crate::foo::bar::Bool; +use foo::bar::Bool; mod foo; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs index 367cf0bc8b96d..1f579d4221b97 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs @@ -811,7 +811,7 @@ pub mod bar { "#, r#" //- /main.rs -use crate::foo::bar::BarResult; +use foo::bar::BarResult; mod foo; diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs index 24bda139b2cd0..2e4541b18119e 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs @@ -881,7 +881,7 @@ fn another_fn() { r#"use my_mod::my_other_mod::MyField; mod my_mod { - use self::my_other_mod::MyField; + use my_other_mod::MyField; fn another_fn() { let m = my_other_mod::MyEnum::MyField(MyField(1, 1)); 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 5e33b08e4a41c..530020f1168b4 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 @@ -637,13 +637,17 @@ fn get_mod_path( prefer_no_std: bool, prefer_prelude: bool, ) -> Option { - module_with_candidate.find_use_path( - db, - item_to_search, - prefixed.unwrap_or(PrefixKind::Plain), - prefer_no_std, - prefer_prelude, - ) + if let Some(prefix_kind) = prefixed { + module_with_candidate.find_use_path( + db, + item_to_search, + prefix_kind, + prefer_no_std, + prefer_prelude, + ) + } else { + module_with_candidate.find_path(db, item_to_search, prefer_no_std, prefer_prelude) + } } impl ImportCandidate { diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/typed_hole.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/typed_hole.rs index 656d79dc7324f..b819cc5b24954 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/typed_hole.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/typed_hole.rs @@ -368,6 +368,7 @@ fn main() { ); } + // FIXME #[test] fn local_shadow_fn() { check_fixes_unordered( @@ -385,7 +386,7 @@ fn f() { r#" fn f() { let f: i32 = 0; - crate::f() + f() }"#, ], );