From 369ca722e97d9e21faca681d9df88c8d841f872e Mon Sep 17 00:00:00 2001 From: Yacin Tmimi Date: Mon, 27 Sep 2021 16:55:23 -0400 Subject: [PATCH] Prevent removal of qualified path for tuple struct inside macro fixes 5005 This was very similar to 4964 and the fix was to extract and pass along the qself of the ``PatKind::TupleStruct`` --- src/patterns.rs | 5 +++-- tests/target/issue-5005/minimum_example.rs | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tests/target/issue-5005/minimum_example.rs diff --git a/src/patterns.rs b/src/patterns.rs index 0c6a6f3e814..4c6a2d5d75b 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -226,8 +226,9 @@ impl Rewrite for Pat { PatKind::Path(ref q_self, ref path) => { rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape) } - PatKind::TupleStruct(_, ref path, ref pat_vec) => { - let path_str = rewrite_path(context, PathContext::Expr, None, path, shape)?; + PatKind::TupleStruct(ref q_self, ref path, ref pat_vec) => { + let path_str = + rewrite_path(context, PathContext::Expr, q_self.as_ref(), path, shape)?; rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape) } PatKind::Lit(ref expr) => expr.rewrite(context, shape), diff --git a/tests/target/issue-5005/minimum_example.rs b/tests/target/issue-5005/minimum_example.rs new file mode 100644 index 00000000000..11cc645fa53 --- /dev/null +++ b/tests/target/issue-5005/minimum_example.rs @@ -0,0 +1,9 @@ +#![feature(more_qualified_paths)] +macro_rules! show { + ($ty:ty, $ex:expr) => { + match $ex { + <$ty>::A(_val) => println!("got a"), // formatting should not remove <$ty>:: + <$ty>::B => println!("got b"), + } + }; +}