@@ -21,7 +21,6 @@ use symbol::Symbol;
2121use tokenstream;
2222use util:: small_vector:: SmallVector ;
2323
24- use std:: fs:: File ;
2524use std:: io:: prelude:: * ;
2625use std:: path:: PathBuf ;
2726use rustc_data_structures:: sync:: Lrc ;
@@ -99,7 +98,18 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[tokenstream::T
9998 None => return DummyResult :: expr ( sp) ,
10099 } ;
101100 // The file will be added to the code map by the parser
102- let path = res_rel_file ( cx, sp, file) ;
101+ let path = res_rel_file ( cx, sp, file. clone ( ) ) ;
102+ let env_sb = cx. parse_sess ( ) . env_sandbox ( ) ;
103+ let path = match env_sb. path_lookup ( & path) {
104+ Ok ( path) => path,
105+ Err ( e) => {
106+ cx. span_err ( sp,
107+ & format ! ( "couldn't read {}: {}" ,
108+ file,
109+ e) ) ;
110+ return DummyResult :: expr ( sp) ;
111+ }
112+ } ;
103113 let directory_ownership = DirectoryOwnership :: Owned { relative : None } ;
104114 let p = parse:: new_sub_parser_from_file ( cx. parse_sess ( ) , & path, directory_ownership, None , sp) ;
105115
@@ -136,9 +146,10 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT
136146 Some ( f) => f,
137147 None => return DummyResult :: expr ( sp)
138148 } ;
149+ let env_sb = cx. parse_sess ( ) . env_sandbox ( ) ;
139150 let file = res_rel_file ( cx, sp, file) ;
140151 let mut bytes = Vec :: new ( ) ;
141- match File :: open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
152+ match env_sb . path_open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
142153 Ok ( ..) => { }
143154 Err ( e) => {
144155 cx. span_err ( sp,
@@ -171,9 +182,10 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke
171182 Some ( f) => f,
172183 None => return DummyResult :: expr ( sp)
173184 } ;
185+ let env_sb = cx. parse_sess ( ) . env_sandbox ( ) ;
174186 let file = res_rel_file ( cx, sp, file) ;
175187 let mut bytes = Vec :: new ( ) ;
176- match File :: open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
188+ match env_sb . path_open ( & file) . and_then ( |mut f| f. read_to_end ( & mut bytes) ) {
177189 Err ( e) => {
178190 cx. span_err ( sp,
179191 & format ! ( "couldn't read {}: {}" , file. display( ) , e) ) ;
0 commit comments