@@ -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,25 @@ 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
+ // Make Windows verbatim paths work even with mixed path separators, which
163
+ // can happen when a path is produced using `concat!`.
164
+ let path_buf: PathBuf ;
165
+ if let Some ( Component :: Prefix ( prefix) ) = path. components ( ) . next ( ) {
166
+ if prefix. kind ( ) . is_verbatim ( ) {
167
+ path_buf = path. components ( ) . collect ( ) ;
168
+ path = & path_buf;
169
+ }
170
+ }
171
+
161
172
match fs:: read_to_string ( path) {
162
173
Ok ( content) => Ok ( content) ,
163
174
Err ( err) => Err ( Error :: new_spanned (
0 commit comments