This repository was archived by the owner on Dec 29, 2022. It is now read-only.
File tree 4 files changed +22
-29
lines changed
4 files changed +22
-29
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,6 @@ pub mod file_loader {
24
24
#[ rpc( name = "file_exists" ) ]
25
25
fn file_exists ( & self , path : PathBuf ) -> Result < bool > ;
26
26
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
-
31
27
/// Read the contents of an UTF-8 file into memory.
32
28
#[ rpc( name = "read_file" ) ]
33
29
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 {
34
34
self . 0 . file_exists ( path. to_owned ( ) ) . wait ( ) . unwrap ( )
35
35
}
36
36
37
- fn abs_path ( & self , path : & Path ) -> Option < PathBuf > {
38
- self . 0 . abs_path ( path. to_owned ( ) ) . wait ( ) . ok ( ) ?
39
- }
40
-
41
37
fn read_file ( & self , path : & Path ) -> io:: Result < String > {
42
38
self . 0
43
39
. 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>);
140
140
141
141
impl rpc:: file_loader:: Rpc for ChangedFiles {
142
142
fn file_exists ( & self , path : PathBuf ) -> RpcResult < bool > {
143
- // Copied from syntax::source_map::RealFileLoader
144
143
Ok ( fs:: metadata ( path) . is_ok ( ) )
145
144
}
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
+
154
146
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 ( ) ) ;
159
149
}
160
150
161
151
fs:: read_to_string ( path) . map_err ( |e| rpc_error ( & e. to_string ( ) ) )
162
152
}
163
153
}
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 {
367
367
self . real_file_loader . file_exists ( path)
368
368
}
369
369
370
- fn abs_path ( & self , path : & Path ) -> Option < PathBuf > {
371
- self . real_file_loader . abs_path ( path)
372
- }
373
-
374
370
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 ( ) ) ;
379
373
}
374
+
380
375
self . real_file_loader . read_file ( path)
381
376
}
382
377
}
383
378
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
+
384
387
pub ( super ) fn current_sysroot ( ) -> Option < String > {
385
388
let home = env:: var ( "RUSTUP_HOME" ) . or_else ( |_| env:: var ( "MULTIRUST_HOME" ) ) ;
386
389
let toolchain = env:: var ( "RUSTUP_TOOLCHAIN" ) . or_else ( |_| env:: var ( "MULTIRUST_TOOLCHAIN" ) ) ;
You can’t perform that action at this time.
0 commit comments