forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransparency.rs
36 lines (31 loc) · 1.37 KB
/
transparency.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use rustc_attr_data_structures::AttributeKind;
use rustc_span::hygiene::Transparency;
use rustc_span::sym;
use super::SingleAttributeGroup;
use crate::parser::{ArgParser, NameValueParser};
pub(crate) struct TransparencyGroup;
// TODO: fix this but I don't want to rn
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
impl SingleAttributeGroup for TransparencyGroup {
const PATH: &'static [rustc_span::Symbol] = &[sym::rustc_macro_transparency];
fn on_duplicate(cx: &crate::context::AttributeAcceptContext<'_>, first_span: rustc_span::Span) {
cx.dcx().span_err(vec![first_span, cx.attr_span], "multiple macro transparency attributes");
}
fn convert(
cx: &crate::context::AttributeAcceptContext<'_>,
args: &crate::parser::GenericArgParser<'_, rustc_ast::Expr>,
) -> Option<AttributeKind> {
match args.name_value().and_then(|nv| nv.value_as_str()) {
Some(sym::transparent) => Some(Transparency::Transparent),
Some(sym::semitransparent) => Some(Transparency::SemiTransparent),
Some(sym::opaque) => Some(Transparency::Opaque),
Some(other) => {
cx.dcx().span_err(cx.attr_span, format!("unknown macro transparency: `{other}`"));
None
}
None => None,
}
.map(AttributeKind::MacroTransparency)
}
}