This repository was archived by the owner on Dec 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,10 +24,6 @@ pub mod file_loader {
2424 #[ rpc( name = "file_exists" ) ]
2525 fn file_exists ( & self , path : PathBuf ) -> Result < bool > ;
2626
27- /// Returns an absolute path to a file, if possible.
28- #[ rpc( name = "abs_path" ) ]
29- fn abs_path ( & self , path : PathBuf ) -> Result < Option < PathBuf > > ;
30-
3127 /// Read the contents of an UTF-8 file into memory.
3228 #[ rpc( name = "read_file" ) ]
3329 fn read_file ( & self , path : PathBuf ) -> Result < String > ;
Original file line number Diff line number Diff line change @@ -34,10 +34,6 @@ impl rustc_span::source_map::FileLoader for IpcFileLoader {
3434 self . 0 . file_exists ( path. to_owned ( ) ) . wait ( ) . unwrap ( )
3535 }
3636
37- fn abs_path ( & self , path : & Path ) -> Option < PathBuf > {
38- self . 0 . abs_path ( path. to_owned ( ) ) . wait ( ) . ok ( ) ?
39- }
40-
4137 fn read_file ( & self , path : & Path ) -> io:: Result < String > {
4238 self . 0
4339 . read_file ( path. to_owned ( ) )
Original file line number Diff line number Diff line change @@ -140,24 +140,22 @@ pub struct ChangedFiles(HashMap<PathBuf, String>);
140140
141141impl rpc:: file_loader:: Rpc for ChangedFiles {
142142 fn file_exists ( & self , path : PathBuf ) -> RpcResult < bool > {
143- // Copied from syntax::source_map::RealFileLoader
144143 Ok ( fs:: metadata ( path) . is_ok ( ) )
145144 }
146- fn abs_path ( & self , path : PathBuf ) -> RpcResult < Option < PathBuf > > {
147- // Copied from syntax::source_map::RealFileLoader
148- Ok ( if path. is_absolute ( ) {
149- Some ( path. to_path_buf ( ) )
150- } else {
151- env:: current_dir ( ) . ok ( ) . map ( |cwd| cwd. join ( path) )
152- } )
153- }
145+
154146 fn read_file ( & self , path : PathBuf ) -> RpcResult < String > {
155- if let Some ( abs_path) = self . abs_path ( path. clone ( ) ) . ok ( ) . and_then ( |x| x) {
156- if self . 0 . contains_key ( & abs_path) {
157- return Ok ( self . 0 [ & abs_path] . clone ( ) ) ;
158- }
147+ if let Some ( contents) = abs_path ( & path) . and_then ( |x| self . 0 . get ( & x) ) {
148+ return Ok ( contents. clone ( ) ) ;
159149 }
160150
161151 fs:: read_to_string ( path) . map_err ( |e| rpc_error ( & e. to_string ( ) ) )
162152 }
163153}
154+
155+ fn abs_path ( path : & Path ) -> Option < PathBuf > {
156+ if path. is_absolute ( ) {
157+ Some ( path. to_path_buf ( ) )
158+ } else {
159+ env:: current_dir ( ) . ok ( ) . map ( |cwd| cwd. join ( path) )
160+ }
161+ }
Original file line number Diff line number Diff line change @@ -367,20 +367,23 @@ impl FileLoader for ReplacedFileLoader {
367367 self . real_file_loader . file_exists ( path)
368368 }
369369
370- fn abs_path ( & self , path : & Path ) -> Option < PathBuf > {
371- self . real_file_loader . abs_path ( path)
372- }
373-
374370 fn read_file ( & self , path : & Path ) -> io:: Result < String > {
375- if let Some ( abs_path) = self . abs_path ( path) {
376- if self . replacements . contains_key ( & abs_path) {
377- return Ok ( self . replacements [ & abs_path] . clone ( ) ) ;
378- }
371+ if let Some ( contents) = abs_path ( path) . and_then ( |x| self . replacements . get ( & x) ) {
372+ return Ok ( contents. clone ( ) ) ;
379373 }
374+
380375 self . real_file_loader . read_file ( path)
381376 }
382377}
383378
379+ fn abs_path ( path : & Path ) -> Option < PathBuf > {
380+ if path. is_absolute ( ) {
381+ Some ( path. to_path_buf ( ) )
382+ } else {
383+ env:: current_dir ( ) . ok ( ) . map ( |cwd| cwd. join ( path) )
384+ }
385+ }
386+
384387pub ( super ) fn current_sysroot ( ) -> Option < String > {
385388 let home = env:: var ( "RUSTUP_HOME" ) . or_else ( |_| env:: var ( "MULTIRUST_HOME" ) ) ;
386389 let toolchain = env:: var ( "RUSTUP_TOOLCHAIN" ) . or_else ( |_| env:: var ( "MULTIRUST_TOOLCHAIN" ) ) ;
You can’t perform that action at this time.
0 commit comments