Skip to main content

rustc_attr_parsing/attributes/
path.rs

1use super::prelude::*;
2
3pub(crate) struct PathParser;
4
5impl SingleAttributeParser for PathParser {
6    const PATH: &[Symbol] = &[sym::path];
7    const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
8    const ALLOWED_TARGETS: AllowedTargets =
9        AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod), Error(Target::Crate)]);
10    const TEMPLATE: AttributeTemplate = ::rustc_feature::AttributeTemplate {
    word: false,
    list: None,
    one_of: &[],
    name_value_str: Some(&["file"]),
    docs: Some("https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"),
}template!(
11        NameValueStr: "file",
12        "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"
13    );
14
15    fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
16        let nv = cx.expect_name_value(args, cx.attr_span, None)?;
17        let Some(path) = nv.value_as_str() else {
18            cx.adcx().expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
19            return None;
20        };
21
22        Some(AttributeKind::Path(path))
23    }
24}