fix: Only compute unstable paths on nightly toolchains for IDE features

This commit is contained in:
Lukas Wirth 2025-08-23 09:00:35 +02:00
parent 14872a5332
commit 685f156fa6
36 changed files with 144 additions and 101 deletions

View file

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

View file

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

View file

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