about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics/fluent.rs
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2023-03-31 03:04:09 +0200
committerest31 <MTest31@outlook.com>2023-03-31 03:18:30 +0200
commitf24983222d207096851344f7551f0f4ec5cc2a61 (patch)
tree212ae844d1ef7ca516ec6945a73a14bea832830d /compiler/rustc_macros/src/diagnostics/fluent.rs
parentc1d3610ac1ddd1cd605479274047fd0a3f37d220 (diff)
downloadrust-f24983222d207096851344f7551f0f4ec5cc2a61.tar.gz
rust-f24983222d207096851344f7551f0f4ec5cc2a61.zip
Use std::fs::read_to_file in fluent_messages macro
Diffstat (limited to 'compiler/rustc_macros/src/diagnostics/fluent.rs')
-rw-r--r--compiler/rustc_macros/src/diagnostics/fluent.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/fluent.rs b/compiler/rustc_macros/src/diagnostics/fluent.rs
index 3b2f5cfdc73..42a1fc147f7 100644
--- a/compiler/rustc_macros/src/diagnostics/fluent.rs
+++ b/compiler/rustc_macros/src/diagnostics/fluent.rs
@@ -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};
@@ -95,8 +94,8 @@ 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())
@@ -104,13 +103,6 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
             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) {