diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-05 07:47:22 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-05 07:47:22 +0100 |
commit | 9c302980e386734472f9bae50a0db59247cba623 (patch) | |
tree | eb4c2f6f30944ebdc8bee7aa6c548986f7595228 /crates/ra_mbe/src | |
parent | 9239a13159d8c9217991ec08cc878c35da019a87 (diff) | |
parent | a48e33f1391596f5a746279a6e456024254fe908 (diff) |
Merge #1242
1242: Fix missing empty vars in $repeat while macro expansion r=matklad a=edwin0cheng
This PR fixes a bug we forget to collect an empty vars in $repeat patterns.
Related issues: #1240
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 3 | ||||
-rw-r--r-- | crates/ra_mbe/src/tests.rs | 52 |
2 files changed, 55 insertions, 0 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 4b007647c..3a4dbb5f5 100644 --- a/crates/ra_mbe/src/mbe_expander.rs +++ b/crates/ra_mbe/src/mbe_expander.rs | |||
@@ -177,6 +177,9 @@ fn collect_vars(subtree: &crate::Subtree) -> Vec<SmolStr> { | |||
177 | crate::TokenTree::Subtree(subtree) => { | 177 | crate::TokenTree::Subtree(subtree) => { |
178 | res.extend(collect_vars(subtree)); | 178 | res.extend(collect_vars(subtree)); |
179 | } | 179 | } |
180 | crate::TokenTree::Repeat(crate::Repeat { subtree, .. }) => { | ||
181 | res.extend(collect_vars(subtree)); | ||
182 | } | ||
180 | _ => {} | 183 | _ => {} |
181 | } | 184 | } |
182 | } | 185 | } |
diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index c487bbbd4..004faf77e 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs | |||
@@ -1397,3 +1397,55 @@ quick_error ! (SORT [enum Wrapped # [derive (Debug)]] items [ | |||
1397 | 1397 | ||
1398 | assert_eq!(expanded.to_string(), "quick_error ! (ENUM_DEFINITION [enum Wrapped # [derive (Debug)]] body [] queue [=> One : UNIT [] => Two : TUPLE [s : String]]) ;"); | 1398 | assert_eq!(expanded.to_string(), "quick_error ! (ENUM_DEFINITION [enum Wrapped # [derive (Debug)]] body [] queue [=> One : UNIT [] => Two : TUPLE [s : String]]) ;"); |
1399 | } | 1399 | } |
1400 | |||
1401 | #[test] | ||
1402 | fn test_empty_repeat_vars_in_empty_repeat_vars() { | ||
1403 | let rules = create_rules(r#" | ||
1404 | macro_rules! delegate_impl { | ||
1405 | ([$self_type:ident, $self_wrap:ty, $self_map:ident] | ||
1406 | pub trait $name:ident $(: $sup:ident)* $(+ $more_sup:ident)* { | ||
1407 | |||
1408 | // "Escaped" associated types. Stripped before making the `trait` | ||
1409 | // itself, but forwarded when delegating impls. | ||
1410 | $( | ||
1411 | @escape [type $assoc_name_ext:ident] | ||
1412 | // Associated types. Forwarded. | ||
1413 | )* | ||
1414 | $( | ||
1415 | @section type | ||
1416 | $( | ||
1417 | $(#[$_assoc_attr:meta])* | ||
1418 | type $assoc_name:ident $(: $assoc_bound:ty)*; | ||
1419 | )+ | ||
1420 | )* | ||
1421 | // Methods. Forwarded. Using $self_map!(self) around the self argument. | ||
1422 | // Methods must use receiver `self` or explicit type like `self: &Self` | ||
1423 | // &self and &mut self are _not_ supported. | ||
1424 | $( | ||
1425 | @section self | ||
1426 | $( | ||
1427 | $(#[$_method_attr:meta])* | ||
1428 | fn $method_name:ident(self $(: $self_selftype:ty)* $(,$marg:ident : $marg_ty:ty)*) -> $mret:ty; | ||
1429 | )+ | ||
1430 | )* | ||
1431 | // Arbitrary tail that is ignored when forwarding. | ||
1432 | $( | ||
1433 | @section nodelegate | ||
1434 | $($tail:tt)* | ||
1435 | )* | ||
1436 | }) => { | ||
1437 | impl<> $name for $self_wrap where $self_type: $name { | ||
1438 | $( | ||
1439 | $( | ||
1440 | fn $method_name(self $(: $self_selftype)* $(,$marg: $marg_ty)*) -> $mret { | ||
1441 | $self_map!(self).$method_name($($marg),*) | ||
1442 | } | ||
1443 | )* | ||
1444 | )* | ||
1445 | } | ||
1446 | } | ||
1447 | } | ||
1448 | "#); | ||
1449 | |||
1450 | assert_expansion(MacroKind::Items, &rules, r#"delegate_impl ! {[G , & 'a mut G , deref] pub trait Data : GraphBase {@ section type type NodeWeight ;}}"#, "impl <> Data for & \'a mut G where G : Data {}"); | ||
1451 | } | ||