Skip to content

Commit

Permalink
Use std::fs::read_to_file in fluent_messages macro
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed Mar 31, 2023
1 parent c1d3610 commit f249832
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions compiler/rustc_macros/src/diagnostics/fluent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
use quote::quote;
use std::{
collections::{HashMap, HashSet},
fs::File,
io::Read,
fs::read_to_string,
path::{Path, PathBuf},
};
use syn::{parse_macro_input, Ident, LitStr};
Expand Down Expand Up @@ -95,22 +94,15 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok

// As this macro also outputs an `include_str!` for this file, the macro will always be
// re-executed when the file changes.
let mut resource_file = match File::open(absolute_ftl_path) {
Ok(resource_file) => resource_file,
let resource_contents = match read_to_string(absolute_ftl_path) {
Ok(resource_contents) => resource_contents,
Err(e) => {
Diagnostic::spanned(resource_span, Level::Error, "could not open Fluent resource")
.note(e.to_string())
.emit();
return failed(&crate_name);
}
};
let mut resource_contents = String::new();
if let Err(e) = resource_file.read_to_string(&mut resource_contents) {
Diagnostic::spanned(resource_span, Level::Error, "could not read Fluent resource")
.note(e.to_string())
.emit();
return failed(&crate_name);
}
let mut bad = false;
for esc in ["\\n", "\\\"", "\\'"] {
for _ in resource_contents.matches(esc) {
Expand Down

0 comments on commit f249832

Please sign in to comment.