Skip to main content

rustc_attr_parsing/attributes/
confusables.rs

1use super::prelude::*;
2use crate::session_diagnostics::EmptyConfusables;
3
4#[derive(#[automatically_derived]
impl ::core::default::Default for ConfusablesParser {
    #[inline]
    fn default() -> ConfusablesParser {
        ConfusablesParser {
            confusables: ::core::default::Default::default(),
            first_span: ::core::default::Default::default(),
        }
    }
}Default)]
5pub(crate) struct ConfusablesParser {
6    confusables: ThinVec<Symbol>,
7    first_span: Option<Span>,
8}
9
10impl<S: Stage> AttributeParser<S> for ConfusablesParser {
11    const ATTRIBUTES: AcceptMapping<Self, S> = &[(
12        &[sym::rustc_confusables],
13        ::rustc_feature::AttributeTemplate {
    word: false,
    list: Some(&[r#""name1", "name2", ..."#]),
    one_of: &[],
    name_value_str: None,
    docs: None,
}template!(List: &[r#""name1", "name2", ..."#]),
14        |this, cx, args| {
15            let Some(list) = args.list() else {
16                let attr_span = cx.attr_span;
17                cx.adcx().expected_list(attr_span, args);
18                return;
19            };
20
21            if list.is_empty() {
22                cx.emit_err(EmptyConfusables { span: cx.attr_span });
23            }
24
25            for param in list.mixed() {
26                let span = param.span();
27
28                let Some(lit) = param.lit().and_then(|i| i.value_str()) else {
29                    cx.adcx().expected_string_literal(span, param.lit());
30                    continue;
31                };
32
33                this.confusables.push(lit);
34            }
35
36            this.first_span.get_or_insert(cx.attr_span);
37        },
38    )];
39    const ALLOWED_TARGETS: AllowedTargets =
40        AllowedTargets::AllowList(&[Allow(Target::Method(MethodKind::Inherent))]);
41
42    fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
43        if self.confusables.is_empty() {
44            return None;
45        }
46
47        Some(AttributeKind::RustcConfusables {
48            symbols: self.confusables,
49            first_span: self.first_span.unwrap(),
50        })
51    }
52}