@@ -15,8 +15,7 @@ use proc_macro2::TokenStream;
1515use quote:: quote;
1616use std:: {
1717 collections:: { HashMap , HashSet } ,
18- fs:: File ,
19- io:: Read ,
18+ fs:: read_to_string,
2019 path:: { Path , PathBuf } ,
2120} ;
2221use syn:: { parse_macro_input, Ident , LitStr } ;
@@ -95,22 +94,18 @@ 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) => {
101- Diagnostic :: spanned ( resource_span, Level :: Error , "could not open Fluent resource" )
102- . note ( e. to_string ( ) )
103- . emit ( ) ;
100+ Diagnostic :: spanned (
101+ resource_span,
102+ Level :: Error ,
103+ format ! ( "could not open Fluent resource: {}" , e. to_string( ) ) ,
104+ )
105+ . emit ( ) ;
104106 return failed ( & crate_name) ;
105107 }
106108 } ;
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- }
114109 let mut bad = false ;
115110 for esc in [ "\\ n" , "\\ \" " , "\\ '" ] {
116111 for _ in resource_contents. matches ( esc) {
0 commit comments