31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
|
|
use rustc_attr_data_structures::AttributeKind;
|
||
|
|
use rustc_attr_data_structures::AttributeKind::LinkName;
|
||
|
|
use rustc_feature::{AttributeTemplate, template};
|
||
|
|
use rustc_span::{Symbol, sym};
|
||
|
|
|
||
|
|
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
|
||
|
|
use crate::context::{AcceptContext, Stage};
|
||
|
|
use crate::parser::ArgParser;
|
||
|
|
|
||
|
|
pub(crate) struct LinkNameParser;
|
||
|
|
|
||
|
|
impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
|
||
|
|
const PATH: &[Symbol] = &[sym::link_name];
|
||
|
|
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
|
||
|
|
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
|
||
|
|
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
|
||
|
|
|
||
|
|
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
|
||
|
|
let Some(nv) = args.name_value() else {
|
||
|
|
cx.expected_name_value(cx.attr_span, None);
|
||
|
|
return None;
|
||
|
|
};
|
||
|
|
let Some(name) = nv.value_as_str() else {
|
||
|
|
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
|
||
|
|
return None;
|
||
|
|
};
|
||
|
|
|
||
|
|
Some(LinkName { name, span: cx.attr_span })
|
||
|
|
}
|
||
|
|
}
|