Skip to main content

rustc_attr_parsing/attributes/
path.rs

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