rustc_attr_parsing/attributes/
path.rs1use super::prelude::*;
2
3pub(crate) struct PathParser;
4
5impl<S: Stage> SingleAttributeParser<S> for PathParser {
6 const PATH: &[Symbol] = &[sym::path];
7 const ON_DUPLICATE: OnDuplicate<S> = 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<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
16 let Some(nv) = args.name_value() else {
17 cx.expected_name_value(cx.attr_span, None);
18 return None;
19 };
20 let Some(path) = nv.value_as_str() else {
21 cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
22 return None;
23 };
24
25 Some(AttributeKind::Path(path, cx.attr_span))
26 }
27}