mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-28 00:15:23 +00:00
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 <edwin0cheng@gmail.com>
This commit is contained in:
commit
9c302980e3
@ -177,6 +177,9 @@ fn collect_vars(subtree: &crate::Subtree) -> Vec<SmolStr> {
|
||||
crate::TokenTree::Subtree(subtree) => {
|
||||
res.extend(collect_vars(subtree));
|
||||
}
|
||||
crate::TokenTree::Repeat(crate::Repeat { subtree, .. }) => {
|
||||
res.extend(collect_vars(subtree));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -1397,3 +1397,55 @@ quick_error ! (SORT [enum Wrapped # [derive (Debug)]] items [
|
||||
|
||||
assert_eq!(expanded.to_string(), "quick_error ! (ENUM_DEFINITION [enum Wrapped # [derive (Debug)]] body [] queue [=> One : UNIT [] => Two : TUPLE [s : String]]) ;");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_repeat_vars_in_empty_repeat_vars() {
|
||||
let rules = create_rules(r#"
|
||||
macro_rules! delegate_impl {
|
||||
([$self_type:ident, $self_wrap:ty, $self_map:ident]
|
||||
pub trait $name:ident $(: $sup:ident)* $(+ $more_sup:ident)* {
|
||||
|
||||
// "Escaped" associated types. Stripped before making the `trait`
|
||||
// itself, but forwarded when delegating impls.
|
||||
$(
|
||||
@escape [type $assoc_name_ext:ident]
|
||||
// Associated types. Forwarded.
|
||||
)*
|
||||
$(
|
||||
@section type
|
||||
$(
|
||||
$(#[$_assoc_attr:meta])*
|
||||
type $assoc_name:ident $(: $assoc_bound:ty)*;
|
||||
)+
|
||||
)*
|
||||
// Methods. Forwarded. Using $self_map!(self) around the self argument.
|
||||
// Methods must use receiver `self` or explicit type like `self: &Self`
|
||||
// &self and &mut self are _not_ supported.
|
||||
$(
|
||||
@section self
|
||||
$(
|
||||
$(#[$_method_attr:meta])*
|
||||
fn $method_name:ident(self $(: $self_selftype:ty)* $(,$marg:ident : $marg_ty:ty)*) -> $mret:ty;
|
||||
)+
|
||||
)*
|
||||
// Arbitrary tail that is ignored when forwarding.
|
||||
$(
|
||||
@section nodelegate
|
||||
$($tail:tt)*
|
||||
)*
|
||||
}) => {
|
||||
impl<> $name for $self_wrap where $self_type: $name {
|
||||
$(
|
||||
$(
|
||||
fn $method_name(self $(: $self_selftype)* $(,$marg: $marg_ty)*) -> $mret {
|
||||
$self_map!(self).$method_name($($marg),*)
|
||||
}
|
||||
)*
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
"#);
|
||||
|
||||
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 {}");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user