From 2976bf450b055a4477f058134f6e9734d538538b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sat, 20 Jun 2020 02:12:17 +0200 Subject: [PATCH] Make procedural-masquerade resilient to macro input pretty-printing changes CC https://github.com/rust-lang/rust/pull/73345#issuecomment-646895843 --- procedural-masquerade/Cargo.toml | 2 +- procedural-masquerade/lib.rs | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/procedural-masquerade/Cargo.toml b/procedural-masquerade/Cargo.toml index b833f1bf..66638a31 100644 --- a/procedural-masquerade/Cargo.toml +++ b/procedural-masquerade/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "procedural-masquerade" -version = "0.1.6" +version = "0.1.7" authors = ["Simon Sapin "] description = "macro_rules for making proc_macro_derive pretending to be proc_macro" documentation = "https://docs.rs/procedural-masquerade/" diff --git a/procedural-masquerade/lib.rs b/procedural-masquerade/lib.rs index 2736ccf5..4b51e149 100644 --- a/procedural-masquerade/lib.rs +++ b/procedural-masquerade/lib.rs @@ -199,14 +199,23 @@ pub fn _extract_input(derive_input: &str) -> &str { let mut input = derive_input; for expected in &[ - "#[allow(unused)]", + "#", + "[", + "allow", + "(", + "unused", + ")", + "]", "enum", "ProceduralMasqueradeDummyType", "{", "Input", "=", - "(0,", - "stringify!", + "(", + "0", + ",", + "stringify", + "!", "(", ] { input = input.trim_start(); @@ -219,7 +228,7 @@ pub fn _extract_input(derive_input: &str) -> &str { input = &input[expected.len()..]; } - for expected in [")", ").0,", "}"].iter().rev() { + for expected in [")", ")", ".", "0", ",", "}"].iter().rev() { input = input.trim_end(); assert!( input.ends_with(expected), @@ -268,7 +277,7 @@ macro_rules! define_invoke_proc_macro { // which is then ignored. // Using `stringify!` enables passing arbitrary tokens // rather than only what can be parsed as a const expression. - Input = (0, stringify! $paren ).0 + Input = (0, stringify! $paren ).0, } } }