44//! but we can't process `.rlib` and need source code instead. The source code
55//! is typically installed with `rustup component add rust-src` command.
66
7- use std:: {
8- env, fs,
9- ops:: { self , Not } ,
10- path:: Path ,
11- process:: Command ,
12- } ;
7+ use std:: { env, fs, ops:: Not , path:: Path , process:: Command } ;
138
149use anyhow:: { format_err, Result } ;
15- use base_db:: CrateName ;
1610use itertools:: Itertools ;
17- use la_arena:: { Arena , Idx } ;
1811use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
1912use rustc_hash:: FxHashMap ;
2013use stdx:: format_to;
@@ -37,58 +30,9 @@ pub struct Sysroot {
3730pub enum RustLibSrcWorkspace {
3831 Workspace ( CargoWorkspace ) ,
3932 Json ( ProjectJson ) ,
40- Stitched ( Stitched ) ,
4133 Empty ,
4234}
4335
44- #[ derive( Debug , Clone , Eq , PartialEq ) ]
45- pub struct Stitched {
46- crates : Arena < RustLibSrcCrateData > ,
47- }
48-
49- impl ops:: Index < RustLibSrcCrate > for Stitched {
50- type Output = RustLibSrcCrateData ;
51- fn index ( & self , index : RustLibSrcCrate ) -> & RustLibSrcCrateData {
52- & self . crates [ index]
53- }
54- }
55-
56- impl Stitched {
57- pub ( crate ) fn public_deps (
58- & self ,
59- ) -> impl Iterator < Item = ( CrateName , RustLibSrcCrate , bool ) > + ' _ {
60- // core is added as a dependency before std in order to
61- // mimic rustcs dependency order
62- [ ( "core" , true ) , ( "alloc" , false ) , ( "std" , true ) , ( "test" , false ) ] . into_iter ( ) . filter_map (
63- move |( name, prelude) | {
64- Some ( ( CrateName :: new ( name) . unwrap ( ) , self . by_name ( name) ?, prelude) )
65- } ,
66- )
67- }
68-
69- pub ( crate ) fn proc_macro ( & self ) -> Option < RustLibSrcCrate > {
70- self . by_name ( "proc_macro" )
71- }
72-
73- pub ( crate ) fn crates ( & self ) -> impl ExactSizeIterator < Item = RustLibSrcCrate > + ' _ {
74- self . crates . iter ( ) . map ( |( id, _data) | id)
75- }
76-
77- fn by_name ( & self , name : & str ) -> Option < RustLibSrcCrate > {
78- let ( id, _data) = self . crates . iter ( ) . find ( |( _id, data) | data. name == name) ?;
79- Some ( id)
80- }
81- }
82-
83- pub ( crate ) type RustLibSrcCrate = Idx < RustLibSrcCrateData > ;
84-
85- #[ derive( Debug , Clone , Eq , PartialEq ) ]
86- pub ( crate ) struct RustLibSrcCrateData {
87- pub ( crate ) name : String ,
88- pub ( crate ) root : ManifestPath ,
89- pub ( crate ) deps : Vec < RustLibSrcCrate > ,
90- }
91-
9236impl Sysroot {
9337 pub const fn empty ( ) -> Sysroot {
9438 Sysroot {
@@ -116,7 +60,6 @@ impl Sysroot {
11660 match & self . workspace {
11761 RustLibSrcWorkspace :: Workspace ( ws) => ws. packages ( ) . next ( ) . is_none ( ) ,
11862 RustLibSrcWorkspace :: Json ( project_json) => project_json. n_crates ( ) == 0 ,
119- RustLibSrcWorkspace :: Stitched ( stitched) => stitched. crates . is_empty ( ) ,
12063 RustLibSrcWorkspace :: Empty => true ,
12164 }
12265 }
@@ -129,7 +72,6 @@ impl Sysroot {
12972 match & self . workspace {
13073 RustLibSrcWorkspace :: Workspace ( ws) => ws. packages ( ) . count ( ) ,
13174 RustLibSrcWorkspace :: Json ( project_json) => project_json. n_crates ( ) ,
132- RustLibSrcWorkspace :: Stitched ( c) => c. crates ( ) . count ( ) ,
13375 RustLibSrcWorkspace :: Empty => 0 ,
13476 }
13577 }
@@ -258,51 +200,8 @@ impl Sysroot {
258200 } else if let RustSourceWorkspaceConfig :: Json ( project_json) = sysroot_source_config {
259201 return Some ( RustLibSrcWorkspace :: Json ( project_json. clone ( ) ) ) ;
260202 }
261- tracing:: debug!( "Stitching sysroot library: {src_root}" ) ;
262-
263- let mut stitched = Stitched { crates : Arena :: default ( ) } ;
264-
265- for path in SYSROOT_CRATES . trim ( ) . lines ( ) {
266- let name = path. split ( '/' ) . last ( ) . unwrap ( ) ;
267- let root = [ format ! ( "{path}/src/lib.rs" ) , format ! ( "lib{path}/lib.rs" ) ]
268- . into_iter ( )
269- . map ( |it| src_root. join ( it) )
270- . filter_map ( |it| ManifestPath :: try_from ( it) . ok ( ) )
271- . find ( |it| fs:: metadata ( it) . is_ok ( ) ) ;
272-
273- if let Some ( root) = root {
274- stitched. crates . alloc ( RustLibSrcCrateData {
275- name : name. into ( ) ,
276- root,
277- deps : Vec :: new ( ) ,
278- } ) ;
279- }
280- }
281-
282- if let Some ( std) = stitched. by_name ( "std" ) {
283- for dep in STD_DEPS . trim ( ) . lines ( ) {
284- if let Some ( dep) = stitched. by_name ( dep) {
285- stitched. crates [ std] . deps . push ( dep)
286- }
287- }
288- }
289-
290- if let Some ( alloc) = stitched. by_name ( "alloc" ) {
291- for dep in ALLOC_DEPS . trim ( ) . lines ( ) {
292- if let Some ( dep) = stitched. by_name ( dep) {
293- stitched. crates [ alloc] . deps . push ( dep)
294- }
295- }
296- }
297203
298- if let Some ( proc_macro) = stitched. by_name ( "proc_macro" ) {
299- for dep in PROC_MACRO_DEPS . trim ( ) . lines ( ) {
300- if let Some ( dep) = stitched. by_name ( dep) {
301- stitched. crates [ proc_macro] . deps . push ( dep)
302- }
303- }
304- }
305- Some ( RustLibSrcWorkspace :: Stitched ( stitched) )
204+ None
306205 }
307206
308207 pub fn set_workspace ( & mut self , workspace : RustLibSrcWorkspace ) {
@@ -317,7 +216,6 @@ impl Sysroot {
317216 . crates ( )
318217 . filter_map ( |( _, krate) | krate. display_name . clone ( ) )
319218 . any ( |name| name. canonical_name ( ) . as_str ( ) == "core" ) ,
320- RustLibSrcWorkspace :: Stitched ( stitched) => stitched. by_name ( "core" ) . is_some ( ) ,
321219 RustLibSrcWorkspace :: Empty => true ,
322220 } ;
323221 if !has_core {
@@ -493,33 +391,3 @@ fn get_rust_lib_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
493391 None
494392 }
495393}
496-
497- const SYSROOT_CRATES : & str = "
498- alloc
499- backtrace
500- core
501- panic_abort
502- panic_unwind
503- proc_macro
504- profiler_builtins
505- std
506- stdarch/crates/std_detect
507- test
508- unwind" ;
509-
510- const ALLOC_DEPS : & str = "core" ;
511-
512- const STD_DEPS : & str = "
513- alloc
514- panic_unwind
515- panic_abort
516- core
517- profiler_builtins
518- unwind
519- std_detect
520- test" ;
521-
522- // core is required for our builtin derives to work in the proc_macro lib currently
523- const PROC_MACRO_DEPS : & str = "
524- std
525- core" ;
0 commit comments