diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index d1e2d74a98..daa0e3f699 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs @@ -10,7 +10,7 @@ use tt::Subtree; use vfs::{file_set::FileSet, VfsPath}; use crate::{ - input::{CrateName, CrateOrigin}, + input::{CrateName, CrateOrigin, LangCrateOrigin}, Change, CrateDisplayName, CrateGraph, CrateId, Dependency, Edition, Env, FileId, FilePosition, FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, SourceDatabaseExt, SourceRoot, SourceRootId, @@ -196,7 +196,7 @@ impl ChangeFixture { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); } else { for (from, to, prelude) in crate_deps { @@ -233,7 +233,7 @@ impl ChangeFixture { Env::default(), Vec::new(), false, - CrateOrigin::Lang, + CrateOrigin::Lang(LangCrateOrigin::Core), ); for krate in all_crates { @@ -270,7 +270,7 @@ impl ChangeFixture { Env::default(), proc_macro, true, - CrateOrigin::Lang, + CrateOrigin::CratesIo { repo: None }, ); for krate in all_crates { @@ -406,7 +406,11 @@ fn parse_crate(crate_str: String) -> (String, CrateOrigin, Option) { }; (a.to_owned(), origin, Some(version.to_string())) } else { - (crate_str, CrateOrigin::Unknown, None) + let crate_origin = match &*crate_str { + "std" => CrateOrigin::Lang(LangCrateOrigin::Std), + _ => CrateOrigin::CratesIo { repo: None }, + }; + (crate_str, crate_origin, None) } } diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index db3f85604b..43d7ccad49 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -117,21 +117,22 @@ impl ops::Deref for CrateName { } /// Origin of the crates. It is used in emitting monikers. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum CrateOrigin { /// Crates that are from crates.io official registry, CratesIo { repo: Option }, /// Crates that are provided by the language, like std, core, proc-macro, ... - Lang, - /// Crates that we don't know their origin. - // Ideally this enum should cover all cases, and then we remove this variant. - Unknown, + Lang(LangCrateOrigin), } -impl Default for CrateOrigin { - fn default() -> Self { - Self::Unknown - } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum LangCrateOrigin { + Alloc, + Core, + ProcMacro, + Std, + Test, + Other, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -585,6 +586,8 @@ impl fmt::Display for CyclicDependenciesError { #[cfg(test)] mod tests { + use crate::CrateOrigin; + use super::{CfgOptions, CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId}; #[test] @@ -600,7 +603,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -612,7 +615,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); let crate3 = graph.add_crate_root( FileId(3u32), @@ -624,7 +627,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); assert!(graph .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2)) @@ -650,7 +653,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -662,7 +665,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); assert!(graph .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2)) @@ -685,7 +688,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -697,7 +700,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); let crate3 = graph.add_crate_root( FileId(3u32), @@ -709,7 +712,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); assert!(graph .add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2)) @@ -732,7 +735,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); let crate2 = graph.add_crate_root( FileId(2u32), @@ -744,7 +747,7 @@ mod tests { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); assert!(graph .add_dep( diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index d80660f7c9..2454698bb6 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -12,8 +12,8 @@ pub use crate::{ change::Change, input::{ CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, - Edition, Env, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacroId, - ProcMacroKind, SourceRoot, SourceRootId, + Edition, Env, LangCrateOrigin, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, + ProcMacroId, ProcMacroKind, SourceRoot, SourceRootId, }, }; pub use salsa::{self, Cancelled}; diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index c07c017c3d..171131c99e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -148,6 +148,10 @@ impl Crate { db.crate_graph()[self.id].origin.clone() } + pub fn is_builtin(self, db: &dyn HirDatabase) -> bool { + matches!(self.origin(db), CrateOrigin::Lang(_)) + } + pub fn dependencies(self, db: &dyn HirDatabase) -> Vec { db.crate_graph()[self.id] .dependencies @@ -155,7 +159,7 @@ impl Crate { .map(|dep| { let krate = Crate { id: dep.crate_id }; let name = dep.as_name(); - CrateDependency { krate, name } + CrateDependency { krate, name, } }) .collect() } @@ -1741,10 +1745,8 @@ impl BuiltinType { BuiltinType { inner: hir_def::builtin_type::BuiltinType::Str } } - pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type { - let resolver = module.id.resolver(db.upcast()); - Type::new_with_resolver(db, &resolver, TyBuilder::builtin(self.inner)) - .expect("crate not present in resolver") + pub fn ty(self, db: &dyn HirDatabase) -> Type { + Type::new_for_crate(db.crate_graph().iter().next().unwrap(), TyBuilder::builtin(self.inner)) } pub fn name(self) -> Name { @@ -2619,6 +2621,7 @@ impl Type { let krate = resolver.krate()?; Some(Type::new_with_resolver_inner(db, krate, resolver, ty)) } + pub(crate) fn new_with_resolver_inner( db: &dyn HirDatabase, krate: CrateId, @@ -2631,6 +2634,10 @@ impl Type { Type { krate, env: environment, ty } } + pub(crate) fn new_for_crate(krate: CrateId, ty: Ty) -> Type { + Type { krate, env: Arc::new(TraitEnvironment::empty(krate)), ty } + } + pub fn reference(inner: &Type, m: Mutability) -> Type { inner.derived( TyKind::Ref( diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index 775af2b66c..a7d6bc2401 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -63,10 +63,7 @@ pub(crate) fn goto_implementation( Definition::Trait(trait_) => impls_for_trait(&sema, trait_), Definition::Adt(adt) => impls_for_ty(&sema, adt.ty(sema.db)), Definition::TypeAlias(alias) => impls_for_ty(&sema, alias.ty(sema.db)), - Definition::BuiltinType(builtin) => { - let module = sema.to_module_def(position.file_id)?; - impls_for_ty(&sema, builtin.ty(sema.db, module)) - } + Definition::BuiltinType(builtin) => impls_for_ty(&sema, builtin.ty(sema.db)), Definition::Function(f) => { let assoc = f.as_assoc_item(sema.db)?; let name = assoc.name(sema.db)?; diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 7fcb09b5e2..4c4a2bd199 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -64,7 +64,7 @@ use cfg::CfgOptions; use ide_db::{ base_db::{ salsa::{self, ParallelDatabase}, - Env, FileLoader, FileSet, SourceDatabase, VfsPath, + CrateOrigin, Env, FileLoader, FileSet, SourceDatabase, VfsPath, }, symbol_index, LineIndexDatabase, }; @@ -232,7 +232,7 @@ impl Analysis { Env::default(), Default::default(), false, - Default::default(), + CrateOrigin::CratesIo { repo: None }, ); change.change_file(file_id, Some(Arc::new(text))); change.set_crate_graph(crate_graph); diff --git a/crates/ide/src/moniker.rs b/crates/ide/src/moniker.rs index 2e93d895f0..0f75abe55c 100644 --- a/crates/ide/src/moniker.rs +++ b/crates/ide/src/moniker.rs @@ -3,7 +3,7 @@ use hir::{db::DefDatabase, AsAssocItem, AssocItemContainer, Crate, Name, Semantics}; use ide_db::{ - base_db::{CrateOrigin, FileId, FileLoader, FilePosition}, + base_db::{CrateOrigin, FileId, FileLoader, FilePosition, LangCrateOrigin}, defs::{Definition, IdentClass}, helpers::pick_best_token, RootDatabase, @@ -151,11 +151,20 @@ pub(crate) fn def_to_moniker( let name = krate.display_name(db)?.to_string(); let (repo, version) = match krate.origin(db) { CrateOrigin::CratesIo { repo } => (repo?, krate.version(db)?), - CrateOrigin::Lang => ( + CrateOrigin::Lang(lang) => ( "https://github.com/rust-lang/rust/".to_string(), - "compiler_version".to_string(), + format!( + "https://github.com/rust-lang/rust/library/{}", + match lang { + LangCrateOrigin::Alloc => "alloc", + LangCrateOrigin::Core => "core", + LangCrateOrigin::ProcMacro => "proc_macro", + LangCrateOrigin::Std => "std", + LangCrateOrigin::Test => "test", + LangCrateOrigin::Other => "", + } + ), ), - CrateOrigin::Unknown => return None, }; PackageInformation { name, repo, version } }, diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 7ac6775685..e92deec8b8 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -3,7 +3,6 @@ use hir::{AsAssocItem, HasVisibility, Semantics}; use ide_db::{ defs::{Definition, IdentClass, NameClass, NameRefClass}, - famous_defs::FamousDefs, RootDatabase, SymbolKind, }; use rustc_hash::FxHashMap; @@ -472,14 +471,12 @@ fn highlight_def( Definition::ToolModule(_) => Highlight::new(HlTag::Symbol(SymbolKind::ToolModule)), }; - let famous_defs = FamousDefs(sema, krate); let def_crate = def.module(db).map(hir::Module::krate).or_else(|| match def { Definition::Module(module) => Some(module.krate()), _ => None, }); let is_from_other_crate = def_crate != krate; - let is_from_builtin_crate = - def_crate.map_or(false, |def_crate| famous_defs.builtin_crates().any(|it| def_crate == it)); + let is_from_builtin_crate = def_crate.map_or(false, |def_crate| def_crate.is_builtin(db)); let is_builtin_type = matches!(def, Definition::BuiltinType(_)); let is_public = def.visibility(db) == Some(hir::Visibility::Public); @@ -525,10 +522,9 @@ fn highlight_method_call( h |= HlMod::Trait; } - let famous_defs = FamousDefs(sema, krate); let def_crate = func.module(sema.db).krate(); let is_from_other_crate = Some(def_crate) != krate; - let is_from_builtin_crate = famous_defs.builtin_crates().any(|it| def_crate == it); + let is_from_builtin_crate = def_crate.is_builtin(sema.db); let is_public = func.visibility(sema.db) == hir::Visibility::Public; if is_from_other_crate { diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html index 87b9da46e2..af41796e21 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_extern_crate.html @@ -43,5 +43,5 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
extern crate std;
-extern crate alloc as abc;
+extern crate alloc as abc;
 
\ No newline at end of file diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs index 42317ea4da..0add950718 100644 --- a/crates/ide_assists/src/utils.rs +++ b/crates/ide_assists/src/utils.rs @@ -600,8 +600,7 @@ fn handle_as_ref_str( db: &dyn HirDatabase, famous_defs: &FamousDefs, ) -> Option { - let module = famous_defs.1?.root_module(db); - let str_type = hir::BuiltinType::str().ty(db, module); + let str_type = hir::BuiltinType::str().ty(db); ty.impls_trait(db, famous_defs.core_convert_AsRef()?, &[str_type]) .then(|| ReferenceConversionType::AsRefStr) diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs index 0d3a49c668..574b8b8c7a 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs @@ -159,13 +159,7 @@ fn pattern_path_completion( hir::PathResolution::Def(hir::ModuleDef::Adt(hir::Adt::Union(u))) => { u.ty(ctx.db) } - hir::PathResolution::Def(hir::ModuleDef::BuiltinType(ty)) => { - let module = match ctx.module { - Some(m) => m, - None => return, - }; - ty.ty(ctx.db, module) - } + hir::PathResolution::Def(hir::ModuleDef::BuiltinType(ty)) => ty.ty(ctx.db), _ => return, }; diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index c1f23ceeca..3930adbf0e 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs @@ -1,7 +1,6 @@ //! Completion of paths, i.e. `some::prefix::$0`. use hir::{ScopeDef, Trait}; -use ide_db::famous_defs::FamousDefs; use rustc_hash::FxHashSet; use syntax::ast; @@ -26,7 +25,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon }; let traits_in_scope = |ctx: &CompletionContext| { let mut traits_in_scope = ctx.scope.visible_traits(); - if let Some(drop) = FamousDefs(&ctx.sema, ctx.krate).core_ops_Drop() { + if let Some(drop) = ctx.famous_defs().core_ops_Drop() { traits_in_scope.remove(&drop.into()); } traits_in_scope @@ -133,12 +132,8 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon ty } hir::ModuleDef::BuiltinType(builtin) => { - let module = match ctx.module { - Some(it) => it, - None => return, - }; cov_mark::hit!(completes_primitive_assoc_const); - builtin.ty(ctx.db, module) + builtin.ty(ctx.db) } _ => unreachable!(), }; diff --git a/crates/ide_db/src/famous_defs.rs b/crates/ide_db/src/famous_defs.rs index cc9f2f9151..e6cbb55203 100644 --- a/crates/ide_db/src/famous_defs.rs +++ b/crates/ide_db/src/famous_defs.rs @@ -1,4 +1,6 @@ //! See [`FamousDefs`]. + +use base_db::{CrateOrigin, LangCrateOrigin, SourceDatabase}; use hir::{Crate, Enum, Macro, Module, ScopeDef, Semantics, Trait}; use crate::RootDatabase; @@ -21,11 +23,23 @@ pub struct FamousDefs<'a, 'b>(pub &'a Semantics<'b, RootDatabase>, pub Option { pub fn std(&self) -> Option { - self.find_crate("std") + self.find_lang_crate(LangCrateOrigin::Std) } pub fn core(&self) -> Option { - self.find_crate("core") + self.find_lang_crate(LangCrateOrigin::Core) + } + + pub fn alloc(&self) -> Option { + self.find_lang_crate(LangCrateOrigin::Alloc) + } + + pub fn test(&self) -> Option { + self.find_lang_crate(LangCrateOrigin::Test) + } + + pub fn proc_macro(&self) -> Option { + self.find_lang_crate(LangCrateOrigin::ProcMacro) } pub fn core_cmp_Ord(&self) -> Option { @@ -88,18 +102,6 @@ impl FamousDefs<'_, '_> { self.find_macro("core:macros:builtin:derive") } - pub fn alloc(&self) -> Option { - self.find_crate("alloc") - } - - pub fn test(&self) -> Option { - self.find_crate("test") - } - - pub fn proc_macro(&self) -> Option { - self.find_crate("proc_macro") - } - pub fn builtin_crates(&self) -> impl Iterator { IntoIterator::into_iter([ self.std(), @@ -139,11 +141,15 @@ impl FamousDefs<'_, '_> { } } - fn find_crate(&self, name: &str) -> Option { + fn find_lang_crate(&self, origin: LangCrateOrigin) -> Option { let krate = self.1?; let db = self.0.db; - let res = - krate.dependencies(db).into_iter().find(|dep| dep.name.to_smol_str() == name)?.krate; + let crate_graph = self.0.db.crate_graph(); + let res = krate + .dependencies(db) + .into_iter() + .find(|dep| crate_graph[dep.krate.into()].origin == CrateOrigin::Lang(origin))? + .krate; Some(res) } @@ -151,8 +157,16 @@ impl FamousDefs<'_, '_> { let db = self.0.db; let mut path = path.split(':'); let trait_ = path.next_back()?; - let std_crate = path.next()?; - let std_crate = self.find_crate(std_crate)?; + let lang_crate = path.next()?; + let lang_crate = match lang_crate { + "core" => LangCrateOrigin::Core, + "alloc" => LangCrateOrigin::Alloc, + "test" => LangCrateOrigin::Test, + "proc_macro" => LangCrateOrigin::ProcMacro, + "std" => LangCrateOrigin::Std, + _ => return None, + }; + let std_crate = self.find_lang_crate(lang_crate)?; let mut module = std_crate.root_module(db); for segment in path { module = module.children(db).find_map(|child| { diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index 805eac30b8..fe99c2e2ce 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs @@ -734,13 +734,7 @@ fn def_to_ty(sema: &Semantics, def: &Definition) -> Option Some(adt.ty(sema.db)), Definition::TypeAlias(it) => Some(it.ty(sema.db)), - Definition::BuiltinType(it) => { - let graph = sema.db.crate_graph(); - let krate = graph.iter().next()?; - let root_file = graph[krate].root_file_id; - let module = sema.to_module_def(root_file)?; - Some(it.ty(sema.db, module)) - } + Definition::BuiltinType(it) => Some(it.ty(sema.db)), Definition::SelfType(it) => Some(it.self_ty(sema.db)), _ => None, } diff --git a/crates/project_model/src/tests.rs b/crates/project_model/src/tests.rs index ca347d71a2..351e820ada 100644 --- a/crates/project_model/src/tests.rs +++ b/crates/project_model/src/tests.rs @@ -1261,7 +1261,9 @@ fn rust_project_hello_world_project_model() { }, ], proc_macro: [], - origin: Lang, + origin: Lang( + Alloc, + ), is_proc_macro: false, }, CrateId( @@ -1291,7 +1293,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Other, + ), is_proc_macro: false, }, CrateId( @@ -1321,7 +1325,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Other, + ), is_proc_macro: false, }, CrateId( @@ -1361,7 +1367,9 @@ fn rust_project_hello_world_project_model() { }, ], proc_macro: [], - origin: Lang, + origin: Lang( + ProcMacro, + ), is_proc_macro: false, }, CrateId( @@ -1391,7 +1399,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Core, + ), is_proc_macro: false, }, CrateId( @@ -1490,7 +1500,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Other, + ), is_proc_macro: false, }, CrateId( @@ -1520,7 +1532,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Other, + ), is_proc_macro: false, }, CrateId( @@ -1550,7 +1564,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Other, + ), is_proc_macro: false, }, CrateId( @@ -1580,7 +1596,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Test, + ), is_proc_macro: false, }, CrateId( @@ -1692,7 +1710,9 @@ fn rust_project_hello_world_project_model() { }, ], proc_macro: [], - origin: Lang, + origin: Lang( + Std, + ), is_proc_macro: false, }, CrateId( @@ -1722,7 +1742,9 @@ fn rust_project_hello_world_project_model() { }, dependencies: [], proc_macro: [], - origin: Lang, + origin: Lang( + Other, + ), is_proc_macro: false, }, }, diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index 1a86d232eb..509219f0b6 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -7,7 +7,7 @@ use std::{collections::VecDeque, fmt, fs, process::Command}; use anyhow::{format_err, Context, Result}; use base_db::{ CrateDisplayName, CrateGraph, CrateId, CrateName, CrateOrigin, Dependency, Edition, Env, - FileId, ProcMacro, + FileId, LangCrateOrigin, ProcMacro, }; use cfg::{CfgDiff, CfgOptions}; use paths::{AbsPath, AbsPathBuf}; @@ -487,7 +487,7 @@ fn project_json_to_crate_graph( if krate.display_name.is_some() { CrateOrigin::CratesIo { repo: krate.repository.clone() } } else { - CrateOrigin::Unknown + CrateOrigin::CratesIo { repo: None } }, ), ) @@ -710,7 +710,7 @@ fn detached_files_to_crate_graph( Env::default(), Vec::new(), false, - CrateOrigin::Unknown, + CrateOrigin::CratesIo { repo: None }, ); public_deps.add(detached_file_crate, &mut crate_graph); @@ -908,7 +908,14 @@ fn sysroot_to_crate_graph( env, proc_macro, false, - CrateOrigin::Lang, + CrateOrigin::Lang(match &*sysroot[krate].name { + "alloc" => LangCrateOrigin::Alloc, + "core" => LangCrateOrigin::Core, + "proc_macro" => LangCrateOrigin::ProcMacro, + "std" => LangCrateOrigin::Std, + "test" => LangCrateOrigin::Test, + _ => LangCrateOrigin::Other, + }), ); Some((krate, crate_id)) })