@@ -57,14 +57,26 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
57
57
crates_indexes [display_name ] = len (crates )
58
58
crates .append (crate )
59
59
60
- # First, the ones in `rust/` since they are a bit special.
61
- append_crate (
62
- "core" ,
63
- sysroot_src / "core" / "src" / "lib.rs" ,
64
- [],
65
- cfg = crates_cfgs .get ("core" , []),
66
- is_workspace_member = False ,
67
- )
60
+ def append_sysroot_crate (
61
+ display_name ,
62
+ deps ,
63
+ cfg = [],
64
+ ):
65
+ append_crate (
66
+ display_name ,
67
+ sysroot_src / display_name / "src" / "lib.rs" ,
68
+ deps ,
69
+ cfg ,
70
+ is_workspace_member = False ,
71
+ )
72
+
73
+ # NB: sysroot crates reexport items from one another so setting up our transitive dependencies
74
+ # here is important for ensuring that rust-analyzer can resolve symbols. The sources of truth
75
+ # for this dependency graph are `(sysroot_src / crate / "Cargo.toml" for crate in crates)`.
76
+ append_sysroot_crate ("core" , [], cfg = crates_cfgs .get ("core" , []))
77
+ append_sysroot_crate ("alloc" , ["core" ])
78
+ append_sysroot_crate ("std" , ["alloc" , "core" ])
79
+ append_sysroot_crate ("proc_macro" , ["core" , "std" ])
68
80
69
81
append_crate (
70
82
"compiler_builtins" ,
@@ -75,7 +87,7 @@ def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=Tr
75
87
append_crate (
76
88
"macros" ,
77
89
srctree / "rust" / "macros" / "lib.rs" ,
78
- [],
90
+ ["std" , "proc_macro" ],
79
91
is_proc_macro = True ,
80
92
)
81
93
0 commit comments