aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-05-05 03:21:26 +0100
committerEdwin Cheng <[email protected]>2019-05-05 03:32:57 +0100
commita48e33f1391596f5a746279a6e456024254fe908 (patch)
treeeb4c2f6f30944ebdc8bee7aa6c548986f7595228 /crates/ra_mbe
parent9239a13159d8c9217991ec08cc878c35da019a87 (diff)
Fixed missing empty vars
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs3
-rw-r--r--crates/ra_mbe/src/tests.rs52
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]
1402fn test_empty_repeat_vars_in_empty_repeat_vars() {
1403 let rules = create_rules(r#"
1404macro_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}