Skip to content

Commit f249832

Browse files
committed
Use std::fs::read_to_file in fluent_messages macro
1 parent c1d3610 commit f249832

File tree

1 file changed

+3
-11
lines changed
  • compiler/rustc_macros/src/diagnostics

1 file changed

+3
-11
lines changed

compiler/rustc_macros/src/diagnostics/fluent.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
1515
use quote::quote;
1616
use std::{
1717
collections::{HashMap, HashSet},
18-
fs::File,
19-
io::Read,
18+
fs::read_to_string,
2019
path::{Path, PathBuf},
2120
};
2221
use syn::{parse_macro_input, Ident, LitStr};
@@ -95,22 +94,15 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
9594

9695
// As this macro also outputs an `include_str!` for this file, the macro will always be
9796
// re-executed when the file changes.
98-
let mut resource_file = match File::open(absolute_ftl_path) {
99-
Ok(resource_file) => resource_file,
97+
let resource_contents = match read_to_string(absolute_ftl_path) {
98+
Ok(resource_contents) => resource_contents,
10099
Err(e) => {
101100
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
102101
.note(e.to_string())
103102
.emit();
104103
return failed(&crate_name);
105104
}
106105
};
107-
let mut resource_contents = String::new();
108-
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
109-
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
110-
.note(e.to_string())
111-
.emit();
112-
return failed(&crate_name);
113-
}
114106
let mut bad = false;
115107
for esc in ["\\n", "\\\"", "\\'"] {
116108
for _ in resource_contents.matches(esc) {

0 commit comments

Comments
 (0)