Skip to content

Commit f16b9b2

Browse files
committed
Remove space in f ".." for Rust 2021.
1 parent 2506a36 commit f16b9b2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

macros/src/embed_python.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,16 @@ impl EmbedPython {
109109
self.loc = token.span().unwrap().end();
110110
}
111111
TokenTree::Literal(x) => {
112-
write!(&mut self.python, "{}", x).unwrap();
112+
let s = x.to_string();
113+
// Remove space in prefixed strings like `f ".."`.
114+
// (`f".."` is not allowed in some versions+editions of Rust.)
115+
if s.starts_with('"')
116+
&& self.python.ends_with(' ')
117+
&& self.python[..self.python.len() - 1].ends_with(|c: char| c.is_ascii_alphabetic())
118+
{
119+
self.python.pop();
120+
}
121+
self.python += &s;
113122
self.loc = token.span().unwrap().end();
114123
}
115124
}

0 commit comments

Comments
 (0)