@@ -9,8 +9,6 @@ use syntax::tokenstream;
99use smallvec:: SmallVec ;
1010use syntax_pos:: { self , Pos , Span } ;
1111
12- use std:: fs;
13- use std:: io:: ErrorKind ;
1412use rustc_data_structures:: sync:: Lrc ;
1513
1614// These macros all relate to the file system; they either return
@@ -114,20 +112,17 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::To
114112 None => return DummyResult :: any ( sp)
115113 } ;
116114 let file = cx. resolve_path ( file, sp) ;
117- match fs:: read_to_string ( & file) {
118- Ok ( src) => {
119- let interned_src = Symbol :: intern ( & src) ;
120-
121- // Add this input file to the code map to make it available as
122- // dependency information
123- cx. source_map ( ) . new_source_file ( file. into ( ) , src) ;
124-
125- base:: MacEager :: expr ( cx. expr_str ( sp, interned_src) )
115+ match cx. source_map ( ) . load_binary_file ( & file) {
116+ Ok ( bytes) => match std:: str:: from_utf8 ( & bytes) {
117+ Ok ( src) => {
118+ let interned_src = Symbol :: intern ( & src) ;
119+ base:: MacEager :: expr ( cx. expr_str ( sp, interned_src) )
120+ }
121+ Err ( _) => {
122+ cx. span_err ( sp, & format ! ( "{} wasn't a utf-8 file" , file. display( ) ) ) ;
123+ DummyResult :: any ( sp)
124+ }
126125 } ,
127- Err ( ref e) if e. kind ( ) == ErrorKind :: InvalidData => {
128- cx. span_err ( sp, & format ! ( "{} wasn't a utf-8 file" , file. display( ) ) ) ;
129- DummyResult :: any ( sp)
130- }
131126 Err ( e) => {
132127 cx. span_err ( sp, & format ! ( "couldn't read {}: {}" , file. display( ) , e) ) ;
133128 DummyResult :: any ( sp)
@@ -142,18 +137,8 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::
142137 None => return DummyResult :: any ( sp)
143138 } ;
144139 let file = cx. resolve_path ( file, sp) ;
145- match fs :: read ( & file) {
140+ match cx . source_map ( ) . load_binary_file ( & file) {
146141 Ok ( bytes) => {
147- // Add the contents to the source map if it contains UTF-8.
148- let ( contents, bytes) = match String :: from_utf8 ( bytes) {
149- Ok ( s) => {
150- let bytes = s. as_bytes ( ) . to_owned ( ) ;
151- ( s, bytes)
152- } ,
153- Err ( e) => ( String :: new ( ) , e. into_bytes ( ) ) ,
154- } ;
155- cx. source_map ( ) . new_source_file ( file. into ( ) , contents) ;
156-
157142 base:: MacEager :: expr ( cx. expr_lit ( sp, ast:: LitKind :: ByteStr ( Lrc :: new ( bytes) ) ) )
158143 } ,
159144 Err ( e) => {
0 commit comments