The above snippet doesn’t do what you want it to do.
match token {
TokenTree::Punct(punct)
if punct_ch == punct.as_char() => {
unimplemented!()
}
_ => { unimplemented!() }
}
name @ pat binds name to the entire pattern, so here token is moved into punct. By writing it as above, you get the Punct in punct instead of the TokenTree.
I’m surprised this example even compiles (if it does), as TokenTree::Punct is a newtype variant, not a struct variant.
Full refinement typing for enum variants is a long way from happening in design as well as implementation. Currently, enum variants aren’t even types, so I’m unsure whether it can even be added.