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