Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-def/src/find_path.rs8
-rw-r--r--crates/hir-def/src/lib.rs2
-rw-r--r--crates/hir-ty/src/display.rs4
-rw-r--r--crates/hir/src/lib.rs6
-rw-r--r--crates/hir/src/semantics.rs7
-rw-r--r--crates/hir/src/term_search/expr.rs10
-rw-r--r--crates/ide-assists/src/assist_config.rs18
-rw-r--r--crates/ide-assists/src/handlers/add_missing_match_arms.rs7
-rw-r--r--crates/ide-assists/src/handlers/convert_bool_to_enum.rs37
-rw-r--r--crates/ide-assists/src/handlers/convert_into_to_from.rs2
-rw-r--r--crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs3
-rw-r--r--crates/ide-assists/src/handlers/destructure_struct_binding.rs3
-rw-r--r--crates/ide-assists/src/handlers/extract_function.rs3
-rw-r--r--crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs3
-rw-r--r--crates/ide-assists/src/handlers/generate_deref.rs8
-rw-r--r--crates/ide-assists/src/handlers/generate_new.rs3
-rw-r--r--crates/ide-assists/src/handlers/generate_single_field_struct_from.rs7
-rw-r--r--crates/ide-assists/src/handlers/qualify_method_call.rs3
-rw-r--r--crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs3
-rw-r--r--crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs9
-rw-r--r--crates/ide-assists/src/handlers/term_search.rs2
-rw-r--r--crates/ide-assists/src/handlers/toggle_async_sugar.rs7
-rw-r--r--crates/ide-completion/src/completions.rs2
-rw-r--r--crates/ide-completion/src/completions/expr.rs4
-rw-r--r--crates/ide-completion/src/completions/flyimport.rs6
-rw-r--r--crates/ide-completion/src/completions/postfix.rs2
-rw-r--r--crates/ide-completion/src/config.rs19
-rw-r--r--crates/ide-completion/src/render.rs2
-rw-r--r--crates/ide-completion/src/snippet.rs2
-rw-r--r--crates/ide-db/src/imports/import_assets.rs21
-rw-r--r--crates/ide-db/src/path_transform.rs10
-rw-r--r--crates/ide-diagnostics/src/handlers/json_is_not_rust.rs4
-rw-r--r--crates/ide-diagnostics/src/handlers/missing_fields.rs4
-rw-r--r--crates/ide-diagnostics/src/handlers/typed_hole.rs4
-rw-r--r--crates/ide-ssr/src/matching.rs4
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs6
36 files changed, 144 insertions, 101 deletions
diff --git a/crates/hir-def/src/find_path.rs b/crates/hir-def/src/find_path.rs
index faa0ef8cee..e8a6ebcffa 100644
--- a/crates/hir-def/src/find_path.rs
+++ b/crates/hir-def/src/find_path.rs
@@ -12,7 +12,7 @@ use intern::sym;
use rustc_hash::FxHashSet;
use crate::{
- ImportPathConfig, ModuleDefId, ModuleId,
+ FindPathConfig, ModuleDefId, ModuleId,
db::DefDatabase,
item_scope::ItemInNs,
nameres::DefMap,
@@ -27,7 +27,7 @@ pub fn find_path(
from: ModuleId,
mut prefix_kind: PrefixKind,
ignore_local_imports: bool,
- mut cfg: ImportPathConfig,
+ mut cfg: FindPathConfig,
) -> Option<ModPath> {
let _p = tracing::info_span!("find_path").entered();
@@ -96,7 +96,7 @@ impl PrefixKind {
struct FindPathCtx<'db> {
db: &'db dyn DefDatabase,
prefix: PrefixKind,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
ignore_local_imports: bool,
is_std_item: bool,
from: ModuleId,
@@ -718,7 +718,7 @@ mod tests {
module,
prefix,
ignore_local_imports,
- ImportPathConfig { prefer_no_std, prefer_prelude, prefer_absolute, allow_unstable },
+ FindPathConfig { prefer_no_std, prefer_prelude, prefer_absolute, allow_unstable },
);
format_to!(
res,
diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs
index 1f5b1e0237..301d4cca06 100644
--- a/crates/hir-def/src/lib.rs
+++ b/crates/hir-def/src/lib.rs
@@ -101,7 +101,7 @@ use crate::{
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, rustc_hash::FxBuildHasher>;
/// A wrapper around three booleans
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
-pub struct ImportPathConfig {
+pub struct FindPathConfig {
/// If true, prefer to unconditionally use imports of the `core` and `alloc` crate
/// over the std.
pub prefer_no_std: bool,
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index ae0113fcbd..f3691b2e4f 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -11,7 +11,7 @@ use base_db::Crate;
use chalk_ir::{BoundVar, Safety, TyKind};
use either::Either;
use hir_def::{
- GeneralConstId, GenericDefId, HasModule, ImportPathConfig, LocalFieldId, Lookup, ModuleDefId,
+ FindPathConfig, GeneralConstId, GenericDefId, HasModule, LocalFieldId, Lookup, ModuleDefId,
ModuleId, TraitId,
db::DefDatabase,
expr_store::{ExpressionStore, path::Path},
@@ -1433,7 +1433,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
PrefixKind::Plain,
false,
// FIXME: no_std Cfg?
- ImportPathConfig {
+ FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index f03f542e5b..4d1d8e2b15 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -130,7 +130,7 @@ pub use {
cfg::{CfgAtom, CfgExpr, CfgOptions},
hir_def::{
Complete,
- ImportPathConfig,
+ FindPathConfig,
attr::{AttrSourceMap, Attrs, AttrsWithOwner},
find_path::PrefixKind,
import_map,
@@ -957,7 +957,7 @@ impl Module {
self,
db: &dyn DefDatabase,
item: impl Into<ItemInNs>,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
) -> Option<ModPath> {
hir_def::find_path::find_path(
db,
@@ -976,7 +976,7 @@ impl Module {
db: &dyn DefDatabase,
item: impl Into<ItemInNs>,
prefix_kind: PrefixKind,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
) -> Option<ModPath> {
hir_def::find_path::find_path(db, item.into().into(), self.into(), prefix_kind, true, cfg)
}
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 6d6e08100b..84f01da72f 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -302,6 +302,13 @@ impl<DB: HirDatabase + ?Sized> Semantics<'_, DB> {
self.imp.hir_file_to_module_defs(file.into())
}
+ pub fn is_nightly(&self, krate: Crate) -> bool {
+ let toolchain = self.db.toolchain_channel(krate.into());
+ // `toolchain == None` means we're in some detached files. Since we have no information on
+ // the toolchain being used, let's just allow unstable items to be listed.
+ matches!(toolchain, Some(base_db::ReleaseChannel::Nightly) | None)
+ }
+
pub fn to_adt_def(&self, a: &ast::Adt) -> Option<Adt> {
self.imp.to_def(a)
}
diff --git a/crates/hir/src/term_search/expr.rs b/crates/hir/src/term_search/expr.rs
index 78f534d014..e56f9e91e3 100644
--- a/crates/hir/src/term_search/expr.rs
+++ b/crates/hir/src/term_search/expr.rs
@@ -1,6 +1,6 @@
//! Type tree for term search
-use hir_def::ImportPathConfig;
+use hir_def::FindPathConfig;
use hir_expand::mod_path::ModPath;
use hir_ty::{
db::HirDatabase,
@@ -18,7 +18,7 @@ use crate::{
fn mod_item_path(
sema_scope: &SemanticsScope<'_>,
def: &ModuleDef,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
) -> Option<ModPath> {
let db = sema_scope.db;
let m = sema_scope.module();
@@ -29,7 +29,7 @@ fn mod_item_path(
fn mod_item_path_str(
sema_scope: &SemanticsScope<'_>,
def: &ModuleDef,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
edition: Edition,
) -> Result<String, DisplaySourceCodeError> {
let path = mod_item_path(sema_scope, def, cfg);
@@ -103,7 +103,7 @@ impl<'db> Expr<'db> {
&self,
sema_scope: &SemanticsScope<'db>,
many_formatter: &mut dyn FnMut(&Type<'db>) -> String,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
display_target: DisplayTarget,
) -> Result<String, DisplaySourceCodeError> {
let db = sema_scope.db;
@@ -380,7 +380,7 @@ impl<'db> Expr<'db> {
fn container_name(
container: AssocItemContainer,
sema_scope: &SemanticsScope<'_>,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
edition: Edition,
display_target: DisplayTarget,
) -> Result<String, DisplaySourceCodeError> {
diff --git a/crates/ide-assists/src/assist_config.rs b/crates/ide-assists/src/assist_config.rs
index 57ced8d853..597d035ebd 100644
--- a/crates/ide-assists/src/assist_config.rs
+++ b/crates/ide-assists/src/assist_config.rs
@@ -4,8 +4,12 @@
//! module, and we use to statically check that we only produce snippet
//! assists if we are allowed to.
-use hir::ImportPathConfig;
-use ide_db::{SnippetCap, assists::ExprFillDefaultMode, imports::insert_use::InsertUseConfig};
+use hir::FindPathConfig;
+use ide_db::{
+ SnippetCap,
+ assists::ExprFillDefaultMode,
+ imports::{import_assets::ImportPathConfig, insert_use::InsertUseConfig},
+};
use crate::AssistKind;
@@ -31,7 +35,15 @@ impl AssistConfig {
prefer_no_std: self.prefer_no_std,
prefer_prelude: self.prefer_prelude,
prefer_absolute: self.prefer_absolute,
- allow_unstable: true,
+ }
+ }
+
+ pub fn find_path_confg(&self, allow_unstable: bool) -> FindPathConfig {
+ FindPathConfig {
+ prefer_no_std: self.prefer_no_std,
+ prefer_prelude: self.prefer_prelude,
+ prefer_absolute: self.prefer_absolute,
+ allow_unstable,
}
}
}
diff --git a/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/crates/ide-assists/src/handlers/add_missing_match_arms.rs
index 1ece7ddab1..4d3212c515 100644
--- a/crates/ide-assists/src/handlers/add_missing_match_arms.rs
+++ b/crates/ide-assists/src/handlers/add_missing_match_arms.rs
@@ -1,7 +1,7 @@
use std::iter::{self, Peekable};
use either::Either;
-use hir::{Adt, AsAssocItem, Crate, HasAttrs, ImportPathConfig, ModuleDef, Semantics, sym};
+use hir::{Adt, AsAssocItem, Crate, FindPathConfig, HasAttrs, ModuleDef, Semantics, sym};
use ide_db::RootDatabase;
use ide_db::assists::ExprFillDefaultMode;
use ide_db::syntax_helpers::suggest_name;
@@ -76,12 +76,11 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
.filter(|pat| !matches!(pat, Pat::WildcardPat(_)))
.collect();
- let cfg = ctx.config.import_path_config();
-
let make = SyntaxFactory::with_mappings();
let scope = ctx.sema.scope(expr.syntax())?;
let module = scope.module();
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(scope.krate()));
let self_ty = if ctx.config.prefer_self_ty {
scope
.containing_function()
@@ -498,7 +497,7 @@ fn build_pat(
make: &SyntaxFactory,
module: hir::Module,
var: ExtendedVariant,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
) -> Option<ast::Pat> {
let db = ctx.db();
match var {
diff --git a/crates/ide-assists/src/handlers/convert_bool_to_enum.rs b/crates/ide-assists/src/handlers/convert_bool_to_enum.rs
index c208c8bf78..80445578fc 100644
--- a/crates/ide-assists/src/handlers/convert_bool_to_enum.rs
+++ b/crates/ide-assists/src/handlers/convert_bool_to_enum.rs
@@ -329,8 +329,6 @@ fn augment_references_with_imports(
) -> Vec<FileReferenceWithImport> {
let mut visited_modules = FxHashSet::default();
- let cfg = ctx.config.import_path_config();
-
let edition = target_module.krate().edition(ctx.db());
references
.into_iter()
@@ -345,22 +343,27 @@ fn augment_references_with_imports(
{
visited_modules.insert(ref_module);
- let import_scope = ImportScope::find_insert_use_container(name.syntax(), &ctx.sema);
- let path = ref_module
- .find_use_path(
- ctx.sema.db,
- ModuleDef::Module(*target_module),
- ctx.config.insert_use.prefix_kind,
- cfg,
- )
- .map(|mod_path| {
- make::path_concat(
- mod_path_to_ast(&mod_path, edition),
- make::path_from_text("Bool"),
- )
- });
+ ImportScope::find_insert_use_container(name.syntax(), &ctx.sema).and_then(
+ |import_scope| {
+ let cfg =
+ ctx.config.find_path_confg(ctx.sema.is_nightly(target_module.krate()));
+ let path = ref_module
+ .find_use_path(
+ ctx.sema.db,
+ ModuleDef::Module(*target_module),
+ ctx.config.insert_use.prefix_kind,
+ cfg,
+ )
+ .map(|mod_path| {
+ make::path_concat(
+ mod_path_to_ast(&mod_path, edition),
+ make::path_from_text("Bool"),
+ )
+ })?;
- import_scope.zip(path)
+ Some((import_scope, path))
+ },
+ )
} else {
None
};
diff --git a/crates/ide-assists/src/handlers/convert_into_to_from.rs b/crates/ide-assists/src/handlers/convert_into_to_from.rs
index 3d9cde0e0a..3a464a3dc6 100644
--- a/crates/ide-assists/src/handlers/convert_into_to_from.rs
+++ b/crates/ide-assists/src/handlers/convert_into_to_from.rs
@@ -43,7 +43,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
return None;
}
- let cfg = ctx.config.import_path_config();
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let src_type_path = {
let src_type_path = src_type.syntax().descendants().find_map(ast::Path::cast)?;
diff --git a/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs b/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs
index 247c101158..80ffb4db3e 100644
--- a/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs
+++ b/crates/ide-assists/src/handlers/convert_tuple_return_type_to_struct.rs
@@ -184,8 +184,6 @@ fn augment_references_with_imports(
) -> Vec<(ast::NameLike, Option<(ImportScope, ast::Path)>)> {
let mut visited_modules = FxHashSet::default();
- let cfg = ctx.config.import_path_config();
-
references
.iter()
.filter_map(|FileReference { name, .. }| {
@@ -201,6 +199,7 @@ fn augment_references_with_imports(
{
visited_modules.insert(ref_module);
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(ref_module.krate()));
let import_scope =
ImportScope::find_insert_use_container(new_name.syntax(), &ctx.sema);
let path = ref_module
diff --git a/crates/ide-assists/src/handlers/destructure_struct_binding.rs b/crates/ide-assists/src/handlers/destructure_struct_binding.rs
index b8c647ac8b..397327cb4f 100644
--- a/crates/ide-assists/src/handlers/destructure_struct_binding.rs
+++ b/crates/ide-assists/src/handlers/destructure_struct_binding.rs
@@ -86,9 +86,8 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option<Str
let ty = ctx.sema.type_of_binding_in_pat(&ident_pat)?;
let hir::Adt::Struct(struct_type) = ty.strip_references().as_adt()? else { return None };
- let cfg = ctx.config.import_path_config();
-
let module = ctx.sema.scope(ident_pat.syntax())?.module();
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let struct_def = hir::ModuleDef::from(struct_type);
let kind = struct_type.kind(ctx.db());
let struct_def_path = module.find_path(ctx.db(), struct_def, cfg)?;
diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs
index d88e3311bd..e79ce567d3 100644
--- a/crates/ide-assists/src/handlers/extract_function.rs
+++ b/crates/ide-assists/src/handlers/extract_function.rs
@@ -209,11 +209,12 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
FamousDefs(&ctx.sema, module.krate()).core_ops_ControlFlow();
if let Some(control_flow_enum) = control_flow_enum {
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let mod_path = module.find_use_path(
ctx.sema.db,
ModuleDef::from(control_flow_enum),
ctx.config.insert_use.prefix_kind,
- ctx.config.import_path_config(),
+ cfg,
);
if let Some(mod_path) = mod_path {
diff --git a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
index c56d0b3de5..a5467e760b 100644
--- a/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide-assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -400,11 +400,12 @@ fn process_references(
let segment = builder.make_mut(segment);
let scope_node = builder.make_syntax_mut(scope_node);
if !visited_modules.contains(&module) {
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let mod_path = module.find_use_path(
ctx.sema.db,
*enum_module_def,
ctx.config.insert_use.prefix_kind,
- ctx.config.import_path_config(),
+ cfg,
);
if let Some(mut mod_path) = mod_path {
mod_path.pop_segment();
diff --git a/crates/ide-assists/src/handlers/generate_deref.rs b/crates/ide-assists/src/handlers/generate_deref.rs
index 55a09c5d77..a1fc2c6023 100644
--- a/crates/ide-assists/src/handlers/generate_deref.rs
+++ b/crates/ide-assists/src/handlers/generate_deref.rs
@@ -57,9 +57,9 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
};
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
- let trait_path =
- module.find_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.import_path_config())?;
+ let trait_path = module.find_path(ctx.db(), ModuleDef::Trait(trait_), cfg)?;
let field_type = field.ty()?;
let field_name = field.name()?;
@@ -99,9 +99,9 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
};
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
- let trait_path =
- module.find_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.import_path_config())?;
+ let trait_path = module.find_path(ctx.db(), ModuleDef::Trait(trait_), cfg)?;
let field_type = field.ty()?;
let target = field.syntax().text_range();
diff --git a/crates/ide-assists/src/handlers/generate_new.rs b/crates/ide-assists/src/handlers/generate_new.rs
index ac4a54a89e..9760fd62aa 100644
--- a/crates/ide-assists/src/handlers/generate_new.rs
+++ b/crates/ide-assists/src/handlers/generate_new.rs
@@ -77,10 +77,11 @@ 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 cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(current_module.krate()));
let type_path = current_module.find_path(
ctx.sema.db,
item_for_path_search(ctx.sema.db, item_in_ns)?,
- ctx.config.import_path_config(),
+ cfg,
)?;
let edition = current_module.krate().edition(ctx.db());
diff --git a/crates/ide-assists/src/handlers/generate_single_field_struct_from.rs b/crates/ide-assists/src/handlers/generate_single_field_struct_from.rs
index 943795d40d..cad14d9296 100644
--- a/crates/ide-assists/src/handlers/generate_single_field_struct_from.rs
+++ b/crates/ide-assists/src/handlers/generate_single_field_struct_from.rs
@@ -169,6 +169,7 @@ fn make_constructors(
types: &[ast::Type],
) -> Vec<Option<ast::Expr>> {
let (db, sema) = (ctx.db(), &ctx.sema);
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
types
.iter()
.map(|ty| {
@@ -179,11 +180,7 @@ fn make_constructors(
let item_in_ns = ModuleDef::Adt(ty.as_adt()?).into();
let edition = module.krate().edition(db);
- let ty_path = module.find_path(
- db,
- item_for_path_search(db, item_in_ns)?,
- ctx.config.import_path_config(),
- )?;
+ let ty_path = module.find_path(db, item_for_path_search(db, item_in_ns)?, cfg)?;
use_trivial_constructor(db, mod_path_to_ast(&ty_path, edition), &ty, edition)
})
diff --git a/crates/ide-assists/src/handlers/qualify_method_call.rs b/crates/ide-assists/src/handlers/qualify_method_call.rs
index 985121780b..e4494f0492 100644
--- a/crates/ide-assists/src/handlers/qualify_method_call.rs
+++ b/crates/ide-assists/src/handlers/qualify_method_call.rs
@@ -45,10 +45,11 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
let current_edition = current_module.krate().edition(ctx.db());
let target_module_def = ModuleDef::from(resolved_call);
let item_in_ns = ItemInNs::from(target_module_def);
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(current_module.krate()));
let receiver_path = current_module.find_path(
ctx.sema.db,
item_for_path_search(ctx.sema.db, item_in_ns)?,
- ctx.config.import_path_config(),
+ cfg,
)?;
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
diff --git a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
index 175f261317..25c5593007 100644
--- a/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
+++ b/crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
@@ -71,6 +71,7 @@ pub(crate) fn replace_derive_with_manual_impl(
let current_module = ctx.sema.scope(adt.syntax())?.module();
let current_crate = current_module.krate();
let current_edition = current_crate.edition(ctx.db());
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(current_crate));
let found_traits = items_locator::items_with_name(
ctx.db(),
@@ -84,7 +85,7 @@ pub(crate) fn replace_derive_with_manual_impl(
})
.flat_map(|trait_| {
current_module
- .find_path(ctx.sema.db, hir::ModuleDef::Trait(trait_), ctx.config.import_path_config())
+ .find_path(ctx.sema.db, hir::ModuleDef::Trait(trait_), cfg)
.as_ref()
.map(|path| mod_path_to_ast(path, current_edition))
.zip(Some(trait_))
diff --git a/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs
index 9f742131e5..5fc4d7a617 100644
--- a/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/ide-assists/src/handlers/replace_qualified_name_with_use.rs
@@ -63,12 +63,9 @@ pub(crate) fn replace_qualified_name_with_use(
);
let path_to_qualifier = starts_with_name_ref
.then(|| {
- ctx.sema.scope(original_path.syntax())?.module().find_use_path(
- ctx.sema.db,
- module,
- ctx.config.insert_use.prefix_kind,
- ctx.config.import_path_config(),
- )
+ let mod_ = ctx.sema.scope(original_path.syntax())?.module();
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(mod_.krate()));
+ mod_.find_use_path(ctx.sema.db, module, ctx.config.insert_use.prefix_kind, cfg)
})
.flatten();
diff --git a/crates/ide-assists/src/handlers/term_search.rs b/crates/ide-assists/src/handlers/term_search.rs
index 6527d3706e..209d3f08eb 100644
--- a/crates/ide-assists/src/handlers/term_search.rs
+++ b/crates/ide-assists/src/handlers/term_search.rs
@@ -55,7 +55,7 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
path.gen_source_code(
&scope,
&mut formatter,
- ctx.config.import_path_config(),
+ ctx.config.find_path_confg(ctx.sema.is_nightly(scope.module().krate())),
scope.krate().to_display_target(ctx.db()),
)
.ok()
diff --git a/crates/ide-assists/src/handlers/toggle_async_sugar.rs b/crates/ide-assists/src/handlers/toggle_async_sugar.rs
index eed070cb07..aed66d3d83 100644
--- a/crates/ide-assists/src/handlers/toggle_async_sugar.rs
+++ b/crates/ide-assists/src/handlers/toggle_async_sugar.rs
@@ -132,12 +132,9 @@ pub(crate) fn desugar_async_into_impl_future(
let scope = ctx.sema.scope(function.syntax())?;
let module = scope.module();
+ let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
let future_trait = FamousDefs(&ctx.sema, scope.krate()).core_future_Future()?;
- let trait_path = module.find_path(
- ctx.db(),
- ModuleDef::Trait(future_trait),
- ctx.config.import_path_config(),
- )?;
+ let trait_path = module.find_path(ctx.db(), ModuleDef::Trait(future_trait), cfg)?;
let edition = scope.krate().edition(ctx.db());
let trait_path = trait_path.display(ctx.db(), edition);
diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs
index 11d26228ba..e36e0e5704 100644
--- a/crates/ide-completion/src/completions.rs
+++ b/crates/ide-completion/src/completions.rs
@@ -654,7 +654,7 @@ fn enum_variants_with_paths(
if let Some(path) = ctx.module.find_path(
ctx.db,
hir::ModuleDef::from(variant),
- ctx.config.import_path_config(ctx.is_nightly),
+ ctx.config.find_path_config(ctx.is_nightly),
) {
// Variants with trivial paths are already added by the existing completion logic,
// so we should avoid adding these twice
diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs
index 1972f16613..a5b8a0b1ce 100644
--- a/crates/ide-completion/src/completions/expr.rs
+++ b/crates/ide-completion/src/completions/expr.rs
@@ -254,7 +254,7 @@ pub(crate) fn complete_expr_path(
.find_path(
ctx.db,
hir::ModuleDef::from(strukt),
- ctx.config.import_path_config(ctx.is_nightly),
+ ctx.config.find_path_config(ctx.is_nightly),
)
.filter(|it| it.len() > 1);
@@ -276,7 +276,7 @@ pub(crate) fn complete_expr_path(
.find_path(
ctx.db,
hir::ModuleDef::from(un),
- ctx.config.import_path_config(ctx.is_nightly),
+ ctx.config.find_path_config(ctx.is_nightly),
)
.filter(|it| it.len() > 1);
diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs
index dad8a76de8..d1e05a4359 100644
--- a/crates/ide-completion/src/completions/flyimport.rs
+++ b/crates/ide-completion/src/completions/flyimport.rs
@@ -257,7 +257,7 @@ fn import_on_the_fly(
};
let user_input_lowercased = potential_import_name.to_lowercase();
- let import_cfg = ctx.config.import_path_config(ctx.is_nightly);
+ let import_cfg = ctx.config.import_path_config();
import_assets
.search_for_imports(&ctx.sema, import_cfg, ctx.config.insert_use.prefix_kind)
@@ -304,7 +304,7 @@ fn import_on_the_fly_pat_(
ItemInNs::Values(def) => matches!(def, hir::ModuleDef::Const(_)),
};
let user_input_lowercased = potential_import_name.to_lowercase();
- let cfg = ctx.config.import_path_config(ctx.is_nightly);
+ let cfg = ctx.config.import_path_config();
import_assets
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
@@ -346,7 +346,7 @@ fn import_on_the_fly_method(
let user_input_lowercased = potential_import_name.to_lowercase();
- let cfg = ctx.config.import_path_config(ctx.is_nightly);
+ let cfg = ctx.config.import_path_config();
import_assets
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
diff --git a/crates/ide-completion/src/completions/postfix.rs b/crates/ide-completion/src/completions/postfix.rs
index 0058611a61..d355fdbe07 100644
--- a/crates/ide-completion/src/completions/postfix.rs
+++ b/crates/ide-completion/src/completions/postfix.rs
@@ -63,7 +63,7 @@ pub(crate) fn complete_postfix(
None => return,
};
- let cfg = ctx.config.import_path_config(ctx.is_nightly);
+ let cfg = ctx.config.find_path_config(ctx.is_nightly);
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop()
&& receiver_ty.impls_trait(ctx.db, drop_trait, &[])
diff --git a/crates/ide-completion/src/config.rs b/crates/ide-completion/src/config.rs
index 844fce5ef8..b7367cb62f 100644
--- a/crates/ide-completion/src/config.rs
+++ b/crates/ide-completion/src/config.rs
@@ -4,8 +4,11 @@
//! module, and we use to statically check that we only produce snippet
//! completions if we are allowed to.
-use hir::ImportPathConfig;
-use ide_db::{SnippetCap, imports::insert_use::InsertUseConfig};
+use hir::FindPathConfig;
+use ide_db::{
+ SnippetCap,
+ imports::{import_assets::ImportPathConfig, insert_use::InsertUseConfig},
+};
use crate::{CompletionFieldsToResolve, snippet::Snippet};
@@ -59,12 +62,20 @@ impl CompletionConfig<'_> {
.flat_map(|snip| snip.prefix_triggers.iter().map(move |trigger| (&**trigger, snip)))
}
- pub fn import_path_config(&self, allow_unstable: bool) -> ImportPathConfig {
- ImportPathConfig {
+ pub fn find_path_config(&self, allow_unstable: bool) -> FindPathConfig {
+ FindPathConfig {
prefer_no_std: self.prefer_no_std,
prefer_prelude: self.prefer_prelude,
prefer_absolute: self.prefer_absolute,
allow_unstable,
}
}
+
+ pub fn import_path_config(&self) -> ImportPathConfig {
+ ImportPathConfig {
+ prefer_no_std: self.prefer_no_std,
+ prefer_prelude: self.prefer_prelude,
+ prefer_absolute: self.prefer_absolute,
+ }
+ }
}
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 7d23f9d14c..dbf68dbe33 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -299,7 +299,7 @@ pub(crate) fn render_expr(
.unwrap_or_else(|| String::from("..."))
};
- let cfg = ctx.config.import_path_config(ctx.is_nightly);
+ let cfg = ctx.config.find_path_config(ctx.is_nightly);
let label =
expr.gen_source_code(&ctx.scope, &mut label_formatter, cfg, ctx.display_target).ok()?;
diff --git a/crates/ide-completion/src/snippet.rs b/crates/ide-completion/src/snippet.rs
index 9dc0c0234d..d326098f94 100644
--- a/crates/ide-completion/src/snippet.rs
+++ b/crates/ide-completion/src/snippet.rs
@@ -164,7 +164,7 @@ impl Snippet {
}
fn import_edits(ctx: &CompletionContext<'_>, requires: &[ModPath]) -> Option<Vec<LocatedImport>> {
- let import_cfg = ctx.config.import_path_config(ctx.is_nightly);
+ let import_cfg = ctx.config.find_path_config(ctx.is_nightly);
let resolve = |import| {
let item = ctx.scope.resolve_mod_path(import).next()?;
diff --git a/crates/ide-db/src/imports/import_assets.rs b/crates/ide-db/src/imports/import_assets.rs
index 1012f99334..0c235c8d9a 100644
--- a/crates/ide-db/src/imports/import_assets.rs
+++ b/crates/ide-db/src/imports/import_assets.rs
@@ -3,7 +3,7 @@
use std::ops::ControlFlow;
use hir::{
- AsAssocItem, AssocItem, AssocItemContainer, Complete, Crate, HasCrate, ImportPathConfig,
+ AsAssocItem, AssocItem, AssocItemContainer, Complete, Crate, FindPathConfig, HasCrate,
ItemInNs, ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics,
SemanticsScope, Trait, TyFingerprint, Type, db::HirDatabase,
};
@@ -19,6 +19,17 @@ use crate::{
items_locator::{self, AssocSearchMode, DEFAULT_QUERY_SEARCH_LIMIT},
};
+#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
+pub struct ImportPathConfig {
+ /// If true, prefer to unconditionally use imports of the `core` and `alloc` crate
+ /// over the std.
+ pub prefer_no_std: bool,
+ /// If true, prefer import paths containing a prelude module.
+ pub prefer_prelude: bool,
+ /// If true, prefer abs path (starting with `::`) where it is available.
+ pub prefer_absolute: bool,
+}
+
/// A candidate for import, derived during various IDE activities:
/// * completion with imports on the fly proposals
/// * completion edit resolve requests
@@ -296,6 +307,12 @@ impl<'db> ImportAssets<'db> {
Some(it) => it,
None => return <FxIndexSet<_>>::default().into_iter(),
};
+ let cfg = FindPathConfig {
+ prefer_no_std: cfg.prefer_no_std,
+ prefer_prelude: cfg.prefer_prelude,
+ prefer_absolute: cfg.prefer_absolute,
+ allow_unstable: sema.is_nightly(scope.krate()),
+ };
let db = sema.db;
let krate = self.module_with_candidate.krate();
let scope_definitions = self.scope_definitions(sema);
@@ -698,7 +715,7 @@ fn get_mod_path(
item_to_search: ItemInNs,
module_with_candidate: &Module,
prefixed: Option<PrefixKind>,
- cfg: ImportPathConfig,
+ cfg: FindPathConfig,
) -> Option<ModPath> {
if let Some(prefix_kind) = prefixed {
module_with_candidate.find_use_path(db, item_to_search, prefix_kind, cfg)
diff --git a/crates/ide-db/src/path_transform.rs b/crates/ide-db/src/path_transform.rs
index a76a0551dd..4a27035afd 100644
--- a/crates/ide-db/src/path_transform.rs
+++ b/crates/ide-db/src/path_transform.rs
@@ -3,7 +3,7 @@
use crate::helpers::mod_path_to_ast;
use either::Either;
use hir::{
- AsAssocItem, HirDisplay, HirFileId, ImportPathConfig, ModuleDef, SemanticsScope,
+ AsAssocItem, FindPathConfig, HirDisplay, HirFileId, ModuleDef, SemanticsScope,
prettify_macro_expansion,
};
use itertools::Itertools;
@@ -392,7 +392,7 @@ impl Ctx<'_> {
parent.segment()?.name_ref()?,
)
.and_then(|trait_ref| {
- let cfg = ImportPathConfig {
+ let cfg = FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
@@ -452,7 +452,7 @@ impl Ctx<'_> {
return None;
}
- let cfg = ImportPathConfig {
+ let cfg = FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
@@ -501,7 +501,7 @@ impl Ctx<'_> {
if let Some(adt) = ty.as_adt()
&& let ast::Type::PathType(path_ty) = &ast_ty
{
- let cfg = ImportPathConfig {
+ let cfg = FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
@@ -546,7 +546,7 @@ impl Ctx<'_> {
match resolution {
hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => {
- let cfg = ImportPathConfig {
+ let cfg = FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
diff --git a/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs b/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs
index 742d614bc5..2dfc2bb565 100644
--- a/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs
+++ b/crates/ide-diagnostics/src/handlers/json_is_not_rust.rs
@@ -1,7 +1,7 @@
//! This diagnostic provides an assist for creating a struct definition from a JSON
//! example.
-use hir::{ImportPathConfig, PathResolution, Semantics};
+use hir::{FindPathConfig, PathResolution, Semantics};
use ide_db::text_edit::TextEdit;
use ide_db::{
EditionedFileId, FileRange, FxHashMap, RootDatabase,
@@ -141,7 +141,7 @@ pub(crate) fn json_in_items(
let scope = scb.make_import_scope_mut(import_scope);
let current_module = semantics_scope.module();
- let cfg = ImportPathConfig {
+ let cfg = FindPathConfig {
prefer_no_std: config.prefer_no_std,
prefer_prelude: config.prefer_prelude,
prefer_absolute: config.prefer_absolute,
diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs
index 893bfca6a1..49f925e2e0 100644
--- a/crates/ide-diagnostics/src/handlers/missing_fields.rs
+++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs
@@ -1,6 +1,6 @@
use either::Either;
use hir::{
- AssocItem, HirDisplay, ImportPathConfig, InFile, Type,
+ AssocItem, FindPathConfig, HirDisplay, InFile, Type,
db::{ExpandDatabase, HirDatabase},
sym,
};
@@ -132,7 +132,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
let type_path = current_module?.find_path(
ctx.sema.db,
item_for_path_search(ctx.sema.db, item_in_ns)?,
- ImportPathConfig {
+ FindPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
diff --git a/crates/ide-diagnostics/src/handlers/typed_hole.rs b/crates/ide-diagnostics/src/handlers/typed_hole.rs
index 8d42770269..c29e525cec 100644
--- a/crates/ide-diagnostics/src/handlers/typed_hole.rs
+++ b/crates/ide-diagnostics/src/handlers/typed_hole.rs
@@ -1,7 +1,7 @@
use std::ops::Not;
use hir::{
- ClosureStyle, HirDisplay, ImportPathConfig,
+ ClosureStyle, FindPathConfig, HirDisplay,
db::ExpandDatabase,
term_search::{TermSearchConfig, TermSearchCtx, term_search},
};
@@ -73,7 +73,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole<'_>) -> Option<Vec<Ass
path.gen_source_code(
&scope,
&mut formatter,
- ImportPathConfig {
+ FindPathConfig {
prefer_no_std: ctx.config.prefer_no_std,
prefer_prelude: ctx.config.prefer_prelude,
prefer_absolute: ctx.config.prefer_absolute,
diff --git a/crates/ide-ssr/src/matching.rs b/crates/ide-ssr/src/matching.rs
index f21132c297..595f0bb5fa 100644
--- a/crates/ide-ssr/src/matching.rs
+++ b/crates/ide-ssr/src/matching.rs
@@ -6,7 +6,7 @@ use crate::{
parsing::{Constraint, NodeKind, Placeholder, Var},
resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo},
};
-use hir::{FileRange, ImportPathConfig, Semantics};
+use hir::{FileRange, FindPathConfig, Semantics};
use ide_db::{FxHashMap, base_db::RootQueryDb};
use std::{cell::Cell, iter::Peekable};
use syntax::{
@@ -661,7 +661,7 @@ impl Match {
.module();
for (path, resolved_path) in &template.resolved_paths {
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
- let cfg = ImportPathConfig {
+ let cfg = FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 6c0aa19f57..17bf504bc1 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -10,8 +10,8 @@ use std::{
use cfg::{CfgAtom, CfgDiff};
use hir::{
- Adt, AssocItem, Crate, DefWithBody, HasCrate, HasSource, HirDisplay, ImportPathConfig,
- ModuleDef, Name,
+ Adt, AssocItem, Crate, DefWithBody, FindPathConfig, HasCrate, HasSource, HirDisplay, ModuleDef,
+ Name,
db::{DefDatabase, ExpandDatabase, HirDatabase},
next_solver::{DbInterner, GenericArgs},
};
@@ -538,7 +538,7 @@ impl flags::AnalysisStats {
.gen_source_code(
&scope,
&mut formatter,
- ImportPathConfig {
+ FindPathConfig {
prefer_no_std: false,
prefer_prelude: true,
prefer_absolute: false,