1 //! Parsing and validation of builtin attributes
3 use super::{find_by_name, mark_used};
5 use rustc_ast::ast::{self, Attribute, Lit, LitKind, MetaItem, MetaItemKind, NestedMetaItem};
6 use rustc_ast_pretty::pprust;
7 use rustc_errors::{struct_span_err, Applicability, Handler};
8 use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
9 use rustc_macros::HashStable_Generic;
10 use rustc_session::parse::{feature_err, ParseSess};
11 use rustc_span::hygiene::Transparency;
12 use rustc_span::{symbol::sym, symbol::Symbol, Span};
13 use std::num::NonZeroU32;
14 use version_check::Version;
16 pub fn is_builtin_attr(attr: &Attribute) -> bool {
17 attr.is_doc_comment() || attr.ident().filter(|ident| is_builtin_attr_name(ident.name)).is_some()
22 UnknownMetaItem(String, &'static [&'static str]),
25 MultipleStabilityLevels,
26 UnsupportedLiteral(&'static str, /* is_bytestr */ bool),
29 fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
30 let diag = &sess.span_diagnostic;
32 AttrError::MultipleItem(item) => {
33 struct_span_err!(diag, span, E0538, "multiple '{}' items", item).emit();
35 AttrError::UnknownMetaItem(item, expected) => {
36 let expected = expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>();
37 struct_span_err!(diag, span, E0541, "unknown meta item '{}'", item)
38 .span_label(span, format!("expected one of {}", expected.join(", ")))
41 AttrError::MissingSince => {
42 struct_span_err!(diag, span, E0542, "missing 'since'").emit();
44 AttrError::MissingFeature => {
45 struct_span_err!(diag, span, E0546, "missing 'feature'").emit();
47 AttrError::MultipleStabilityLevels => {
48 struct_span_err!(diag, span, E0544, "multiple stability levels").emit();
50 AttrError::UnsupportedLiteral(msg, is_bytestr) => {
51 let mut err = struct_span_err!(diag, span, E0565, "{}", msg);
53 if let Ok(lint_str) = sess.source_map().span_to_snippet(span) {
56 "consider removing the prefix",
57 lint_str[1..].to_string(),
58 Applicability::MaybeIncorrect,
67 #[derive(Clone, PartialEq, RustcEncodable, RustcDecodable)]
75 #[derive(Clone, RustcEncodable, RustcDecodable)]
76 pub enum OptimizeAttr {
82 #[derive(Copy, Clone, PartialEq)]
88 /// Determine what `#[unwind]` attribute is present in `attrs`, if any.
89 pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Option<UnwindAttr> {
90 attrs.iter().fold(None, |ia, attr| {
91 if attr.check_name(sym::unwind) {
92 if let Some(meta) = attr.meta() {
93 if let MetaItemKind::List(items) = meta.kind {
95 if items[0].check_name(sym::allowed) {
96 return Some(UnwindAttr::Allowed);
97 } else if items[0].check_name(sym::aborts) {
98 return Some(UnwindAttr::Aborts);
102 if let Some(d) = diagnostic {
103 struct_span_err!(d, attr.span, E0633, "malformed `unwind` attribute input")
104 .span_label(attr.span, "invalid argument")
107 "the allowed arguments are `allowed` and `aborts`",
108 (vec!["allowed", "aborts"])
110 .map(|s| format!("#[unwind({})]", s)),
111 Applicability::MachineApplicable,
123 /// Represents the following attributes:
127 #[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
128 #[derive(HashStable_Generic)]
129 pub struct Stability {
130 pub level: StabilityLevel,
132 pub rustc_depr: Option<RustcDeprecation>,
135 /// Represents the `#[rustc_const_unstable]` and `#[rustc_const_stable]` attributes.
136 #[derive(RustcEncodable, RustcDecodable, Copy, Clone, Debug, PartialEq, Eq, Hash)]
137 #[derive(HashStable_Generic)]
138 pub struct ConstStability {
139 pub level: StabilityLevel,
141 /// whether the function has a `#[rustc_promotable]` attribute
142 pub promotable: bool,
143 /// whether the function has a `#[rustc_allow_const_fn_ptr]` attribute
144 pub allow_const_fn_ptr: bool,
147 /// The available stability levels.
148 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)]
149 #[derive(HashStable_Generic)]
150 pub enum StabilityLevel {
151 // Reason for the current stability level and the relevant rust-lang issue
152 Unstable { reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
153 Stable { since: Symbol },
156 impl StabilityLevel {
157 pub fn is_unstable(&self) -> bool {
158 if let StabilityLevel::Unstable { .. } = *self { true } else { false }
160 pub fn is_stable(&self) -> bool {
161 if let StabilityLevel::Stable { .. } = *self { true } else { false }
165 #[derive(RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)]
166 #[derive(HashStable_Generic)]
167 pub struct RustcDeprecation {
170 /// A text snippet used to completely replace any use of the deprecated item in an expression.
171 pub suggestion: Option<Symbol>,
174 /// Checks if `attrs` contains an attribute like `#![feature(feature_name)]`.
175 /// This will not perform any "sanity checks" on the form of the attributes.
176 pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool {
177 attrs.iter().any(|item| {
178 item.check_name(sym::feature)
181 .map(|list| list.iter().any(|mi| mi.is_word() && mi.check_name(feature_name)))
186 /// Collects stability info from all stability attributes in `attrs`.
187 /// Returns `None` if no stability attributes are found.
188 pub fn find_stability(
192 ) -> (Option<Stability>, Option<ConstStability>) {
193 find_stability_generic(sess, attrs.iter(), item_sp)
196 fn find_stability_generic<'a, I>(
200 ) -> (Option<Stability>, Option<ConstStability>)
202 I: Iterator<Item = &'a Attribute>,
204 use StabilityLevel::*;
206 let mut stab: Option<Stability> = None;
207 let mut rustc_depr: Option<RustcDeprecation> = None;
208 let mut const_stab: Option<ConstStability> = None;
209 let mut promotable = false;
210 let mut allow_const_fn_ptr = false;
211 let diagnostic = &sess.span_diagnostic;
213 'outer: for attr in attrs_iter {
215 sym::rustc_const_unstable,
216 sym::rustc_const_stable,
219 sym::rustc_promotable,
220 sym::rustc_allow_const_fn_ptr,
223 .any(|&s| attr.has_name(s))
225 continue; // not a stability level
230 let meta = attr.meta();
232 if attr.has_name(sym::rustc_promotable) {
235 if attr.has_name(sym::rustc_allow_const_fn_ptr) {
236 allow_const_fn_ptr = true;
238 // attributes with data
239 else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
240 let meta = meta.as_ref().unwrap();
241 let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
246 AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
250 if let Some(v) = meta.value_str() {
254 struct_span_err!(diagnostic, meta.span, E0539, "incorrect meta item").emit();
259 macro_rules! get_meta {
260 ($($name:ident),+) => {
262 let mut $name = None;
265 if let Some(mi) = meta.meta_item() {
266 match mi.name_or_empty() {
268 sym::$name => if !get(mi, &mut $name) { continue 'outer },
271 let expected = &[ $( stringify!($name) ),+ ];
275 AttrError::UnknownMetaItem(
276 pprust::path_to_string(&mi.path),
287 AttrError::UnsupportedLiteral(
288 "unsupported literal",
298 let meta_name = meta.name_or_empty();
300 sym::rustc_const_unstable | sym::unstable => {
301 if meta_name == sym::unstable && stab.is_some() {
302 handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels);
304 } else if meta_name == sym::rustc_const_unstable && const_stab.is_some() {
305 handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels);
309 let mut feature = None;
310 let mut reason = None;
311 let mut issue = None;
312 let mut issue_num = None;
313 let mut is_soft = false;
315 if let Some(mi) = meta.meta_item() {
316 match mi.name_or_empty() {
318 if !get(mi, &mut feature) {
323 if !get(mi, &mut reason) {
328 if !get(mi, &mut issue) {
332 // These unwraps are safe because `get` ensures the meta item
333 // is a name/value pair string literal.
334 issue_num = match &*issue.unwrap().as_str() {
337 let emit_diag = |msg: &str| {
342 "`issue` must be a non-zero numeric string \
346 mi.name_value_literal().unwrap().span,
351 match issue.parse() {
352 Ok(num) if num == 0 => {
354 "`issue` must not be \"0\", \
355 use \"none\" instead",
359 Ok(num) => NonZeroU32::new(num),
361 emit_diag(&err.to_string());
370 let msg = "`soft` should not have any arguments";
371 sess.span_diagnostic.span_err(mi.span, msg);
379 AttrError::UnknownMetaItem(
380 pprust::path_to_string(&mi.path),
381 &["feature", "reason", "issue", "soft"],
391 AttrError::UnsupportedLiteral("unsupported literal", false),
397 match (feature, reason, issue) {
398 (Some(feature), reason, Some(_)) => {
399 let level = Unstable { reason, issue: issue_num, is_soft };
400 if sym::unstable == meta_name {
401 stab = Some(Stability { level, feature, rustc_depr: None });
403 const_stab = Some(ConstStability {
407 allow_const_fn_ptr: false,
412 handle_errors(sess, attr.span, AttrError::MissingFeature);
416 struct_span_err!(diagnostic, attr.span, E0547, "missing 'issue'")
422 sym::rustc_const_stable | sym::stable => {
423 if meta_name == sym::stable && stab.is_some() {
424 handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels);
426 } else if meta_name == sym::rustc_const_stable && const_stab.is_some() {
427 handle_errors(sess, attr.span, AttrError::MultipleStabilityLevels);
431 let mut feature = None;
432 let mut since = None;
435 NestedMetaItem::MetaItem(mi) => match mi.name_or_empty() {
437 if !get(mi, &mut feature) {
442 if !get(mi, &mut since) {
450 AttrError::UnknownMetaItem(
451 pprust::path_to_string(&mi.path),
458 NestedMetaItem::Literal(lit) => {
462 AttrError::UnsupportedLiteral("unsupported literal", false),
469 match (feature, since) {
470 (Some(feature), Some(since)) => {
471 let level = Stable { since };
472 if sym::stable == meta_name {
473 stab = Some(Stability { level, feature, rustc_depr: None });
475 const_stab = Some(ConstStability {
479 allow_const_fn_ptr: false,
484 handle_errors(sess, attr.span, AttrError::MissingFeature);
488 handle_errors(sess, attr.span, AttrError::MissingSince);
498 // Merge the deprecation info into the stability info
499 if let Some(rustc_depr) = rustc_depr {
500 if let Some(ref mut stab) = stab {
501 stab.rustc_depr = Some(rustc_depr);
507 "rustc_deprecated attribute must be paired with \
508 either stable or unstable attribute"
514 // Merge the const-unstable info into the stability info
515 if promotable || allow_const_fn_ptr {
516 if let Some(ref mut stab) = const_stab {
517 stab.promotable = promotable;
518 stab.allow_const_fn_ptr = allow_const_fn_ptr;
524 "rustc_promotable and rustc_allow_const_fn_ptr attributes \
525 must be paired with either a rustc_const_unstable or a rustc_const_stable \
535 pub fn find_crate_name(attrs: &[Attribute]) -> Option<Symbol> {
536 super::first_attr_value_str_by_name(attrs, sym::crate_name)
539 /// Tests if a cfg-pattern matches the cfg set
540 pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) -> bool {
541 eval_condition(cfg, sess, features, &mut |cfg| {
542 try_gate_cfg(cfg, sess, features);
543 let error = |span, msg| {
544 sess.span_diagnostic.span_err(span, msg);
547 if cfg.path.segments.len() != 1 {
548 return error(cfg.path.span, "`cfg` predicate key must be an identifier");
551 MetaItemKind::List(..) => {
552 error(cfg.span, "unexpected parentheses after `cfg` predicate key")
554 MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
558 AttrError::UnsupportedLiteral(
559 "literal in `cfg` predicate value must be a string",
560 lit.kind.is_bytestr(),
565 MetaItemKind::NameValue(..) | MetaItemKind::Word => {
566 let ident = cfg.ident().expect("multi-segment cfg predicate");
567 sess.config.contains(&(ident.name, cfg.value_str()))
573 fn try_gate_cfg(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) {
574 let gate = find_gated_cfg(|sym| cfg.check_name(sym));
575 if let (Some(feats), Some(gated_cfg)) = (features, gate) {
576 gate_cfg(&gated_cfg, cfg.span, sess, feats);
580 fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &ParseSess, features: &Features) {
581 let (cfg, feature, has_feature) = gated_cfg;
582 if !has_feature(features) && !cfg_span.allows_unstable(*feature) {
583 let explain = format!("`cfg({})` is experimental and subject to change", cfg);
584 feature_err(sess, *feature, cfg_span, &explain).emit();
588 /// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
589 /// evaluate individual items.
590 pub fn eval_condition(
593 features: Option<&Features>,
594 eval: &mut impl FnMut(&ast::MetaItem) -> bool,
597 ast::MetaItemKind::List(ref mis) if cfg.name_or_empty() == sym::version => {
598 try_gate_cfg(cfg, sess, features);
599 let (min_version, span) = match &mis[..] {
600 [NestedMetaItem::Literal(Lit { kind: LitKind::Str(sym, ..), span, .. })] => {
603 [NestedMetaItem::Literal(Lit { span, .. })
604 | NestedMetaItem::MetaItem(MetaItem { span, .. })] => {
606 .struct_span_err(*span, "expected a version literal")
612 .struct_span_err(cfg.span, "expected single version literal")
617 let min_version = match Version::parse(&min_version.as_str()) {
620 sess.span_diagnostic.struct_span_err(*span, "invalid version literal").emit();
624 let channel = env!("CFG_RELEASE_CHANNEL");
625 let nightly = channel == "nightly" || channel == "dev";
626 let rustc_version = Version::parse(env!("CFG_RELEASE")).unwrap();
628 // See https://github.com/rust-lang/rust/issues/64796#issuecomment-625474439 for details
629 if nightly { rustc_version > min_version } else { rustc_version >= min_version }
631 ast::MetaItemKind::List(ref mis) => {
632 for mi in mis.iter() {
633 if !mi.is_meta_item() {
637 AttrError::UnsupportedLiteral("unsupported literal", false),
643 // The unwraps below may look dangerous, but we've already asserted
644 // that they won't fail with the loop above.
645 match cfg.name_or_empty() {
648 .any(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
651 .all(|mi| eval_condition(mi.meta_item().unwrap(), sess, features, eval)),
655 sess.span_diagnostic,
658 "expected 1 cfg-pattern"
664 !eval_condition(mis[0].meta_item().unwrap(), sess, features, eval)
668 sess.span_diagnostic,
671 "invalid predicate `{}`",
672 pprust::path_to_string(&cfg.path)
679 ast::MetaItemKind::Word | ast::MetaItemKind::NameValue(..) => eval(cfg),
683 #[derive(RustcEncodable, RustcDecodable, Clone, HashStable_Generic)]
684 pub struct Deprecation {
685 pub since: Option<Symbol>,
686 /// The note to issue a reason.
687 pub note: Option<Symbol>,
688 /// A text snippet used to completely replace any use of the deprecated item in an expression.
690 /// This is currently unstable.
691 pub suggestion: Option<Symbol>,
693 /// Whether to treat the since attribute as being a Rust version identifier
694 /// (rather than an opaque string).
695 pub is_since_rustc_version: bool,
698 /// Finds the deprecation attribute. `None` if none exists.
699 pub fn find_deprecation(
703 ) -> Option<Deprecation> {
704 find_deprecation_generic(sess, attrs.iter(), item_sp)
707 fn find_deprecation_generic<'a, I>(
711 ) -> Option<Deprecation>
713 I: Iterator<Item = &'a Attribute>,
715 let mut depr: Option<Deprecation> = None;
716 let diagnostic = &sess.span_diagnostic;
718 'outer: for attr in attrs_iter {
719 if !(attr.check_name(sym::deprecated) || attr.check_name(sym::rustc_deprecated)) {
724 struct_span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes").emit();
728 let meta = match attr.meta() {
732 let mut since = None;
734 let mut suggestion = None;
736 MetaItemKind::Word => {}
737 MetaItemKind::NameValue(..) => note = meta.value_str(),
738 MetaItemKind::List(list) => {
739 let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
744 AttrError::MultipleItem(pprust::path_to_string(&meta.path)),
748 if let Some(v) = meta.value_str() {
752 if let Some(lit) = meta.name_value_literal() {
756 AttrError::UnsupportedLiteral(
757 "literal in `deprecated` \
758 value must be a string",
759 lit.kind.is_bytestr(),
763 struct_span_err!(diagnostic, meta.span, E0551, "incorrect meta item")
773 NestedMetaItem::MetaItem(mi) => match mi.name_or_empty() {
775 if !get(mi, &mut since) {
779 sym::note if attr.check_name(sym::deprecated) => {
780 if !get(mi, &mut note) {
784 sym::reason if attr.check_name(sym::rustc_deprecated) => {
785 if !get(mi, &mut note) {
789 sym::suggestion if attr.check_name(sym::rustc_deprecated) => {
790 if !get(mi, &mut suggestion) {
798 AttrError::UnknownMetaItem(
799 pprust::path_to_string(&mi.path),
800 if attr.check_name(sym::deprecated) {
803 &["since", "reason", "suggestion"]
810 NestedMetaItem::Literal(lit) => {
814 AttrError::UnsupportedLiteral(
815 "item in `deprecated` must be a key/value pair",
826 if suggestion.is_some() && attr.check_name(sym::deprecated) {
827 unreachable!("only allowed on rustc_deprecated")
830 if attr.check_name(sym::rustc_deprecated) {
832 handle_errors(sess, attr.span, AttrError::MissingSince);
837 struct_span_err!(diagnostic, attr.span, E0543, "missing 'reason'").emit();
844 let is_since_rustc_version = attr.check_name(sym::rustc_deprecated);
845 depr = Some(Deprecation { since, note, suggestion, is_since_rustc_version });
851 #[derive(PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone)]
862 #[derive(Eq, PartialEq, Debug, RustcEncodable, RustcDecodable, Copy, Clone, HashStable_Generic)]
864 SignedInt(ast::IntTy),
865 UnsignedInt(ast::UintTy),
870 pub fn is_signed(self) -> bool {
874 SignedInt(..) => true,
875 UnsignedInt(..) => false,
880 /// Parse #[repr(...)] forms.
882 /// Valid repr contents: any of the primitive integral type names (see
883 /// `int_type_of_word`, below) to specify enum discriminant type; `C`, to use
884 /// the same discriminant size that the corresponding C enum would or C
885 /// structure layout, `packed` to remove padding, and `transparent` to elegate representation
886 /// concerns to the only non-ZST field.
887 pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
890 let mut acc = Vec::new();
891 let diagnostic = &sess.span_diagnostic;
892 if attr.has_name(sym::repr) {
893 if let Some(items) = attr.meta_item_list() {
896 if !item.is_meta_item() {
900 AttrError::UnsupportedLiteral(
901 "meta item in `repr` must be an identifier",
908 let mut recognised = false;
910 let hint = match item.name_or_empty() {
911 sym::C => Some(ReprC),
912 sym::packed => Some(ReprPacked(1)),
913 sym::simd => Some(ReprSimd),
914 sym::transparent => Some(ReprTransparent),
915 sym::no_niche => Some(ReprNoNiche),
916 name => int_type_of_word(name).map(ReprInt),
919 if let Some(h) = hint {
923 } else if let Some((name, value)) = item.name_value_literal() {
924 let parse_alignment = |node: &ast::LitKind| -> Result<u32, &'static str> {
925 if let ast::LitKind::Int(literal, ast::LitIntType::Unsuffixed) = node {
926 if literal.is_power_of_two() {
927 // rustc_middle::ty::layout::Align restricts align to <= 2^29
928 if *literal <= 1 << 29 {
931 Err("larger than 2^29")
934 Err("not a power of two")
937 Err("not an unsuffixed integer")
941 let mut literal_error = None;
942 if name == sym::align {
944 match parse_alignment(&value.kind) {
945 Ok(literal) => acc.push(ReprAlign(literal)),
946 Err(message) => literal_error = Some(message),
948 } else if name == sym::packed {
950 match parse_alignment(&value.kind) {
951 Ok(literal) => acc.push(ReprPacked(literal)),
952 Err(message) => literal_error = Some(message),
955 if let Some(literal_error) = literal_error {
960 "invalid `repr(align)` attribute: {}",
966 if let Some(meta_item) = item.meta_item() {
967 if meta_item.check_name(sym::align) {
968 if let MetaItemKind::NameValue(ref value) = meta_item.kind {
970 let mut err = struct_span_err!(
974 "incorrect `repr(align)` attribute format"
977 ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
980 "use parentheses instead",
981 format!("align({})", int),
982 Applicability::MachineApplicable,
985 ast::LitKind::Str(s, _) => {
988 "use parentheses instead",
989 format!("align({})", s),
990 Applicability::MachineApplicable,
1001 // Not a word we recognize
1006 "unrecognized representation hint"
1016 fn int_type_of_word(s: Symbol) -> Option<IntType> {
1020 sym::i8 => Some(SignedInt(ast::IntTy::I8)),
1021 sym::u8 => Some(UnsignedInt(ast::UintTy::U8)),
1022 sym::i16 => Some(SignedInt(ast::IntTy::I16)),
1023 sym::u16 => Some(UnsignedInt(ast::UintTy::U16)),
1024 sym::i32 => Some(SignedInt(ast::IntTy::I32)),
1025 sym::u32 => Some(UnsignedInt(ast::UintTy::U32)),
1026 sym::i64 => Some(SignedInt(ast::IntTy::I64)),
1027 sym::u64 => Some(UnsignedInt(ast::UintTy::U64)),
1028 sym::i128 => Some(SignedInt(ast::IntTy::I128)),
1029 sym::u128 => Some(UnsignedInt(ast::UintTy::U128)),
1030 sym::isize => Some(SignedInt(ast::IntTy::Isize)),
1031 sym::usize => Some(UnsignedInt(ast::UintTy::Usize)),
1036 pub enum TransparencyError {
1037 UnknownTransparency(Symbol, Span),
1038 MultipleTransparencyAttrs(Span, Span),
1041 pub fn find_transparency(
1042 attrs: &[Attribute],
1044 ) -> (Transparency, Option<TransparencyError>) {
1045 let mut transparency = None;
1046 let mut error = None;
1048 if attr.check_name(sym::rustc_macro_transparency) {
1049 if let Some((_, old_span)) = transparency {
1050 error = Some(TransparencyError::MultipleTransparencyAttrs(old_span, attr.span));
1052 } else if let Some(value) = attr.value_str() {
1053 transparency = Some((
1055 sym::transparent => Transparency::Transparent,
1056 sym::semitransparent => Transparency::SemiTransparent,
1057 sym::opaque => Transparency::Opaque,
1059 error = Some(TransparencyError::UnknownTransparency(value, attr.span));
1068 let fallback = if macro_rules { Transparency::SemiTransparent } else { Transparency::Opaque };
1069 (transparency.map_or(fallback, |t| t.0), error)
1072 pub fn allow_internal_unstable<'a>(
1073 attrs: &[Attribute],
1074 diag: &'a rustc_errors::Handler,
1075 ) -> Option<impl Iterator<Item = Symbol> + 'a> {
1076 let attr = find_by_name(attrs, sym::allow_internal_unstable)?;
1077 let list = attr.meta_item_list().or_else(|| {
1078 diag.span_err(attr.span, "allow_internal_unstable expects list of feature names");
1081 Some(list.into_iter().filter_map(move |it| {
1082 let name = it.ident().map(|ident| ident.name);
1084 diag.span_err(it.span(), "`allow_internal_unstable` expects feature names");