diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 9aa8684677a9..d05a2a0d2d42 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -1,5 +1,6 @@ use rustc_ast as ast; use rustc_ast::tokenstream::TokenStream; +use rustc_data_structures::profiling::TimingGuard; use rustc_errors::ErrorGuaranteed; use rustc_middle::ty::{self, TyCtxt}; use rustc_parse::parser::{AllowConstBlockItems, ForceCollect, Parser}; @@ -19,6 +20,16 @@ fn exec_strategy(sess: &Session) -> impl pm::bridge::server::ExecutionStrategy + } } +fn record_expand_proc_macro<'a>( + ecx: &ExtCtxt<'a>, + name: &'static str, + span: Span, +) -> TimingGuard<'a> { + ecx.sess.prof.generic_activity_with_arg_recorder(name, |recorder| { + recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span); + }) +} + pub struct BangProcMacro { pub client: pm::bridge::client::Client, } @@ -30,10 +41,7 @@ fn expand( span: Span, input: TokenStream, ) -> Result { - let _timer = - ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| { - recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span); - }); + let _timer = record_expand_proc_macro(ecx, "expand_proc_macro", span); let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace; let strategy = exec_strategy(ecx.sess); @@ -61,10 +69,7 @@ fn expand( annotation: TokenStream, annotated: TokenStream, ) -> Result { - let _timer = - ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| { - recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span); - }); + let _timer = record_expand_proc_macro(ecx, "expand_proc_macro", span); let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace; let strategy = exec_strategy(ecx.sess); @@ -95,12 +100,7 @@ fn expand( item: Annotatable, _is_derive_const: bool, ) -> ExpandResult, Annotatable> { - let _timer = ecx.sess.prof.generic_activity_with_arg_recorder( - "expand_derive_proc_macro_outer", - |recorder| { - recorder.record_arg_with_span(ecx.sess.source_map(), ecx.expansion_descr(), span); - }, - ); + let _timer = record_expand_proc_macro(ecx, "expand_derive_proc_macro_outer", span); // We need special handling for statement items // (e.g. `fn foo() { #[derive(Debug)] struct Bar; }`) @@ -191,7 +191,7 @@ fn expand_derive_macro( let invoc_expn_data = invoc_id.expn_data(); let span = invoc_expn_data.call_site; let event_arg = invoc_expn_data.kind.descr(); - recorder.record_arg_with_span(ecx.sess.source_map(), event_arg.clone(), span); + recorder.record_arg_with_span(ecx.sess.source_map(), event_arg, span); }); let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace;