How to refactor quote_method? (living on after https://github.com/rust-lang/rust/pull/23265 landed)


#1

Can someone advice, what is the proper way to refactor code to replace ast::Method and quote_method! for the current rustc head for code like this:

quote_item!(cx,
  $doc_attr
  pub fn $fn_name<'b>(&'b mut self, new_value: $field_ty) -> &'b mut $setter_ty<'a> {
    self.value |= (self.value & ! $mask) | ((new_value as $unpacked_ty) & $mask) << $shift;
    self.mask |= $mask << $shift;
    self
  }
)

#2

If someone will be looking for answer, here’s how you do that. First, wrap your method in a stub impl X { ... }, then use this function to extract it from quote_item!:

pub fn unwrap_impl_item(item: P<ast::Item>) -> P<ast::ImplItem> {
  match item.node {
    ast::ItemImpl(_, _, _, _, _, ref items) => {
      items.clone().pop().expect("impl method not found")
    }
    _ => unreachable!("impl parsed to something other than impl")
  }
}