2025-02-09 22:49:33 +01:00
|
|
|
use rustc_attr_data_structures::AttributeKind;
|
2024-12-13 14:47:11 +01:00
|
|
|
use rustc_span::hygiene::Transparency;
|
2025-05-20 09:20:27 +10:00
|
|
|
use rustc_span::{Span, Symbol, sym};
|
2024-12-07 15:27:17 +01:00
|
|
|
|
2025-02-09 22:49:33 +01:00
|
|
|
use super::{AcceptContext, SingleAttributeParser};
|
|
|
|
|
use crate::parser::ArgParser;
|
|
|
|
|
|
|
|
|
|
pub(crate) struct TransparencyParser;
|
|
|
|
|
|
|
|
|
|
// FIXME(jdonszelmann): make these proper diagnostics
|
|
|
|
|
#[allow(rustc::untranslatable_diagnostic)]
|
|
|
|
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
|
|
|
|
impl SingleAttributeParser for TransparencyParser {
|
2025-05-20 09:20:27 +10:00
|
|
|
const PATH: &'static [Symbol] = &[sym::rustc_macro_transparency];
|
2025-02-09 22:49:33 +01:00
|
|
|
|
2025-05-20 09:20:27 +10:00
|
|
|
fn on_duplicate(cx: &crate::context::AcceptContext<'_>, first_span: Span) {
|
2025-02-09 22:49:33 +01:00
|
|
|
cx.dcx().span_err(vec![first_span, cx.attr_span], "multiple macro transparency attributes");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn convert(cx: &AcceptContext<'_>, args: &ArgParser<'_>) -> Option<AttributeKind> {
|
|
|
|
|
match args.name_value().and_then(|nv| nv.value_as_str()) {
|
|
|
|
|
Some(sym::transparent) => Some(Transparency::Transparent),
|
2025-03-28 22:31:20 +03:00
|
|
|
Some(sym::semiopaque | sym::semitransparent) => Some(Transparency::SemiOpaque),
|
2025-02-09 22:49:33 +01:00
|
|
|
Some(sym::opaque) => Some(Transparency::Opaque),
|
|
|
|
|
Some(other) => {
|
|
|
|
|
cx.dcx().span_err(cx.attr_span, format!("unknown macro transparency: `{other}`"));
|
|
|
|
|
None
|
2024-12-07 15:27:17 +01:00
|
|
|
}
|
2025-02-09 22:49:33 +01:00
|
|
|
None => None,
|
2024-12-07 15:27:17 +01:00
|
|
|
}
|
2025-02-09 22:49:33 +01:00
|
|
|
.map(AttributeKind::MacroTransparency)
|
2024-12-07 15:27:17 +01:00
|
|
|
}
|
|
|
|
|
}
|