about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukas.wirth@ferrous-systems.com>2024-02-20 10:40:39 +0100
committerLukas Wirth <lukas.wirth@ferrous-systems.com>2024-02-20 10:40:39 +0100
commitd93096ecc0cb530d851ebbd58dce6cd2e68c850f (patch)
tree113984be419c1e1fdf57082f637f398b71fa6fd6
parent2223b4fa71e543ac6dd1abd4770a69fab8dbdec1 (diff)
downloadrust-d93096ecc0cb530d851ebbd58dce6cd2e68c850f.tar.gz
rust-d93096ecc0cb530d851ebbd58dce6cd2e68c850f.zip
internal: Fetch toolchain and datalayout for DetachedFiles
-rw-r--r--crates/hir-def/src/body/pretty.rs4
-rw-r--r--crates/hir-def/src/import_map.rs4
-rw-r--r--crates/hir-def/src/item_tree.rs6
-rw-r--r--crates/hir-def/src/item_tree/lower.rs26
-rw-r--r--crates/hir-def/src/item_tree/pretty.rs9
-rw-r--r--crates/hir-def/src/nameres.rs2
-rw-r--r--crates/hir-def/src/nameres/collector.rs2
-rw-r--r--crates/hir-def/src/nameres/tests/macros.rs3
-rw-r--r--crates/hir-ty/src/diagnostics/match_check/pat_util.rs2
-rw-r--r--crates/hir-ty/src/mir/eval/shim.rs8
-rw-r--r--crates/hir-ty/src/mir/eval/shim/simd.rs1
-rw-r--r--crates/hir-ty/src/mir/lower.rs10
-rw-r--r--crates/hir-ty/src/mir/lower/pattern_matching.rs13
-rw-r--r--crates/ide-assists/src/handlers/generate_delegate_methods.rs2
-rw-r--r--crates/ide-completion/src/completions/item_list/trait_impl.rs2
-rw-r--r--crates/ide-db/src/imports/insert_use/tests.rs1
-rw-r--r--crates/ide-db/src/symbol_index.rs3
-rw-r--r--crates/ide/src/join_lines.rs1
-rw-r--r--crates/load-cargo/src/lib.rs15
-rw-r--r--crates/project-model/src/workspace.rs96
-rw-r--r--crates/rust-analyzer/src/cargo_target_spec.rs3
-rw-r--r--crates/rust-analyzer/src/cli/lsif.rs2
-rw-r--r--crates/rust-analyzer/src/cli/rustc_tests.rs22
-rw-r--r--crates/rust-analyzer/src/cli/scip.rs2
-rw-r--r--crates/salsa/salsa-macros/src/query_group.rs1
-rw-r--r--crates/salsa/src/debug.rs1
-rw-r--r--crates/salsa/src/derived.rs1
-rw-r--r--crates/salsa/src/input.rs1
-rw-r--r--crates/salsa/src/interned.rs1
29 files changed, 164 insertions, 80 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs
index 7007dea638e..cd14f7b855a 100644
--- a/crates/hir-def/src/body/pretty.rs
+++ b/crates/hir-def/src/body/pretty.rs
@@ -6,8 +6,8 @@ use itertools::Itertools;
 
 use crate::{
     hir::{
-        Array, BindingAnnotation, BindingId, CaptureBy, ClosureKind, Literal, LiteralOrConst,
-        Movability, Statement,
+        Array, BindingAnnotation, CaptureBy, ClosureKind, Literal, LiteralOrConst, Movability,
+        Statement,
     },
     pretty::{print_generic_args, print_path, print_type_ref},
     type_ref::TypeRef,
diff --git a/crates/hir-def/src/import_map.rs b/crates/hir-def/src/import_map.rs
index 98982c7db84..faa1eed15a4 100644
--- a/crates/hir-def/src/import_map.rs
+++ b/crates/hir-def/src/import_map.rs
@@ -3,7 +3,7 @@
 use std::{fmt, hash::BuildHasherDefault};
 
 use base_db::CrateId;
-use fst::{self, raw::IndexedValue, Automaton, Streamer};
+use fst::{raw::IndexedValue, Automaton, Streamer};
 use hir_expand::name::Name;
 use indexmap::IndexMap;
 use itertools::Itertools;
@@ -477,7 +477,7 @@ mod tests {
     use expect_test::{expect, Expect};
     use test_fixture::WithFixture;
 
-    use crate::{db::DefDatabase, test_db::TestDB, ItemContainerId, Lookup};
+    use crate::{test_db::TestDB, ItemContainerId, Lookup};
 
     use super::*;
 
diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs
index be16a5e31a2..bb36950f95a 100644
--- a/crates/hir-def/src/item_tree.rs
+++ b/crates/hir-def/src/item_tree.rs
@@ -44,13 +44,13 @@ use std::{
     ops::{Index, Range},
 };
 
-use ast::{AstNode, HasName, StructKind};
+use ast::{AstNode, StructKind};
 use base_db::CrateId;
 use either::Either;
 use hir_expand::{
     ast_id_map::{AstIdNode, FileAstId},
     attrs::RawAttrs,
-    name::{name, AsName, Name},
+    name::Name,
     ExpandTo, HirFileId, InFile,
 };
 use intern::Interned;
@@ -67,7 +67,7 @@ use crate::{
     attr::Attrs,
     db::DefDatabase,
     generics::{GenericParams, LifetimeParamData, TypeOrConstParamData},
-    path::{path, AssociatedTypeBinding, GenericArgs, ImportAlias, ModPath, Path, PathKind},
+    path::{GenericArgs, ImportAlias, ModPath, Path, PathKind},
     type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
     visibility::{RawVisibility, VisibilityExplicitness},
     BlockId, Lookup,
diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs
index e0aa3ae6123..37fdece8768 100644
--- a/crates/hir-def/src/item_tree/lower.rs
+++ b/crates/hir-def/src/item_tree/lower.rs
@@ -2,17 +2,33 @@
 
 use std::collections::hash_map::Entry;
 
-use hir_expand::{ast_id_map::AstIdMap, span_map::SpanMapRef, HirFileId};
-use syntax::ast::{self, HasModuleItem, HasTypeBounds, IsString};
+use hir_expand::{
+    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::{
+    db::DefDatabase,
     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,
 };
 
-use super::*;
-
 fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
     FileItemTreeId(index)
 }
diff --git a/crates/hir-def/src/item_tree/pretty.rs b/crates/hir-def/src/item_tree/pretty.rs
index 0086b7180b2..87c90a4c6ab 100644
--- a/crates/hir-def/src/item_tree/pretty.rs
+++ b/crates/hir-def/src/item_tree/pretty.rs
@@ -6,12 +6,17 @@ use span::ErasedFileAstId;
 
 use crate::{
     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},
     visibility::RawVisibility,
 };
 
-use super::*;
-
 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 };
 
diff --git a/crates/hir-def/src/nameres.rs b/crates/hir-def/src/nameres.rs
index 2a9390e7978..a2eca066438 100644
--- a/crates/hir-def/src/nameres.rs
+++ b/crates/hir-def/src/nameres.rs
@@ -57,7 +57,7 @@ pub mod proc_macro;
 #[cfg(test)]
 mod tests;
 
-use std::{cmp::Ord, ops::Deref};
+use std::ops::Deref;
 
 use base_db::{CrateId, Edition, FileId};
 use hir_expand::{
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs
index 88838f58fe7..32825406505 100644
--- a/crates/hir-def/src/nameres/collector.rs
+++ b/crates/hir-def/src/nameres/collector.rs
@@ -2446,7 +2446,7 @@ mod tests {
     use base_db::SourceDatabase;
     use test_fixture::WithFixture;
 
-    use crate::{db::DefDatabase, test_db::TestDB};
+    use crate::test_db::TestDB;
 
     use super::*;
 
diff --git a/crates/hir-def/src/nameres/tests/macros.rs b/crates/hir-def/src/nameres/tests/macros.rs
index bf89ea711a0..d278b75e815 100644
--- a/crates/hir-def/src/nameres/tests/macros.rs
+++ b/crates/hir-def/src/nameres/tests/macros.rs
@@ -1,10 +1,7 @@
 use expect_test::expect;
-use test_fixture::WithFixture;
 
 use itertools::Itertools;
 
-use crate::nameres::tests::check;
-
 use super::*;
 
 #[test]
diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_util.rs b/crates/hir-ty/src/diagnostics/match_check/pat_util.rs
index 217454499ef..c6a26cdd1d0 100644
--- a/crates/hir-ty/src/diagnostics/match_check/pat_util.rs
+++ b/crates/hir-ty/src/diagnostics/match_check/pat_util.rs
@@ -2,7 +2,7 @@
 //!
 //! Originates from `rustc_hir::pat_util`
 
-use std::iter::{Enumerate, ExactSizeIterator};
+use std::iter::Enumerate;
 
 pub(crate) struct EnumerateAndAdjust<I> {
     enumerate: Enumerate<I>,
diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs
index d68803fe280..cd992d07602 100644
--- a/crates/hir-ty/src/mir/eval/shim.rs
+++ b/crates/hir-ty/src/mir/eval/shim.rs
@@ -8,9 +8,13 @@ use hir_def::{
     builtin_type::{BuiltinInt, BuiltinUint},
     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;
 
diff --git a/crates/hir-ty/src/mir/eval/shim/simd.rs b/crates/hir-ty/src/mir/eval/shim/simd.rs
index eddfd0acfb9..e229a4ab317 100644
--- a/crates/hir-ty/src/mir/eval/shim/simd.rs
+++ b/crates/hir-ty/src/mir/eval/shim/simd.rs
@@ -2,6 +2,7 @@
 
 use std::cmp::Ordering;
 
+use crate::consteval::try_const_usize;
 use crate::TyKind;
 
 use super::*;
diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs
index b038900cdac..ed316f97268 100644
--- a/crates/hir-ty/src/mir/lower.rs
+++ b/crates/hir-ty/src/mir/lower.rs
@@ -31,14 +31,20 @@ use crate::{
     inhabitedness::is_ty_uninhabited_from,
     layout::LayoutError,
     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,
     traits::FnTrait,
     utils::{generics, ClosureSubst},
     Adjust, Adjustment, AutoBorrow, CallableDefId, TyBuilder, TyExt,
 };
 
-use super::*;
-
 mod as_place;
 mod pattern_matching;
 
diff --git a/crates/hir-ty/src/mir/lower/pattern_matching.rs b/crates/hir-ty/src/mir/lower/pattern_matching.rs
index 8202bac532f..85c8d1685b8 100644
--- a/crates/hir-ty/src/mir/lower/pattern_matching.rs
+++ b/crates/hir-ty/src/mir/lower/pattern_matching.rs
@@ -2,9 +2,16 @@
 
 use hir_def::{hir::LiteralOrConst, resolver::HasResolver, AssocItemId};
 
-use crate::BindingMode;
-
-use super::*;
+use crate::{
+    mir::lower::{
+        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 {
     ($x: expr) => {
diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs
index 4f2df5633c3..38f40b8d58b 100644
--- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs
+++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs
@@ -1,4 +1,4 @@
-use hir::{self, HasCrate, HasVisibility};
+use hir::{HasCrate, HasVisibility};
 use ide_db::{path_transform::PathTransform, FxHashSet};
 use syntax::{
     ast::{
diff --git a/crates/ide-completion/src/completions/item_list/trait_impl.rs b/crates/ide-completion/src/completions/item_list/trait_impl.rs
index 3c4b89ca742..7394d63be58 100644
--- a/crates/ide-completion/src/completions/item_list/trait_impl.rs
+++ b/crates/ide-completion/src/completions/item_list/trait_impl.rs
@@ -31,7 +31,7 @@
 //! }
 //! ```
 
-use hir::{self, HasAttrs};
+use hir::HasAttrs;
 use ide_db::{
     documentation::HasDocs, path_transform::PathTransform,
     syntax_helpers::insert_whitespace_into_node, traits::get_missing_assoc_items, SymbolKind,
diff --git a/crates/ide-db/src/imports/insert_use/tests.rs b/crates/ide-db/src/imports/insert_use/tests.rs
index 6b0fecae267..10c285a13fb 100644
--- a/crates/ide-db/src/imports/insert_use/tests.rs
+++ b/crates/ide-db/src/imports/insert_use/tests.rs
@@ -1,4 +1,3 @@
-use hir::PrefixKind;
 use stdx::trim_indent;
 use test_fixture::WithFixture;
 use test_utils::{assert_eq_text, CURSOR_MARKER};
diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs
index 92c09089e1f..c65467a4324 100644
--- a/crates/ide-db/src/symbol_index.rs
+++ b/crates/ide-db/src/symbol_index.rs
@@ -31,7 +31,7 @@ use base_db::{
     salsa::{self, ParallelDatabase},
     SourceDatabaseExt, SourceRootId, Upcast,
 };
-use fst::{self, raw::IndexedValue, Automaton, Streamer};
+use fst::{raw::IndexedValue, Automaton, Streamer};
 use hir::{
     db::HirDatabase,
     import_map::{AssocSearchMode, SearchMode},
@@ -394,7 +394,6 @@ impl Query {
 mod tests {
 
     use expect_test::expect_file;
-    use hir::symbols::SymbolCollector;
     use test_fixture::WithFixture;
 
     use super::*;
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs
index fef0ec35ba0..815a4ba7fd7 100644
--- a/crates/ide/src/join_lines.rs
+++ b/crates/ide/src/join_lines.rs
@@ -303,7 +303,6 @@ fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {
 
 #[cfg(test)]
 mod tests {
-    use syntax::SourceFile;
     use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
 
     use super::*;
diff --git a/crates/load-cargo/src/lib.rs b/crates/load-cargo/src/lib.rs
index 8c5592da63e..830d19a709c 100644
--- a/crates/load-cargo/src/lib.rs
+++ b/crates/load-cargo/src/lib.rs
@@ -309,6 +309,10 @@ fn load_crate_graph(
     vfs: &mut vfs::Vfs,
     receiver: &Receiver<vfs::loader::Message>,
 ) -> 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 mut host = AnalysisHost::new(lru_cap);
     let mut analysis_change = Change::new();
@@ -344,14 +348,9 @@ fn load_crate_graph(
     let num_crates = crate_graph.len();
     analysis_change.set_crate_graph(crate_graph);
     analysis_change.set_proc_macros(proc_macros);
-    if let ProjectWorkspace::Cargo { toolchain, target_layout, .. }
-    | ProjectWorkspace::Json { toolchain, target_layout, .. } = ws
-    {
-        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_target_data_layouts(iter::repeat(target_layout.clone()).take(num_crates).collect());
+    analysis_change.set_toolchains(iter::repeat(toolchain.clone()).take(num_crates).collect());
 
     host.apply_change(analysis_change);
     host
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index b7ae76be8ce..bcb5dcadb5b 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -100,6 +100,8 @@ pub enum ProjectWorkspace {
         /// Holds cfg flags for the current target. We get those by running
         /// `rustc --print cfg`.
         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("toolchain", &toolchain)
                     .field("n_rustc_cfg", &rustc_cfg.len())
+                    .field("toolchain", &toolchain)
                     .field("data_layout", &data_layout);
                 debug_struct.finish()
             }
-            ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => f
+            ProjectWorkspace::DetachedFiles {
+                files,
+                sysroot,
+                rustc_cfg,
+                toolchain,
+                target_layout,
+            } => f
                 .debug_struct("DetachedFiles")
                 .field("n_files", &files.len())
                 .field("sysroot", &sysroot.is_ok())
                 .field("n_rustc_cfg", &rustc_cfg.len())
+                .field("toolchain", &toolchain)
+                .field("data_layout", &target_layout)
                 .finish(),
         }
     }
@@ -403,32 +413,54 @@ impl ProjectWorkspace {
         detached_files: Vec<AbsPathBuf>,
         config: &CargoConfig,
     ) -> 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 {
             Some(RustLibSource::Path(path)) => {
                 Sysroot::with_sysroot_dir(path.clone(), config.sysroot_query_metadata)
                     .map_err(|e| Some(format!("Failed to find sysroot at {path}:{e}")))
             }
-            Some(RustLibSource::Discover) => {
-                let dir = &detached_files
-                    .first()
-                    .and_then(|it| it.parent())
-                    .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}"
-                        ))
-                    },
-                )
-            }
+            Some(RustLibSource::Discover) => 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}"))
+            }),
             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,
-            &FxHashMap::default(),
-            RustcCfgConfig::Rustc(sysroot.as_ref().ok()),
+            &config.extra_env,
         );
-        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`].
@@ -724,7 +756,13 @@ impl ProjectWorkspace {
                 cfg_overrides,
                 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())
             }
         };
@@ -786,9 +824,21 @@ impl ProjectWorkspace {
                     && toolchain == o_toolchain
             }
             (
-                Self::DetachedFiles { files, sysroot, 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,
+                Self::DetachedFiles { files, sysroot, rustc_cfg, toolchain, target_layout },
+                Self::DetachedFiles {
+                    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,
         }
     }
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs
index 9a9357a5398..815a98980b9 100644
--- a/crates/rust-analyzer/src/cargo_target_spec.rs
+++ b/crates/rust-analyzer/src/cargo_target_spec.rs
@@ -4,7 +4,7 @@ use std::mem;
 
 use cfg::{CfgAtom, CfgExpr};
 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 vfs::AbsPathBuf;
 
@@ -208,7 +208,6 @@ fn required_features(cfg_expr: &CfgExpr, features: &mut Vec<String>) {
 mod tests {
     use super::*;
 
-    use cfg::CfgExpr;
     use mbe::{syntax_node_to_token_tree, DummyTestSpanMap, DUMMY};
     use syntax::{
         ast::{self, AstNode},
diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs
index 1424a775777..5e810463db6 100644
--- a/crates/rust-analyzer/src/cli/lsif.rs
+++ b/crates/rust-analyzer/src/cli/lsif.rs
@@ -13,7 +13,7 @@ use ide_db::{
     LineIndexDatabase,
 };
 use load_cargo::{load_workspace, LoadCargoConfig, ProcMacroServerChoice};
-use lsp_types::{self, lsif};
+use lsp_types::lsif;
 use project_model::{CargoConfig, ProjectManifest, ProjectWorkspace, RustLibSource};
 use rustc_hash::FxHashMap;
 use vfs::{AbsPathBuf, Vfs};
diff --git a/crates/rust-analyzer/src/cli/rustc_tests.rs b/crates/rust-analyzer/src/cli/rustc_tests.rs
index 64ea246a458..25f84d770bf 100644
--- a/crates/rust-analyzer/src/cli/rustc_tests.rs
+++ b/crates/rust-analyzer/src/cli/rustc_tests.rs
@@ -5,7 +5,8 @@ use std::{cell::RefCell, fs::read_to_string, panic::AssertUnwindSafe, path::Path
 use hir::{Change, Crate};
 use ide::{AnalysisHost, DiagnosticCode, DiagnosticsConfig};
 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 rustc_hash::FxHashMap;
@@ -60,15 +61,22 @@ impl Tester {
         std::fs::write(&tmp_file, "")?;
         let cargo_config =
             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 {
             files: vec![tmp_file.clone()],
-            sysroot: Ok(Sysroot::discover(
-                tmp_file.parent().unwrap(),
-                &cargo_config.extra_env,
-                false,
-            )
-            .unwrap()),
+            sysroot,
             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 {
             load_out_dirs_from_check: false,
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index 2d56830c87f..27869a5a7e6 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -324,7 +324,7 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
 #[cfg(test)]
 mod test {
     use super::*;
-    use ide::{AnalysisHost, FilePosition, StaticIndex, TextSize};
+    use ide::{AnalysisHost, FilePosition, TextSize};
     use scip::symbol::format_symbol;
     use test_fixture::ChangeFixture;
 
diff --git a/crates/salsa/salsa-macros/src/query_group.rs b/crates/salsa/salsa-macros/src/query_group.rs
index e535d7ed043..5d1678ef120 100644
--- a/crates/salsa/salsa-macros/src/query_group.rs
+++ b/crates/salsa/salsa-macros/src/query_group.rs
@@ -1,5 +1,4 @@
 //!
-use std::{convert::TryFrom, iter::FromIterator};
 
 use crate::parenthesized::Parenthesized;
 use heck::ToUpperCamelCase;
diff --git a/crates/salsa/src/debug.rs b/crates/salsa/src/debug.rs
index 0925ddb3d85..5f113541f04 100644
--- a/crates/salsa/src/debug.rs
+++ b/crates/salsa/src/debug.rs
@@ -5,7 +5,6 @@ use crate::durability::Durability;
 use crate::plumbing::QueryStorageOps;
 use crate::Query;
 use crate::QueryTable;
-use std::iter::FromIterator;
 
 /// Additional methods on queries that can be used to "peek into"
 /// their current state. These methods are meant for debugging and
diff --git a/crates/salsa/src/derived.rs b/crates/salsa/src/derived.rs
index c381e66e087..d6316710058 100644
--- a/crates/salsa/src/derived.rs
+++ b/crates/salsa/src/derived.rs
@@ -13,7 +13,6 @@ use crate::Runtime;
 use crate::{Database, DatabaseKeyIndex, QueryDb, Revision};
 use parking_lot::RwLock;
 use std::borrow::Borrow;
-use std::convert::TryFrom;
 use std::hash::Hash;
 use std::marker::PhantomData;
 use triomphe::Arc;
diff --git a/crates/salsa/src/input.rs b/crates/salsa/src/input.rs
index 4e8fca6149b..c2539570e0f 100644
--- a/crates/salsa/src/input.rs
+++ b/crates/salsa/src/input.rs
@@ -14,7 +14,6 @@ use crate::Runtime;
 use crate::{DatabaseKeyIndex, QueryDb};
 use indexmap::map::Entry;
 use parking_lot::RwLock;
-use std::convert::TryFrom;
 use std::iter;
 use tracing::debug;
 
diff --git a/crates/salsa/src/interned.rs b/crates/salsa/src/interned.rs
index 731839e9598..822219f5185 100644
--- a/crates/salsa/src/interned.rs
+++ b/crates/salsa/src/interned.rs
@@ -13,7 +13,6 @@ use crate::{Database, DatabaseKeyIndex, QueryDb};
 use parking_lot::RwLock;
 use rustc_hash::FxHashMap;
 use std::collections::hash_map::Entry;
-use std::convert::From;
 use std::fmt::Debug;
 use std::hash::Hash;
 use triomphe::Arc;