From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../rustdoc-scrape-examples-macros/src/proc.rs | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/run-make-fulldeps/rustdoc-scrape-examples-macros/src/proc.rs (limited to 'tests/run-make-fulldeps/rustdoc-scrape-examples-macros/src/proc.rs') diff --git a/tests/run-make-fulldeps/rustdoc-scrape-examples-macros/src/proc.rs b/tests/run-make-fulldeps/rustdoc-scrape-examples-macros/src/proc.rs new file mode 100644 index 000000000..46e518fdf --- /dev/null +++ b/tests/run-make-fulldeps/rustdoc-scrape-examples-macros/src/proc.rs @@ -0,0 +1,39 @@ +extern crate proc_macro; +use proc_macro::*; + +#[proc_macro] +pub fn a_proc_macro(_item: TokenStream) -> TokenStream { + "fn ex() { foobar::f(); }".parse().unwrap() +} + +// inserts foobar::f() to the end of the function +#[proc_macro_attribute] +pub fn an_attr_macro(attr: TokenStream, item: TokenStream) -> TokenStream { + let new_call: TokenStream = "foobar::f();".parse().unwrap(); + + let mut tokens = item.into_iter(); + + let fn_tok = tokens.next().unwrap(); + let ident_tok = tokens.next().unwrap(); + let args_tok = tokens.next().unwrap(); + let body = match tokens.next().unwrap() { + TokenTree::Group(g) => { + let new_g = Group::new(g.delimiter(), new_call); + let mut outer_g = Group::new( + g.delimiter(), + [TokenTree::Group(g.clone()), TokenTree::Group(new_g)].into_iter().collect(), + ); + + if attr.to_string() == "with_span" { + outer_g.set_span(g.span()); + } + + TokenTree::Group(outer_g) + } + _ => unreachable!(), + }; + + let tokens = vec![fn_tok, ident_tok, args_tok, body].into_iter().collect::(); + + tokens +} -- cgit v1.2.3