Skip to content

Commit 2976bf4

Browse files
committed
Make procedural-masquerade resilient to macro input pretty-printing changes
CC rust-lang/rust#73345 (comment)
1 parent 7c9854e commit 2976bf4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

procedural-masquerade/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "procedural-masquerade"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors = ["Simon Sapin <[email protected]>"]
55
description = "macro_rules for making proc_macro_derive pretending to be proc_macro"
66
documentation = "https://docs.rs/procedural-masquerade/"

procedural-masquerade/lib.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,23 @@ pub fn _extract_input(derive_input: &str) -> &str {
199199
let mut input = derive_input;
200200

201201
for expected in &[
202-
"#[allow(unused)]",
202+
"#",
203+
"[",
204+
"allow",
205+
"(",
206+
"unused",
207+
")",
208+
"]",
203209
"enum",
204210
"ProceduralMasqueradeDummyType",
205211
"{",
206212
"Input",
207213
"=",
208-
"(0,",
209-
"stringify!",
214+
"(",
215+
"0",
216+
",",
217+
"stringify",
218+
"!",
210219
"(",
211220
] {
212221
input = input.trim_start();
@@ -219,7 +228,7 @@ pub fn _extract_input(derive_input: &str) -> &str {
219228
input = &input[expected.len()..];
220229
}
221230

222-
for expected in [")", ").0,", "}"].iter().rev() {
231+
for expected in [")", ")", ".", "0", ",", "}"].iter().rev() {
223232
input = input.trim_end();
224233
assert!(
225234
input.ends_with(expected),
@@ -268,7 +277,7 @@ macro_rules! define_invoke_proc_macro {
268277
// which is then ignored.
269278
// Using `stringify!` enables passing arbitrary tokens
270279
// rather than only what can be parsed as a const expression.
271-
Input = (0, stringify! $paren ).0
280+
Input = (0, stringify! $paren ).0,
272281
}
273282
}
274283
}

0 commit comments

Comments
 (0)