mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Auto merge of #17277 - Veykril:find-path-fixes, r=Veykril
fix: Various find path fixes Fixes https://github.com/rust-lang/rust-analyzer/issues/17271
This commit is contained in:
commit
6a16749eb0
33 changed files with 645 additions and 344 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,13 +1,12 @@
|
||||||
//! A map of all publicly exported items in a crate.
|
//! A map of all publicly exported items in a crate.
|
||||||
|
|
||||||
use std::{fmt, hash::BuildHasherDefault};
|
use std::fmt;
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use fst::{raw::IndexedValue, Automaton, Streamer};
|
use fst::{raw::IndexedValue, Automaton, Streamer};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use indexmap::IndexMap;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::{FxHashSet, FxHasher};
|
use rustc_hash::FxHashSet;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use stdx::{format_to, TupleExt};
|
use stdx::{format_to, TupleExt};
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
@ -17,7 +16,7 @@ use crate::{
|
||||||
item_scope::{ImportOrExternCrate, ItemInNs},
|
item_scope::{ImportOrExternCrate, ItemInNs},
|
||||||
nameres::DefMap,
|
nameres::DefMap,
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
AssocItemId, ModuleDefId, ModuleId, TraitId,
|
AssocItemId, FxIndexMap, ModuleDefId, ModuleId, TraitId,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Item import details stored in the `ImportMap`.
|
/// Item import details stored in the `ImportMap`.
|
||||||
|
@ -58,7 +57,6 @@ enum IsTraitAssocItem {
|
||||||
No,
|
No,
|
||||||
}
|
}
|
||||||
|
|
||||||
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<FxHasher>>;
|
|
||||||
type ImportMapIndex = FxIndexMap<ItemInNs, (SmallVec<[ImportInfo; 1]>, IsTraitAssocItem)>;
|
type ImportMapIndex = FxIndexMap<ItemInNs, (SmallVec<[ImportInfo; 1]>, IsTraitAssocItem)>;
|
||||||
|
|
||||||
impl ImportMap {
|
impl ImportMap {
|
||||||
|
|
|
@ -295,7 +295,7 @@ impl ItemScope {
|
||||||
pub(crate) fn names_of<T>(
|
pub(crate) fn names_of<T>(
|
||||||
&self,
|
&self,
|
||||||
item: ItemInNs,
|
item: ItemInNs,
|
||||||
mut cb: impl FnMut(&Name, Visibility, bool) -> Option<T>,
|
mut cb: impl FnMut(&Name, Visibility, /*declared*/ bool) -> Option<T>,
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
match item {
|
match item {
|
||||||
ItemInNs::Macros(def) => self
|
ItemInNs::Macros(def) => self
|
||||||
|
|
|
@ -106,6 +106,9 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type FxIndexMap<K, V> =
|
||||||
|
indexmap::IndexMap<K, V, std::hash::BuildHasherDefault<rustc_hash::FxHasher>>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ItemLoc<N: ItemTreeNode> {
|
pub struct ItemLoc<N: ItemTreeNode> {
|
||||||
pub container: ModuleId,
|
pub container: ModuleId,
|
||||||
|
@ -455,6 +458,26 @@ impl ModuleId {
|
||||||
pub fn is_block_module(self) -> bool {
|
pub fn is_block_module(self) -> bool {
|
||||||
self.block.is_some() && self.local_id == DefMap::ROOT
|
self.block.is_some() && self.local_id == DefMap::ROOT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_within_block(self) -> bool {
|
||||||
|
self.block.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_crate_root(&self) -> Option<CrateRootModuleId> {
|
||||||
|
if self.local_id == DefMap::ROOT && self.block.is_none() {
|
||||||
|
Some(CrateRootModuleId { krate: self.krate })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn derive_crate_root(&self) -> CrateRootModuleId {
|
||||||
|
CrateRootModuleId { krate: self.krate }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_crate_root(&self) -> bool {
|
||||||
|
self.local_id == DefMap::ROOT && self.block.is_none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<CrateRootModuleId> for ModuleId {
|
impl PartialEq<CrateRootModuleId> for ModuleId {
|
||||||
|
|
|
@ -81,7 +81,7 @@ use crate::{
|
||||||
per_ns::PerNs,
|
per_ns::PerNs,
|
||||||
visibility::{Visibility, VisibilityExplicitness},
|
visibility::{Visibility, VisibilityExplicitness},
|
||||||
AstId, BlockId, BlockLoc, CrateRootModuleId, EnumId, EnumVariantId, ExternCrateId, FunctionId,
|
AstId, BlockId, BlockLoc, CrateRootModuleId, EnumId, EnumVariantId, ExternCrateId, FunctionId,
|
||||||
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
|
FxIndexMap, LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PREDEFINED_TOOLS: &[SmolStr] = &[
|
const PREDEFINED_TOOLS: &[SmolStr] = &[
|
||||||
|
@ -137,7 +137,7 @@ pub struct DefMap {
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
struct DefMapCrateData {
|
struct DefMapCrateData {
|
||||||
/// The extern prelude which contains all root modules of external crates that are in scope.
|
/// The extern prelude which contains all root modules of external crates that are in scope.
|
||||||
extern_prelude: FxHashMap<Name, (CrateRootModuleId, Option<ExternCrateId>)>,
|
extern_prelude: FxIndexMap<Name, (CrateRootModuleId, Option<ExternCrateId>)>,
|
||||||
|
|
||||||
/// Side table for resolving derive helpers.
|
/// Side table for resolving derive helpers.
|
||||||
exported_derives: FxHashMap<MacroDefId, Box<[Name]>>,
|
exported_derives: FxHashMap<MacroDefId, Box<[Name]>>,
|
||||||
|
@ -163,7 +163,7 @@ struct DefMapCrateData {
|
||||||
impl DefMapCrateData {
|
impl DefMapCrateData {
|
||||||
fn new(edition: Edition) -> Self {
|
fn new(edition: Edition) -> Self {
|
||||||
Self {
|
Self {
|
||||||
extern_prelude: FxHashMap::default(),
|
extern_prelude: FxIndexMap::default(),
|
||||||
exported_derives: FxHashMap::default(),
|
exported_derives: FxHashMap::default(),
|
||||||
fn_proc_macro_mapping: FxHashMap::default(),
|
fn_proc_macro_mapping: FxHashMap::default(),
|
||||||
proc_macro_loading_error: None,
|
proc_macro_loading_error: None,
|
||||||
|
@ -586,7 +586,8 @@ impl DefMap {
|
||||||
|
|
||||||
pub(crate) fn extern_prelude(
|
pub(crate) fn extern_prelude(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Iterator<Item = (&Name, (CrateRootModuleId, Option<ExternCrateId>))> + '_ {
|
) -> impl DoubleEndedIterator<Item = (&Name, (CrateRootModuleId, Option<ExternCrateId>))> + '_
|
||||||
|
{
|
||||||
self.data.extern_prelude.iter().map(|(name, &def)| (name, def))
|
self.data.extern_prelude.iter().map(|(name, &def)| (name, def))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
//! Name resolution façade.
|
//! Name resolution façade.
|
||||||
use std::{fmt, hash::BuildHasherDefault, iter, mem};
|
use std::{fmt, iter, mem};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
name::{name, Name},
|
name::{name, Name},
|
||||||
MacroDefId,
|
MacroDefId,
|
||||||
};
|
};
|
||||||
use indexmap::IndexMap;
|
|
||||||
use intern::Interned;
|
use intern::Interned;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
@ -27,10 +26,10 @@ use crate::{
|
||||||
type_ref::LifetimeRef,
|
type_ref::LifetimeRef,
|
||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
AdtId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId,
|
AdtId, ConstId, ConstParamId, CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId,
|
||||||
ExternBlockId, ExternCrateId, FunctionId, GenericDefId, GenericParamId, HasModule, ImplId,
|
ExternBlockId, ExternCrateId, FunctionId, FxIndexMap, GenericDefId, GenericParamId, HasModule,
|
||||||
ItemContainerId, ItemTreeLoc, LifetimeParamId, LocalModuleId, Lookup, Macro2Id, MacroId,
|
ImplId, ItemContainerId, ItemTreeLoc, LifetimeParamId, LocalModuleId, Lookup, Macro2Id,
|
||||||
MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId, TraitId,
|
MacroId, MacroRulesId, ModuleDefId, ModuleId, ProcMacroId, StaticId, StructId, TraitAliasId,
|
||||||
TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId, VariantId,
|
TraitId, TypeAliasId, TypeOrConstParamId, TypeOwnerId, TypeParamId, UseId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -957,7 +956,6 @@ fn to_type_ns(per_ns: PerNs) -> Option<(TypeNs, Option<ImportOrExternCrate>)> {
|
||||||
Some((res, import))
|
Some((res, import))
|
||||||
}
|
}
|
||||||
|
|
||||||
type FxIndexMap<K, V> = IndexMap<K, V, BuildHasherDefault<rustc_hash::FxHasher>>;
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ScopeNames {
|
struct ScopeNames {
|
||||||
map: FxIndexMap<Name, SmallVec<[ScopeDef; 1]>>,
|
map: FxIndexMap<Name, SmallVec<[ScopeDef; 1]>>,
|
||||||
|
|
|
@ -13,7 +13,7 @@ use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
data::adt::VariantData,
|
data::adt::VariantData,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
find_path,
|
find_path::{self, PrefixKind},
|
||||||
generics::{TypeOrConstParamData, TypeParamProvenance},
|
generics::{TypeOrConstParamData, TypeParamProvenance},
|
||||||
item_scope::ItemInNs,
|
item_scope::ItemInNs,
|
||||||
lang_item::{LangItem, LangItemTarget},
|
lang_item::{LangItem, LangItemTarget},
|
||||||
|
@ -999,6 +999,8 @@ impl HirDisplay for Ty {
|
||||||
db.upcast(),
|
db.upcast(),
|
||||||
ItemInNs::Types((*def_id).into()),
|
ItemInNs::Types((*def_id).into()),
|
||||||
module_id,
|
module_id,
|
||||||
|
PrefixKind::Plain,
|
||||||
|
false,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -788,7 +788,7 @@ impl Module {
|
||||||
|
|
||||||
/// Finds a path that can be used to refer to the given item from within
|
/// Finds a path that can be used to refer to the given item from within
|
||||||
/// this module, if possible.
|
/// this module, if possible.
|
||||||
pub fn find_use_path(
|
pub fn find_path(
|
||||||
self,
|
self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item: impl Into<ItemInNs>,
|
item: impl Into<ItemInNs>,
|
||||||
|
@ -799,6 +799,8 @@ impl Module {
|
||||||
db,
|
db,
|
||||||
item.into().into(),
|
item.into().into(),
|
||||||
self.into(),
|
self.into(),
|
||||||
|
PrefixKind::Plain,
|
||||||
|
false,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
prefer_prelude,
|
prefer_prelude,
|
||||||
)
|
)
|
||||||
|
@ -806,7 +808,7 @@ impl Module {
|
||||||
|
|
||||||
/// Finds a path that can be used to refer to the given item from within
|
/// Finds a path that can be used to refer to the given item from within
|
||||||
/// this module, if possible. This is used for returning import paths for use-statements.
|
/// this module, if possible. This is used for returning import paths for use-statements.
|
||||||
pub fn find_use_path_prefixed(
|
pub fn find_use_path(
|
||||||
self,
|
self,
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
item: impl Into<ItemInNs>,
|
item: impl Into<ItemInNs>,
|
||||||
|
@ -814,11 +816,12 @@ impl Module {
|
||||||
prefer_no_std: bool,
|
prefer_no_std: bool,
|
||||||
prefer_prelude: bool,
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
hir_def::find_path::find_path_prefixed(
|
hir_def::find_path::find_path(
|
||||||
db,
|
db,
|
||||||
item.into().into(),
|
item.into().into(),
|
||||||
self.into(),
|
self.into(),
|
||||||
prefix_kind,
|
prefix_kind,
|
||||||
|
true,
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
prefer_prelude,
|
prefer_prelude,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! Type tree for term search
|
//! Type tree for term search
|
||||||
|
|
||||||
use hir_def::find_path::PrefixKind;
|
|
||||||
use hir_expand::mod_path::ModPath;
|
use hir_expand::mod_path::ModPath;
|
||||||
use hir_ty::{
|
use hir_ty::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
|
@ -21,28 +20,8 @@ fn mod_item_path(
|
||||||
prefer_prelude: bool,
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
let db = sema_scope.db;
|
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 m = sema_scope.module();
|
||||||
match name_hit_count {
|
m.find_path(db.upcast(), *def, prefer_no_std, prefer_prelude)
|
||||||
Some(0..=1) | None => m.find_use_path(db.upcast(), *def, prefer_no_std, prefer_prelude),
|
|
||||||
Some(_) => m.find_use_path_prefixed(
|
|
||||||
db.upcast(),
|
|
||||||
*def,
|
|
||||||
PrefixKind::ByCrate,
|
|
||||||
prefer_no_std,
|
|
||||||
prefer_prelude,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to get path to `ModuleDef` as string
|
/// Helper function to get path to `ModuleDef` as string
|
||||||
|
|
|
@ -462,7 +462,7 @@ fn build_pat(
|
||||||
) -> Option<ast::Pat> {
|
) -> Option<ast::Pat> {
|
||||||
match var {
|
match var {
|
||||||
ExtendedVariant::Variant(var) => {
|
ExtendedVariant::Variant(var) => {
|
||||||
let path = mod_path_to_ast(&module.find_use_path(
|
let path = mod_path_to_ast(&module.find_path(
|
||||||
db,
|
db,
|
||||||
ModuleDef::from(var),
|
ModuleDef::from(var),
|
||||||
prefer_no_std,
|
prefer_no_std,
|
||||||
|
|
|
@ -341,7 +341,7 @@ fn augment_references_with_imports(
|
||||||
|
|
||||||
let import_scope = ImportScope::find_insert_use_container(name.syntax(), &ctx.sema);
|
let import_scope = ImportScope::find_insert_use_container(name.syntax(), &ctx.sema);
|
||||||
let path = ref_module
|
let path = ref_module
|
||||||
.find_use_path_prefixed(
|
.find_use_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
ModuleDef::Module(*target_module),
|
ModuleDef::Module(*target_module),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
@ -1521,7 +1521,7 @@ mod foo {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
use crate::foo::Bool;
|
use foo::Bool;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
use foo::FOO;
|
use foo::FOO;
|
||||||
|
@ -1602,7 +1602,7 @@ pub mod bar {
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
use crate::foo::bar::Bool;
|
use foo::bar::Bool;
|
||||||
|
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod_path_to_ast(&module.find_use_path(
|
mod_path_to_ast(&module.find_path(
|
||||||
ctx.db(),
|
ctx.db(),
|
||||||
src_type_def,
|
src_type_def,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -201,7 +201,7 @@ fn augment_references_with_imports(
|
||||||
let import_scope =
|
let import_scope =
|
||||||
ImportScope::find_insert_use_container(new_name.syntax(), &ctx.sema);
|
ImportScope::find_insert_use_container(new_name.syntax(), &ctx.sema);
|
||||||
let path = ref_module
|
let path = ref_module
|
||||||
.find_use_path_prefixed(
|
.find_use_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
ModuleDef::Module(*target_module),
|
ModuleDef::Module(*target_module),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
@ -811,7 +811,7 @@ pub mod bar {
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
use crate::foo::bar::BarResult;
|
use foo::bar::BarResult;
|
||||||
|
|
||||||
mod foo;
|
mod foo;
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option<Str
|
||||||
let module = ctx.sema.scope(ident_pat.syntax())?.module();
|
let module = ctx.sema.scope(ident_pat.syntax())?.module();
|
||||||
let struct_def = hir::ModuleDef::from(struct_type);
|
let struct_def = hir::ModuleDef::from(struct_type);
|
||||||
let kind = struct_type.kind(ctx.db());
|
let kind = struct_type.kind(ctx.db());
|
||||||
let struct_def_path = module.find_use_path(
|
let struct_def_path = module.find_path(
|
||||||
ctx.db(),
|
ctx.db(),
|
||||||
struct_def,
|
struct_def,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -209,7 +209,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
||||||
FamousDefs(&ctx.sema, module.krate()).core_ops_ControlFlow();
|
FamousDefs(&ctx.sema, module.krate()).core_ops_ControlFlow();
|
||||||
|
|
||||||
if let Some(control_flow_enum) = control_flow_enum {
|
if let Some(control_flow_enum) = control_flow_enum {
|
||||||
let mod_path = module.find_use_path_prefixed(
|
let mod_path = module.find_use_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
ModuleDef::from(control_flow_enum),
|
ModuleDef::from(control_flow_enum),
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
|
|
@ -386,7 +386,7 @@ fn process_references(
|
||||||
let segment = builder.make_mut(segment);
|
let segment = builder.make_mut(segment);
|
||||||
let scope_node = builder.make_syntax_mut(scope_node);
|
let scope_node = builder.make_syntax_mut(scope_node);
|
||||||
if !visited_modules.contains(&module) {
|
if !visited_modules.contains(&module) {
|
||||||
let mod_path = module.find_use_path_prefixed(
|
let mod_path = module.find_use_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
*enum_module_def,
|
*enum_module_def,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
@ -881,7 +881,7 @@ fn another_fn() {
|
||||||
r#"use my_mod::my_other_mod::MyField;
|
r#"use my_mod::my_other_mod::MyField;
|
||||||
|
|
||||||
mod my_mod {
|
mod my_mod {
|
||||||
use self::my_other_mod::MyField;
|
use my_other_mod::MyField;
|
||||||
|
|
||||||
fn another_fn() {
|
fn another_fn() {
|
||||||
let m = my_other_mod::MyEnum::MyField(MyField(1, 1));
|
let m = my_other_mod::MyEnum::MyField(MyField(1, 1));
|
||||||
|
|
|
@ -58,7 +58,7 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
||||||
|
|
||||||
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
||||||
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
||||||
let trait_path = module.find_use_path(
|
let trait_path = module.find_path(
|
||||||
ctx.db(),
|
ctx.db(),
|
||||||
ModuleDef::Trait(trait_),
|
ModuleDef::Trait(trait_),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
@ -103,7 +103,7 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
|
||||||
|
|
||||||
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
||||||
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
||||||
let trait_path = module.find_use_path(
|
let trait_path = module.find_path(
|
||||||
ctx.db(),
|
ctx.db(),
|
||||||
ModuleDef::Trait(trait_),
|
ModuleDef::Trait(trait_),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
||||||
|
|
||||||
let item_in_ns = hir::ItemInNs::from(hir::ModuleDef::from(ty.as_adt()?));
|
let item_in_ns = hir::ItemInNs::from(hir::ModuleDef::from(ty.as_adt()?));
|
||||||
|
|
||||||
let type_path = current_module.find_use_path(
|
let type_path = current_module.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
||||||
let current_module = ctx.sema.scope(call.syntax())?.module();
|
let current_module = ctx.sema.scope(call.syntax())?.module();
|
||||||
let target_module_def = ModuleDef::from(resolved_call);
|
let target_module_def = ModuleDef::from(resolved_call);
|
||||||
let item_in_ns = ItemInNs::from(target_module_def);
|
let item_in_ns = ItemInNs::from(target_module_def);
|
||||||
let receiver_path = current_module.find_use_path(
|
let receiver_path = current_module.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub(crate) fn replace_derive_with_manual_impl(
|
||||||
})
|
})
|
||||||
.flat_map(|trait_| {
|
.flat_map(|trait_| {
|
||||||
current_module
|
current_module
|
||||||
.find_use_path(
|
.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
hir::ModuleDef::Trait(trait_),
|
hir::ModuleDef::Trait(trait_),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn replace_qualified_name_with_use(
|
||||||
);
|
);
|
||||||
let path_to_qualifier = starts_with_name_ref
|
let path_to_qualifier = starts_with_name_ref
|
||||||
.then(|| {
|
.then(|| {
|
||||||
ctx.sema.scope(path.syntax())?.module().find_use_path_prefixed(
|
ctx.sema.scope(path.syntax())?.module().find_use_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
module,
|
module,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
|
|
@ -633,7 +633,7 @@ fn enum_variants_with_paths(
|
||||||
}
|
}
|
||||||
|
|
||||||
for variant in variants {
|
for variant in variants {
|
||||||
if let Some(path) = ctx.module.find_use_path(
|
if let Some(path) = ctx.module.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(variant),
|
hir::ModuleDef::from(variant),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -171,7 +171,7 @@ pub(crate) fn complete_expr_path(
|
||||||
hir::Adt::Struct(strukt) => {
|
hir::Adt::Struct(strukt) => {
|
||||||
let path = ctx
|
let path = ctx
|
||||||
.module
|
.module
|
||||||
.find_use_path(
|
.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(strukt),
|
hir::ModuleDef::from(strukt),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
@ -194,7 +194,7 @@ pub(crate) fn complete_expr_path(
|
||||||
hir::Adt::Union(un) => {
|
hir::Adt::Union(un) => {
|
||||||
let path = ctx
|
let path = ctx
|
||||||
.module
|
.module
|
||||||
.find_use_path(
|
.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
hir::ModuleDef::from(un),
|
hir::ModuleDef::from(un),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn complete_postfix(
|
||||||
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop() {
|
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop() {
|
||||||
if receiver_ty.impls_trait(ctx.db, drop_trait, &[]) {
|
if receiver_ty.impls_trait(ctx.db, drop_trait, &[]) {
|
||||||
if let Some(drop_fn) = ctx.famous_defs().core_mem_drop() {
|
if let Some(drop_fn) = ctx.famous_defs().core_mem_drop() {
|
||||||
if let Some(path) = ctx.module.find_use_path(
|
if let Some(path) = ctx.module.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
ItemInNs::Values(drop_fn.into()),
|
ItemInNs::Values(drop_fn.into()),
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -260,7 +260,7 @@ pub fn resolve_completion_edits(
|
||||||
);
|
);
|
||||||
let import = items_with_name
|
let import = items_with_name
|
||||||
.filter_map(|candidate| {
|
.filter_map(|candidate| {
|
||||||
current_module.find_use_path_prefixed(
|
current_module.find_use_path(
|
||||||
db,
|
db,
|
||||||
candidate,
|
candidate,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
|
|
|
@ -333,7 +333,7 @@ pub(crate) fn render_expr(
|
||||||
});
|
});
|
||||||
for trait_ in expr.traits_used(ctx.db) {
|
for trait_ in expr.traits_used(ctx.db) {
|
||||||
let trait_item = hir::ItemInNs::from(hir::ModuleDef::from(trait_));
|
let trait_item = hir::ItemInNs::from(hir::ModuleDef::from(trait_));
|
||||||
let Some(path) = ctx.module.find_use_path(
|
let Some(path) = ctx.module.find_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
trait_item,
|
trait_item,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -174,7 +174,7 @@ fn import_edits(ctx: &CompletionContext<'_>, requires: &[GreenNode]) -> Option<V
|
||||||
hir::PathResolution::Def(def) => def.into(),
|
hir::PathResolution::Def(def) => def.into(),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let path = ctx.module.find_use_path_prefixed(
|
let path = ctx.module.find_use_path(
|
||||||
ctx.db,
|
ctx.db,
|
||||||
item,
|
item,
|
||||||
ctx.config.insert_use.prefix_kind,
|
ctx.config.insert_use.prefix_kind,
|
||||||
|
|
|
@ -638,7 +638,7 @@ fn get_mod_path(
|
||||||
prefer_prelude: bool,
|
prefer_prelude: bool,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
if let Some(prefix_kind) = prefixed {
|
if let Some(prefix_kind) = prefixed {
|
||||||
module_with_candidate.find_use_path_prefixed(
|
module_with_candidate.find_use_path(
|
||||||
db,
|
db,
|
||||||
item_to_search,
|
item_to_search,
|
||||||
prefix_kind,
|
prefix_kind,
|
||||||
|
@ -646,7 +646,7 @@ fn get_mod_path(
|
||||||
prefer_prelude,
|
prefer_prelude,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
module_with_candidate.find_use_path(db, item_to_search, prefer_no_std, prefer_prelude)
|
module_with_candidate.find_path(db, item_to_search, prefer_no_std, prefer_prelude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -308,7 +308,7 @@ impl Ctx<'_> {
|
||||||
parent.segment()?.name_ref()?,
|
parent.segment()?.name_ref()?,
|
||||||
)
|
)
|
||||||
.and_then(|trait_ref| {
|
.and_then(|trait_ref| {
|
||||||
let found_path = self.target_module.find_use_path(
|
let found_path = self.target_module.find_path(
|
||||||
self.source_scope.db.upcast(),
|
self.source_scope.db.upcast(),
|
||||||
hir::ModuleDef::Trait(trait_ref),
|
hir::ModuleDef::Trait(trait_ref),
|
||||||
false,
|
false,
|
||||||
|
@ -347,7 +347,7 @@ impl Ctx<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let found_path = self.target_module.find_use_path(
|
let found_path = self.target_module.find_path(
|
||||||
self.source_scope.db.upcast(),
|
self.source_scope.db.upcast(),
|
||||||
def,
|
def,
|
||||||
false,
|
false,
|
||||||
|
@ -385,7 +385,7 @@ impl Ctx<'_> {
|
||||||
|
|
||||||
if let Some(adt) = ty.as_adt() {
|
if let Some(adt) = ty.as_adt() {
|
||||||
if let ast::Type::PathType(path_ty) = &ast_ty {
|
if let ast::Type::PathType(path_ty) = &ast_ty {
|
||||||
let found_path = self.target_module.find_use_path(
|
let found_path = self.target_module.find_path(
|
||||||
self.source_scope.db.upcast(),
|
self.source_scope.db.upcast(),
|
||||||
ModuleDef::from(adt),
|
ModuleDef::from(adt),
|
||||||
false,
|
false,
|
||||||
|
|
|
@ -144,7 +144,7 @@ pub(crate) fn json_in_items(
|
||||||
let current_module = semantics_scope.module();
|
let current_module = semantics_scope.module();
|
||||||
if !scope_has("Serialize") {
|
if !scope_has("Serialize") {
|
||||||
if let Some(PathResolution::Def(it)) = serialize_resolved {
|
if let Some(PathResolution::Def(it)) = serialize_resolved {
|
||||||
if let Some(it) = current_module.find_use_path_prefixed(
|
if let Some(it) = current_module.find_use_path(
|
||||||
sema.db,
|
sema.db,
|
||||||
it,
|
it,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
|
@ -157,7 +157,7 @@ pub(crate) fn json_in_items(
|
||||||
}
|
}
|
||||||
if !scope_has("Deserialize") {
|
if !scope_has("Deserialize") {
|
||||||
if let Some(PathResolution::Def(it)) = deserialize_resolved {
|
if let Some(PathResolution::Def(it)) = deserialize_resolved {
|
||||||
if let Some(it) = current_module.find_use_path_prefixed(
|
if let Some(it) = current_module.find_use_path(
|
||||||
sema.db,
|
sema.db,
|
||||||
it,
|
it,
|
||||||
config.insert_use.prefix_kind,
|
config.insert_use.prefix_kind,
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
||||||
let expr = (|| -> Option<ast::Expr> {
|
let expr = (|| -> Option<ast::Expr> {
|
||||||
let item_in_ns = hir::ItemInNs::from(hir::ModuleDef::from(ty.as_adt()?));
|
let item_in_ns = hir::ItemInNs::from(hir::ModuleDef::from(ty.as_adt()?));
|
||||||
|
|
||||||
let type_path = current_module?.find_use_path(
|
let type_path = current_module?.find_path(
|
||||||
ctx.sema.db,
|
ctx.sema.db,
|
||||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||||
ctx.config.prefer_no_std,
|
ctx.config.prefer_no_std,
|
||||||
|
|
|
@ -368,6 +368,7 @@ fn main() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
#[test]
|
#[test]
|
||||||
fn local_shadow_fn() {
|
fn local_shadow_fn() {
|
||||||
check_fixes_unordered(
|
check_fixes_unordered(
|
||||||
|
@ -385,7 +386,7 @@ fn f() {
|
||||||
r#"
|
r#"
|
||||||
fn f() {
|
fn f() {
|
||||||
let f: i32 = 0;
|
let f: i32 = 0;
|
||||||
crate::f()
|
f()
|
||||||
}"#,
|
}"#,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -664,7 +664,7 @@ impl Match {
|
||||||
for (path, resolved_path) in &template.resolved_paths {
|
for (path, resolved_path) in &template.resolved_paths {
|
||||||
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
||||||
let mod_path =
|
let mod_path =
|
||||||
module.find_use_path(sema.db, module_def, false, true).ok_or_else(|| {
|
module.find_path(sema.db, module_def, false, true).ok_or_else(|| {
|
||||||
match_error!("Failed to render template path `{}` at match location")
|
match_error!("Failed to render template path `{}` at match location")
|
||||||
})?;
|
})?;
|
||||||
self.rendered_template_paths.insert(path.clone(), mod_path);
|
self.rendered_template_paths.insert(path.clone(), mod_path);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue