Skip to content

Commit

Permalink
Prevent removal of qualified path for tuple struct inside macro
Browse files Browse the repository at this point in the history
fixes 5005

This was very similar to 4964 and the fix was to extract and pass along
the qself of the ``PatKind::TupleStruct``
  • Loading branch information
ytmimi authored and calebcartwright committed Sep 27, 2021
1 parent cb144c3 commit a5138b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/patterns.rs
Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions 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"),
}
};
}

0 comments on commit a5138b3

Please sign in to comment.