diff options
Diffstat (limited to 'compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs')
| -rw-r--r-- | compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs new file mode 100644 index 00000000000..b9f841800ab --- /dev/null +++ b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs @@ -0,0 +1,49 @@ +use rustc_ast::attr::{AttributeExt, filter_by_name}; +use rustc_session::Session; +use rustc_span::symbol::{Symbol, sym}; + +use crate::session_diagnostics; + +pub fn allow_internal_unstable<'a>( + sess: &'a Session, + attrs: &'a [impl AttributeExt], +) -> impl Iterator<Item = Symbol> + 'a { + allow_unstable(sess, attrs, sym::allow_internal_unstable) +} + +pub fn rustc_allow_const_fn_unstable<'a>( + sess: &'a Session, + attrs: &'a [impl AttributeExt], +) -> impl Iterator<Item = Symbol> + 'a { + allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable) +} + +fn allow_unstable<'a>( + sess: &'a Session, + attrs: &'a [impl AttributeExt], + symbol: Symbol, +) -> impl Iterator<Item = Symbol> + 'a { + let attrs = filter_by_name(attrs, symbol); + let list = attrs + .filter_map(move |attr| { + attr.meta_item_list().or_else(|| { + sess.dcx().emit_err(session_diagnostics::ExpectsFeatureList { + span: attr.span(), + name: symbol.to_ident_string(), + }); + None + }) + }) + .flatten(); + + list.into_iter().filter_map(move |it| { + let name = it.ident().map(|ident| ident.name); + if name.is_none() { + sess.dcx().emit_err(session_diagnostics::ExpectsFeatures { + span: it.span(), + name: symbol.to_ident_string(), + }); + } + name + }) +} |
