@@ -73,7 +73,7 @@ use proc_macro2::TokenStream;
73
73
use quote:: { quote, ToTokens } ;
74
74
use std:: env;
75
75
use std:: fs;
76
- use std:: path:: Path ;
76
+ use std:: path:: { Component , Path , PathBuf } ;
77
77
use syn:: parse:: { Error , Parse , ParseBuffer , ParseStream , Parser , Result } ;
78
78
use syn:: punctuated:: Punctuated ;
79
79
use syn:: token:: { Brace , Bracket , Paren } ;
@@ -150,14 +150,26 @@ impl Expr {
150
150
}
151
151
152
152
fn fs_read ( span : & dyn ToTokens , path : impl AsRef < Path > ) -> Result < String > {
153
- let path = path. as_ref ( ) ;
153
+ let mut path = path. as_ref ( ) ;
154
154
if path. is_relative ( ) {
155
155
let name = span. to_token_stream ( ) . into_iter ( ) . next ( ) . unwrap ( ) ;
156
156
return Err ( Error :: new_spanned (
157
157
span,
158
158
format ! ( "a relative path is not supported here; use `{name}!(concat!(env!(\" CARGO_MANIFEST_DIR\" ), ...))`" ) ,
159
159
) ) ;
160
160
}
161
+
162
+ // This ensures that Windows verbatim paths are fixed if mixed path
163
+ // separators are used, which can happen when `concat!` is used to join
164
+ // paths.
165
+ let path_buf: PathBuf ;
166
+ if let Some ( Component :: Prefix ( prefix) ) = path. components ( ) . next ( ) {
167
+ if prefix. kind ( ) . is_verbatim ( ) {
168
+ path_buf = path. components ( ) . collect ( ) ;
169
+ path = & path_buf;
170
+ }
171
+ }
172
+
161
173
match fs:: read_to_string ( path) {
162
174
Ok ( content) => Ok ( content) ,
163
175
Err ( err) => Err ( Error :: new_spanned (
0 commit comments