rustc_attr_parsing/attributes/
debugger.rs1use rustc_feature::AttributeStability;
2use rustc_hir::attrs::{DebugVisualizer, DebuggerVisualizerType};
3
4use super::prelude::*;
5
6pub(crate) struct DebuggerVisualizerParser;
7
8impl CombineAttributeParser for DebuggerVisualizerParser {
9 const PATH: &[Symbol] = &[sym::debugger_visualizer];
10 const ALLOWED_TARGETS: AllowedTargets =
11 AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::Crate)]);
12 const TEMPLATE: AttributeTemplate = ::rustc_feature::AttributeTemplate {
word: false,
list: Some(&[r#"natvis_file = "...", gdb_script_file = "...""#]),
one_of: &[],
name_value_str: None,
docs: Some("https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute"),
}template!(
13 List: &[r#"natvis_file = "...", gdb_script_file = "...""#],
14 "https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute"
15 );
16 const STABILITY: AttributeStability = AttributeStability::Stable;
17
18 type Item = DebugVisualizer;
19 const CONVERT: ConvertFn<Self::Item> = |v, _| AttributeKind::DebuggerVisualizer(v);
20
21 fn extend(
22 cx: &mut AcceptContext<'_, '_>,
23 args: &ArgParser,
24 ) -> impl IntoIterator<Item = Self::Item> {
25 let single = cx.expect_single_element_list(args, cx.attr_span)?;
26 let (ident, args) = cx.expect_name_value(single, single.span(), None)?;
27 let visualizer_type = match ident.name {
28 sym::natvis_file => DebuggerVisualizerType::Natvis,
29 sym::gdb_script_file => DebuggerVisualizerType::GdbPrettyPrinter,
30 _ => {
31 cx.adcx().expected_specific_argument(
32 ident.span,
33 &[sym::natvis_file, sym::gdb_script_file],
34 );
35 return None;
36 }
37 };
38
39 let path = cx.expect_string_literal(args)?;
40
41 Some(DebugVisualizer { span: ident.span.to(args.value_span), visualizer_type, path })
42 }
43}