@@ -9,8 +9,6 @@ use syntax::tokenstream;
9
9
use smallvec:: SmallVec ;
10
10
use syntax_pos:: { self , Pos , Span } ;
11
11
12
- use std:: fs;
13
- use std:: io:: ErrorKind ;
14
12
use rustc_data_structures:: sync:: Lrc ;
15
13
16
14
// 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
114
112
None => return DummyResult :: any ( sp)
115
113
} ;
116
114
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
+ }
126
125
} ,
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
- }
131
126
Err ( e) => {
132
127
cx. span_err ( sp, & format ! ( "couldn't read {}: {}" , file. display( ) , e) ) ;
133
128
DummyResult :: any ( sp)
@@ -142,18 +137,8 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::
142
137
None => return DummyResult :: any ( sp)
143
138
} ;
144
139
let file = cx. resolve_path ( file, sp) ;
145
- match fs :: read ( & file) {
140
+ match cx . source_map ( ) . load_binary_file ( & file) {
146
141
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
-
157
142
base:: MacEager :: expr ( cx. expr_lit ( sp, ast:: LitKind :: ByteStr ( Lrc :: new ( bytes) ) ) )
158
143
} ,
159
144
Err ( e) => {
0 commit comments