mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
Auto merge of #16612 - Veykril:detached-files, r=Veykril
internal: Fetch toolchain and datalayout for DetachedFiles My changes broke the rustc test runs since we use detached files for that, this should fix that. Also addresses some new nightly warnings wrt to unnecessary imports
This commit is contained in:
commit
26a16c4d9b
29 changed files with 164 additions and 80 deletions
|
@ -6,8 +6,8 @@ use itertools::Itertools;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
hir::{
|
hir::{
|
||||||
Array, BindingAnnotation, BindingId, CaptureBy, ClosureKind, Literal, LiteralOrConst,
|
Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability,
|
||||||
Movability, Statement,
|
Statement,
|
||||||
},
|
},
|
||||||
pretty::{print_generic_args, print_path, print_type_ref},
|
pretty::{print_generic_args, print_path, print_type_ref},
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use std::{fmt, hash::BuildHasherDefault};
|
use std::{fmt, hash::BuildHasherDefault};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use fst::{self, raw::IndexedValue, Automaton, Streamer};
|
use fst::{raw::IndexedValue, Automaton, Streamer};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -477,7 +477,7 @@ mod tests {
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
|
|
||||||
use crate::{db::DefDatabase, test_db::TestDB, ItemContainerId, Lookup};
|
use crate::{test_db::TestDB, ItemContainerId, Lookup};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -44,13 +44,13 @@ use std::{
|
||||||
ops::{Index, Range},
|
ops::{Index, Range},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ast::{AstNode, HasName, StructKind};
|
use ast::{AstNode, StructKind};
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
ast_id_map::{AstIdNode, FileAstId},
|
ast_id_map::{AstIdNode, FileAstId},
|
||||||
attrs::RawAttrs,
|
attrs::RawAttrs,
|
||||||
name::{name, AsName, Name},
|
name::Name,
|
||||||
ExpandTo, HirFileId, InFile,
|
ExpandTo, HirFileId, InFile,
|
||||||
};
|
};
|
||||||
use intern::Interned;
|
use intern::Interned;
|
||||||
|
@ -67,7 +67,7 @@ use crate::{
|
||||||
attr::Attrs,
|
attr::Attrs,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
generics::{GenericParams, LifetimeParamData, TypeOrConstParamData},
|
generics::{GenericParams, LifetimeParamData, TypeOrConstParamData},
|
||||||
path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
|
path::{GenericArgs, ImportAlias, ModPath, Path, PathKind},
|
||||||
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
|
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
|
||||||
visibility::{RawVisibility, VisibilityExplicitness},
|
visibility::{RawVisibility, VisibilityExplicitness},
|
||||||
BlockId, Lookup,
|
BlockId, Lookup,
|
||||||
|
|
|
@ -2,17 +2,33 @@
|
||||||
|
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
use hir_expand::{ast_id_map::AstIdMap, span_map::SpanMapRef, HirFileId};
|
use hir_expand::{
|
||||||
use syntax::ast::{self, HasModuleItem, HasTypeBounds, IsString};
|
ast_id_map::AstIdMap, mod_path::path, name, name::AsName, span_map::SpanMapRef, HirFileId,
|
||||||
|
};
|
||||||
|
use la_arena::Arena;
|
||||||
|
use syntax::{
|
||||||
|
ast::{self, HasModuleItem, HasName, HasTypeBounds, IsString},
|
||||||
|
AstNode,
|
||||||
|
};
|
||||||
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
db::DefDatabase,
|
||||||
generics::{GenericParams, GenericParamsCollector, TypeParamData, TypeParamProvenance},
|
generics::{GenericParams, GenericParamsCollector, TypeParamData, TypeParamProvenance},
|
||||||
type_ref::{LifetimeRef, TraitBoundModifier, TraitRef},
|
item_tree::{
|
||||||
|
AssocItem, AttrOwner, Const, Either, Enum, ExternBlock, ExternCrate, Field, FieldAstId,
|
||||||
|
Fields, FileItemTreeId, FnFlags, Function, GenericArgs, Idx, IdxRange, Impl, ImportAlias,
|
||||||
|
Interned, ItemTree, ItemTreeData, ItemTreeNode, Macro2, MacroCall, MacroRules, Mod,
|
||||||
|
ModItem, ModKind, ModPath, Mutability, Name, Param, ParamAstId, Path, Range, RawAttrs,
|
||||||
|
RawIdx, RawVisibilityId, Static, Struct, StructKind, Trait, TraitAlias, TypeAlias, Union,
|
||||||
|
Use, UseTree, UseTreeKind, Variant,
|
||||||
|
},
|
||||||
|
path::AssociatedTypeBinding,
|
||||||
|
type_ref::{LifetimeRef, TraitBoundModifier, TraitRef, TypeBound, TypeRef},
|
||||||
|
visibility::RawVisibility,
|
||||||
LocalLifetimeParamId, LocalTypeOrConstParamId,
|
LocalLifetimeParamId, LocalTypeOrConstParamId,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
|
fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
|
||||||
FileItemTreeId(index)
|
FileItemTreeId(index)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,17 @@ use span::ErasedFileAstId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
generics::{TypeOrConstParamData, WherePredicate, WherePredicateTypeTarget},
|
generics::{TypeOrConstParamData, WherePredicate, WherePredicateTypeTarget},
|
||||||
|
item_tree::{
|
||||||
|
AttrOwner, Const, DefDatabase, Enum, ExternBlock, ExternCrate, Field, FieldAstId, Fields,
|
||||||
|
FileItemTreeId, FnFlags, Function, GenericParams, Impl, Interned, ItemTree, Macro2,
|
||||||
|
MacroCall, MacroRules, Mod, ModItem, ModKind, Param, ParamAstId, Path, RawAttrs,
|
||||||
|
RawVisibilityId, Static, Struct, Trait, TraitAlias, TypeAlias, TypeBound, TypeRef, Union,
|
||||||
|
Use, UseTree, UseTreeKind, Variant,
|
||||||
|
},
|
||||||
pretty::{print_path, print_type_bounds, print_type_ref},
|
pretty::{print_path, print_type_bounds, print_type_ref},
|
||||||
visibility::RawVisibility,
|
visibility::RawVisibility,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
pub(super) fn print_item_tree(db: &dyn DefDatabase, tree: &ItemTree) -> String {
|
pub(super) fn print_item_tree(db: &dyn DefDatabase, tree: &ItemTree) -> String {
|
||||||
let mut p = Printer { db, tree, buf: String::new(), indent_level: 0, needs_indent: true };
|
let mut p = Printer { db, tree, buf: String::new(), indent_level: 0, needs_indent: true };
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub mod proc_macro;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use std::{cmp::Ord, ops::Deref};
|
use std::ops::Deref;
|
||||||
|
|
||||||
use base_db::{CrateId, Edition, FileId};
|
use base_db::{CrateId, Edition, FileId};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
|
|
|
@ -2446,7 +2446,7 @@ mod tests {
|
||||||
use base_db::SourceDatabase;
|
use base_db::SourceDatabase;
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
|
|
||||||
use crate::{db::DefDatabase, test_db::TestDB};
|
use crate::test_db::TestDB;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use expect_test::expect;
|
use expect_test::expect;
|
||||||
use test_fixture::WithFixture;
|
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::nameres::tests::check;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//!
|
//!
|
||||||
//! Originates from `rustc_hir::pat_util`
|
//! Originates from `rustc_hir::pat_util`
|
||||||
|
|
||||||
use std::iter::{Enumerate, ExactSizeIterator};
|
use std::iter::Enumerate;
|
||||||
|
|
||||||
pub(crate) struct EnumerateAndAdjust<I> {
|
pub(crate) struct EnumerateAndAdjust<I> {
|
||||||
enumerate: Enumerate<I>,
|
enumerate: Enumerate<I>,
|
||||||
|
|
|
@ -8,9 +8,13 @@ use hir_def::{
|
||||||
builtin_type::{BuiltinInt, BuiltinUint},
|
builtin_type::{BuiltinInt, BuiltinUint},
|
||||||
resolver::HasResolver,
|
resolver::HasResolver,
|
||||||
};
|
};
|
||||||
use hir_expand::mod_path::ModPath;
|
|
||||||
|
|
||||||
use super::*;
|
use crate::mir::eval::{
|
||||||
|
name, pad16, static_lifetime, Address, AdtId, Arc, BuiltinType, Evaluator, FunctionId,
|
||||||
|
HasModule, HirDisplay, Interned, InternedClosure, Interner, Interval, IntervalAndTy,
|
||||||
|
IntervalOrOwned, ItemContainerId, LangItem, Layout, Locals, Lookup, MirEvalError, MirSpan,
|
||||||
|
ModPath, Mutability, Result, Substitution, Ty, TyBuilder, TyExt,
|
||||||
|
};
|
||||||
|
|
||||||
mod simd;
|
mod simd;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
use crate::consteval::try_const_usize;
|
||||||
use crate::TyKind;
|
use crate::TyKind;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -31,14 +31,20 @@ use crate::{
|
||||||
inhabitedness::is_ty_uninhabited_from,
|
inhabitedness::is_ty_uninhabited_from,
|
||||||
layout::LayoutError,
|
layout::LayoutError,
|
||||||
mapping::ToChalk,
|
mapping::ToChalk,
|
||||||
|
mir::{
|
||||||
|
intern_const_scalar, return_slot, AggregateKind, Arena, BasicBlock, BasicBlockId, BinOp,
|
||||||
|
BorrowKind, CastKind, ClosureId, ConstScalar, Either, Expr, FieldId, Idx, InferenceResult,
|
||||||
|
Interner, Local, LocalId, MemoryMap, MirBody, MirSpan, Mutability, Operand, Place,
|
||||||
|
PlaceElem, PointerCast, ProjectionElem, ProjectionStore, RawIdx, Rvalue, Statement,
|
||||||
|
StatementKind, Substitution, SwitchTargets, Terminator, TerminatorKind, TupleFieldId, Ty,
|
||||||
|
UnOp, VariantId,
|
||||||
|
},
|
||||||
static_lifetime,
|
static_lifetime,
|
||||||
traits::FnTrait,
|
traits::FnTrait,
|
||||||
utils::{generics, ClosureSubst},
|
utils::{generics, ClosureSubst},
|
||||||
Adjust, Adjustment, AutoBorrow, CallableDefId, TyBuilder, TyExt,
|
Adjust, Adjustment, AutoBorrow, CallableDefId, TyBuilder, TyExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
mod as_place;
|
mod as_place;
|
||||||
mod pattern_matching;
|
mod pattern_matching;
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,16 @@
|
||||||
|
|
||||||
use hir_def::{hir::LiteralOrConst, resolver::HasResolver, AssocItemId};
|
use hir_def::{hir::LiteralOrConst, resolver::HasResolver, AssocItemId};
|
||||||
|
|
||||||
use crate::BindingMode;
|
use crate::{
|
||||||
|
mir::lower::{
|
||||||
use super::*;
|
BasicBlockId, BinOp, BindingId, BorrowKind, Either, Expr, FieldId, Idx, Interner,
|
||||||
|
MemoryMap, MirLowerCtx, MirLowerError, MirSpan, Mutability, Operand, Pat, PatId, Place,
|
||||||
|
PlaceElem, ProjectionElem, RecordFieldPat, ResolveValueResult, Result, Rvalue,
|
||||||
|
Substitution, SwitchTargets, TerminatorKind, TupleFieldId, TupleId, TyBuilder, TyKind,
|
||||||
|
ValueNs, VariantData, VariantId,
|
||||||
|
},
|
||||||
|
BindingMode,
|
||||||
|
};
|
||||||
|
|
||||||
macro_rules! not_supported {
|
macro_rules! not_supported {
|
||||||
($x: expr) => {
|
($x: expr) => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use hir::{self, HasCrate, HasVisibility};
|
use hir::{HasCrate, HasVisibility};
|
||||||
use ide_db::{path_transform::PathTransform, FxHashSet};
|
use ide_db::{path_transform::PathTransform, FxHashSet};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use hir::{self, HasAttrs};
|
use hir::HasAttrs;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
documentation::HasDocs, path_transform::PathTransform,
|
documentation::HasDocs, path_transform::PathTransform,
|
||||||
syntax_helpers::insert_whitespace_into_node, traits::get_missing_assoc_items, SymbolKind,
|
syntax_helpers::insert_whitespace_into_node, traits::get_missing_assoc_items, SymbolKind,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use hir::PrefixKind;
|
|
||||||
use stdx::trim_indent;
|
use stdx::trim_indent;
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
use test_utils::{assert_eq_text, CURSOR_MARKER};
|
use test_utils::{assert_eq_text, CURSOR_MARKER};
|
||||||
|
|
|
@ -31,7 +31,7 @@ use base_db::{
|
||||||
salsa::{self, ParallelDatabase},
|
salsa::{self, ParallelDatabase},
|
||||||
SourceDatabaseExt, SourceRootId, Upcast,
|
SourceDatabaseExt, SourceRootId, Upcast,
|
||||||
};
|
};
|
||||||
use fst::{self, raw::IndexedValue, Automaton, Streamer};
|
use fst::{raw::IndexedValue, Automaton, Streamer};
|
||||||
use hir::{
|
use hir::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
import_map::{AssocSearchMode, SearchMode},
|
import_map::{AssocSearchMode, SearchMode},
|
||||||
|
@ -394,7 +394,6 @@ impl Query {
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use expect_test::expect_file;
|
use expect_test::expect_file;
|
||||||
use hir::symbols::SymbolCollector;
|
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -303,7 +303,6 @@ fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use syntax::SourceFile;
|
|
||||||
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
|
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -309,6 +309,10 @@ fn load_crate_graph(
|
||||||
vfs: &mut vfs::Vfs,
|
vfs: &mut vfs::Vfs,
|
||||||
receiver: &Receiver<vfs::loader::Message>,
|
receiver: &Receiver<vfs::loader::Message>,
|
||||||
) -> AnalysisHost {
|
) -> AnalysisHost {
|
||||||
|
let (ProjectWorkspace::Cargo { toolchain, target_layout, .. }
|
||||||
|
| ProjectWorkspace::Json { toolchain, target_layout, .. }
|
||||||
|
| ProjectWorkspace::DetachedFiles { toolchain, target_layout, .. }) = ws;
|
||||||
|
|
||||||
let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok());
|
let lru_cap = std::env::var("RA_LRU_CAP").ok().and_then(|it| it.parse::<usize>().ok());
|
||||||
let mut host = AnalysisHost::new(lru_cap);
|
let mut host = AnalysisHost::new(lru_cap);
|
||||||
let mut analysis_change = Change::new();
|
let mut analysis_change = Change::new();
|
||||||
|
@ -344,14 +348,9 @@ fn load_crate_graph(
|
||||||
let num_crates = crate_graph.len();
|
let num_crates = crate_graph.len();
|
||||||
analysis_change.set_crate_graph(crate_graph);
|
analysis_change.set_crate_graph(crate_graph);
|
||||||
analysis_change.set_proc_macros(proc_macros);
|
analysis_change.set_proc_macros(proc_macros);
|
||||||
if let ProjectWorkspace::Cargo { toolchain, target_layout, .. }
|
analysis_change
|
||||||
| ProjectWorkspace::Json { toolchain, target_layout, .. } = ws
|
.set_target_data_layouts(iter::repeat(target_layout.clone()).take(num_crates).collect());
|
||||||
{
|
|
||||||
analysis_change.set_target_data_layouts(
|
|
||||||
iter::repeat(target_layout.clone()).take(num_crates).collect(),
|
|
||||||
);
|
|
||||||
analysis_change.set_toolchains(iter::repeat(toolchain.clone()).take(num_crates).collect());
|
analysis_change.set_toolchains(iter::repeat(toolchain.clone()).take(num_crates).collect());
|
||||||
}
|
|
||||||
|
|
||||||
host.apply_change(analysis_change);
|
host.apply_change(analysis_change);
|
||||||
host
|
host
|
||||||
|
|
|
@ -100,6 +100,8 @@ pub enum ProjectWorkspace {
|
||||||
/// Holds cfg flags for the current target. We get those by running
|
/// Holds cfg flags for the current target. We get those by running
|
||||||
/// `rustc --print cfg`.
|
/// `rustc --print cfg`.
|
||||||
rustc_cfg: Vec<CfgFlag>,
|
rustc_cfg: Vec<CfgFlag>,
|
||||||
|
toolchain: Option<Version>,
|
||||||
|
target_layout: TargetLayoutLoadResult,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,16 +147,24 @@ impl fmt::Debug for ProjectWorkspace {
|
||||||
debug_struct.field("n_sysroot_crates", &sysroot.num_packages());
|
debug_struct.field("n_sysroot_crates", &sysroot.num_packages());
|
||||||
}
|
}
|
||||||
debug_struct
|
debug_struct
|
||||||
.field("toolchain", &toolchain)
|
|
||||||
.field("n_rustc_cfg", &rustc_cfg.len())
|
.field("n_rustc_cfg", &rustc_cfg.len())
|
||||||
|
.field("toolchain", &toolchain)
|
||||||
.field("data_layout", &data_layout);
|
.field("data_layout", &data_layout);
|
||||||
debug_struct.finish()
|
debug_struct.finish()
|
||||||
}
|
}
|
||||||
ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => f
|
ProjectWorkspace::DetachedFiles {
|
||||||
|
files,
|
||||||
|
sysroot,
|
||||||
|
rustc_cfg,
|
||||||
|
toolchain,
|
||||||
|
target_layout,
|
||||||
|
} => f
|
||||||
.debug_struct("DetachedFiles")
|
.debug_struct("DetachedFiles")
|
||||||
.field("n_files", &files.len())
|
.field("n_files", &files.len())
|
||||||
.field("sysroot", &sysroot.is_ok())
|
.field("sysroot", &sysroot.is_ok())
|
||||||
.field("n_rustc_cfg", &rustc_cfg.len())
|
.field("n_rustc_cfg", &rustc_cfg.len())
|
||||||
|
.field("toolchain", &toolchain)
|
||||||
|
.field("data_layout", &target_layout)
|
||||||
.finish(),
|
.finish(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -403,32 +413,54 @@ impl ProjectWorkspace {
|
||||||
detached_files: Vec<AbsPathBuf>,
|
detached_files: Vec<AbsPathBuf>,
|
||||||
config: &CargoConfig,
|
config: &CargoConfig,
|
||||||
) -> anyhow::Result<ProjectWorkspace> {
|
) -> anyhow::Result<ProjectWorkspace> {
|
||||||
|
let dir = detached_files
|
||||||
|
.first()
|
||||||
|
.and_then(|it| it.parent())
|
||||||
|
.ok_or_else(|| format_err!("No detached files to load"))?;
|
||||||
let sysroot = match &config.sysroot {
|
let sysroot = match &config.sysroot {
|
||||||
Some(RustLibSource::Path(path)) => {
|
Some(RustLibSource::Path(path)) => {
|
||||||
Sysroot::with_sysroot_dir(path.clone(), config.sysroot_query_metadata)
|
Sysroot::with_sysroot_dir(path.clone(), config.sysroot_query_metadata)
|
||||||
.map_err(|e| Some(format!("Failed to find sysroot at {path}:{e}")))
|
.map_err(|e| Some(format!("Failed to find sysroot at {path}:{e}")))
|
||||||
}
|
}
|
||||||
Some(RustLibSource::Discover) => {
|
Some(RustLibSource::Discover) => Sysroot::discover(
|
||||||
let dir = &detached_files
|
dir,
|
||||||
.first()
|
&config.extra_env,
|
||||||
.and_then(|it| it.parent())
|
config.sysroot_query_metadata,
|
||||||
.ok_or_else(|| format_err!("No detached files to load"))?;
|
|
||||||
Sysroot::discover(dir, &config.extra_env, config.sysroot_query_metadata).map_err(
|
|
||||||
|e| {
|
|
||||||
Some(format!(
|
|
||||||
"Failed to find sysroot for {dir}. Is rust-src installed? {e}"
|
|
||||||
))
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
.map_err(|e| {
|
||||||
|
Some(format!("Failed to find sysroot for {dir}. Is rust-src installed? {e}"))
|
||||||
|
}),
|
||||||
None => Err(None),
|
None => Err(None),
|
||||||
};
|
};
|
||||||
let rustc_cfg = rustc_cfg::get(
|
|
||||||
|
let sysroot_ref = sysroot.as_ref().ok();
|
||||||
|
let toolchain = match get_toolchain_version(
|
||||||
|
dir,
|
||||||
|
sysroot_ref,
|
||||||
|
toolchain::Tool::Rustc,
|
||||||
|
&config.extra_env,
|
||||||
|
"rustc ",
|
||||||
|
) {
|
||||||
|
Ok(it) => it,
|
||||||
|
Err(e) => {
|
||||||
|
tracing::error!("{e}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let rustc_cfg = rustc_cfg::get(None, &config.extra_env, RustcCfgConfig::Rustc(sysroot_ref));
|
||||||
|
let data_layout = target_data_layout::get(
|
||||||
|
RustcDataLayoutConfig::Rustc(sysroot_ref),
|
||||||
None,
|
None,
|
||||||
&FxHashMap::default(),
|
&config.extra_env,
|
||||||
RustcCfgConfig::Rustc(sysroot.as_ref().ok()),
|
|
||||||
);
|
);
|
||||||
Ok(ProjectWorkspace::DetachedFiles { files: detached_files, sysroot, rustc_cfg })
|
Ok(ProjectWorkspace::DetachedFiles {
|
||||||
|
files: detached_files,
|
||||||
|
sysroot,
|
||||||
|
rustc_cfg,
|
||||||
|
toolchain,
|
||||||
|
target_layout: data_layout.map(Arc::from).map_err(|it| Arc::from(it.to_string())),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Runs the build scripts for this [`ProjectWorkspace`].
|
/// Runs the build scripts for this [`ProjectWorkspace`].
|
||||||
|
@ -724,7 +756,13 @@ impl ProjectWorkspace {
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
),
|
),
|
||||||
ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => {
|
ProjectWorkspace::DetachedFiles {
|
||||||
|
files,
|
||||||
|
sysroot,
|
||||||
|
rustc_cfg,
|
||||||
|
toolchain: _,
|
||||||
|
target_layout: _,
|
||||||
|
} => {
|
||||||
detached_files_to_crate_graph(rustc_cfg.clone(), load, files, sysroot.as_ref().ok())
|
detached_files_to_crate_graph(rustc_cfg.clone(), load, files, sysroot.as_ref().ok())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -786,9 +824,21 @@ impl ProjectWorkspace {
|
||||||
&& toolchain == o_toolchain
|
&& toolchain == o_toolchain
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
Self::DetachedFiles { files, sysroot, rustc_cfg },
|
Self::DetachedFiles { files, sysroot, rustc_cfg, toolchain, target_layout },
|
||||||
Self::DetachedFiles { files: o_files, sysroot: o_sysroot, rustc_cfg: o_rustc_cfg },
|
Self::DetachedFiles {
|
||||||
) => files == o_files && sysroot == o_sysroot && rustc_cfg == o_rustc_cfg,
|
files: o_files,
|
||||||
|
sysroot: o_sysroot,
|
||||||
|
rustc_cfg: o_rustc_cfg,
|
||||||
|
toolchain: o_toolchain,
|
||||||
|
target_layout: o_target_layout,
|
||||||
|
},
|
||||||
|
) => {
|
||||||
|
files == o_files
|
||||||
|
&& sysroot == o_sysroot
|
||||||
|
&& rustc_cfg == o_rustc_cfg
|
||||||
|
&& toolchain == o_toolchain
|
||||||
|
&& target_layout == o_target_layout
|
||||||
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::mem;
|
||||||
|
|
||||||
use cfg::{CfgAtom, CfgExpr};
|
use cfg::{CfgAtom, CfgExpr};
|
||||||
use ide::{Cancellable, CrateId, FileId, RunnableKind, TestId};
|
use ide::{Cancellable, CrateId, FileId, RunnableKind, TestId};
|
||||||
use project_model::{self, CargoFeatures, ManifestPath, TargetKind};
|
use project_model::{CargoFeatures, ManifestPath, TargetKind};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use vfs::AbsPathBuf;
|
use vfs::AbsPathBuf;
|
||||||
|
|
||||||
|
@ -208,7 +208,6 @@ fn required_features(cfg_expr: &CfgExpr, features: &mut Vec<String>) {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use cfg::CfgExpr;
|
|
||||||
use mbe::{syntax_node_to_token_tree, DummyTestSpanMap, DUMMY};
|
use mbe::{syntax_node_to_token_tree, DummyTestSpanMap, DUMMY};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
|
|
|
@ -13,7 +13,7 @@ use ide_db::{
|
||||||
LineIndexDatabase,
|
LineIndexDatabase,
|
||||||
};
|
};
|
||||||
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
|
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
|
||||||
use lsp_types::{self, lsif};
|
use lsp_types::lsif;
|
||||||
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
|
use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use vfs::{AbsPathBuf, Vfs};
|
use vfs::{AbsPathBuf, Vfs};
|
||||||
|
|
|
@ -5,7 +5,8 @@ use std::{cell::RefCell, fs::read_to_string, panic::AssertUnwindSafe, path::Path
|
||||||
use hir::{Change, Crate};
|
use hir::{Change, Crate};
|
||||||
use ide::{AnalysisHost, DiagnosticCode, DiagnosticsConfig};
|
use ide::{AnalysisHost, DiagnosticCode, DiagnosticsConfig};
|
||||||
use profile::StopWatch;
|
use profile::StopWatch;
|
||||||
use project_model::{CargoConfig, ProjectWorkspace, RustLibSource, Sysroot};
|
use project_model::target_data_layout::RustcDataLayoutConfig;
|
||||||
|
use project_model::{target_data_layout, CargoConfig, ProjectWorkspace, RustLibSource, Sysroot};
|
||||||
|
|
||||||
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
|
use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
@ -60,15 +61,22 @@ impl Tester {
|
||||||
std::fs::write(&tmp_file, "")?;
|
std::fs::write(&tmp_file, "")?;
|
||||||
let cargo_config =
|
let cargo_config =
|
||||||
CargoConfig { sysroot: Some(RustLibSource::Discover), ..Default::default() };
|
CargoConfig { sysroot: Some(RustLibSource::Discover), ..Default::default() };
|
||||||
|
|
||||||
|
let sysroot =
|
||||||
|
Ok(Sysroot::discover(tmp_file.parent().unwrap(), &cargo_config.extra_env, false)
|
||||||
|
.unwrap());
|
||||||
|
let data_layout = target_data_layout::get(
|
||||||
|
RustcDataLayoutConfig::Rustc(sysroot.as_ref().ok()),
|
||||||
|
None,
|
||||||
|
&cargo_config.extra_env,
|
||||||
|
);
|
||||||
|
|
||||||
let workspace = ProjectWorkspace::DetachedFiles {
|
let workspace = ProjectWorkspace::DetachedFiles {
|
||||||
files: vec![tmp_file.clone()],
|
files: vec![tmp_file.clone()],
|
||||||
sysroot: Ok(Sysroot::discover(
|
sysroot,
|
||||||
tmp_file.parent().unwrap(),
|
|
||||||
&cargo_config.extra_env,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.unwrap()),
|
|
||||||
rustc_cfg: vec![],
|
rustc_cfg: vec![],
|
||||||
|
toolchain: None,
|
||||||
|
target_layout: data_layout.map(Arc::from).map_err(|it| Arc::from(it.to_string())),
|
||||||
};
|
};
|
||||||
let load_cargo_config = LoadCargoConfig {
|
let load_cargo_config = LoadCargoConfig {
|
||||||
load_out_dirs_from_check: false,
|
load_out_dirs_from_check: false,
|
||||||
|
|
|
@ -324,7 +324,7 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use ide::{AnalysisHost, FilePosition, StaticIndex, TextSize};
|
use ide::{AnalysisHost, FilePosition, TextSize};
|
||||||
use scip::symbol::format_symbol;
|
use scip::symbol::format_symbol;
|
||||||
use test_fixture::ChangeFixture;
|
use test_fixture::ChangeFixture;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
//!
|
//!
|
||||||
use std::{convert::TryFrom, iter::FromIterator};
|
|
||||||
|
|
||||||
use crate::parenthesized::Parenthesized;
|
use crate::parenthesized::Parenthesized;
|
||||||
use heck::ToUpperCamelCase;
|
use heck::ToUpperCamelCase;
|
||||||
|
|
|
@ -5,7 +5,6 @@ use crate::durability::Durability;
|
||||||
use crate::plumbing::QueryStorageOps;
|
use crate::plumbing::QueryStorageOps;
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
use crate::QueryTable;
|
use crate::QueryTable;
|
||||||
use std::iter::FromIterator;
|
|
||||||
|
|
||||||
/// Additional methods on queries that can be used to "peek into"
|
/// Additional methods on queries that can be used to "peek into"
|
||||||
/// their current state. These methods are meant for debugging and
|
/// their current state. These methods are meant for debugging and
|
||||||
|
|
|
@ -13,7 +13,6 @@ use crate::Runtime;
|
||||||
use crate::{Database, DatabaseKeyIndex, QueryDb, Revision};
|
use crate::{Database, DatabaseKeyIndex, QueryDb, Revision};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
|
@ -14,7 +14,6 @@ use crate::Runtime;
|
||||||
use crate::{DatabaseKeyIndex, QueryDb};
|
use crate::{DatabaseKeyIndex, QueryDb};
|
||||||
use indexmap::map::Entry;
|
use indexmap::map::Entry;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::convert::TryFrom;
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use crate::{Database, DatabaseKeyIndex, QueryDb};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::convert::From;
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
Loading…
Reference in a new issue