rustc_span/
profiling.rs

1use std::borrow::Borrow;
2
3use rustc_data_structures::profiling::EventArgRecorder;
4
5use crate::source_map::SourceMap;
6
7/// Extension trait for self-profiling purposes: allows to record spans within a generic activity's
8/// event arguments.
9pub trait SpannedEventArgRecorder {
10    /// Records the following event arguments within the current generic activity being profiled:
11    /// - the provided `event_arg`
12    /// - a string representation of the provided `span`
13    ///
14    /// Note: when self-profiling with costly event arguments, at least one argument
15    /// needs to be recorded. A panic will be triggered if that doesn't happen.
16    fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
17    where
18        A: Borrow<str> + Into<String>;
19}
20
21impl SpannedEventArgRecorder for EventArgRecorder<'_> {
22    fn record_arg_with_span<A>(&mut self, source_map: &SourceMap, event_arg: A, span: crate::Span)
23    where
24        A: Borrow<str> + Into<String>,
25    {
26        self.record_arg(event_arg);
27        self.record_arg(source_map.span_to_embeddable_string(span));
28    }
29}