Skip to content

Commit 22505a8

Browse files
committed
---
yaml --- r: 207014 b: refs/heads/tmp c: 0d50b04 h: refs/heads/master v: v3
1 parent f84e309 commit 22505a8

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: cd7d89af9169885642d43597302af69f842bbd78
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: 6a59d1824d11b6452463fcc23ad64cd142dfa203
35+
refs/heads/tmp: 0d50b043f748bf9a07b28a8f734327258204e26b
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: 571f371b3fce3e023fb1b41a1682de260c943222
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/src/libsyntax/parse/mod.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,30 +221,16 @@ pub fn new_parser_from_tts<'a>(sess: &'a ParseSess,
221221
/// Given a session and a path and an optional span (for error reporting),
222222
/// add the path to the session's codemap and return the new filemap.
223223
pub fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
224-
-> Rc<FileMap> {
225-
let err = |msg: &str| {
224+
-> Rc<FileMap> {
225+
let mut contents = String::new();
226+
if let Err(e) = File::open(path).and_then(|mut f| f.read_to_string(&mut contents)) {
227+
let msg = format!("couldn't read {:?}: {}", path.display(), e);
226228
match spanopt {
227-
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, msg)),
228-
None => sess.span_diagnostic.handler().fatal(msg),
229-
}
230-
};
231-
let mut bytes = Vec::new();
232-
match File::open(path).and_then(|mut f| f.read_to_end(&mut bytes)) {
233-
Ok(..) => {}
234-
Err(e) => {
235-
err(&format!("couldn't read {:?}: {}", path.display(), e));
236-
unreachable!();
237-
}
238-
};
239-
match str::from_utf8(&bytes[..]).ok() {
240-
Some(s) => {
241-
sess.codemap().new_filemap(path.to_str().unwrap().to_string(), s.to_string())
242-
}
243-
None => {
244-
err(&format!("{:?} is not UTF-8 encoded", path.display()));
245-
unreachable!();
229+
Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)),
230+
None => sess.span_diagnostic.handler().fatal(&msg)
246231
}
247232
}
233+
sess.codemap().new_filemap(path.to_str().unwrap().to_string(), contents)
248234
}
249235

250236
/// Given a filemap, produce a sequence of token-trees

0 commit comments

Comments
 (0)