pub feature: Symbol,
/// whether the function has a `#[rustc_promotable]` attribute
pub promotable: bool,
- /// whether the function has a `#[rustc_allow_const_fn_ptr]` attribute
- pub allow_const_fn_ptr: bool,
}
/// The available stability levels.
let mut stab: Option<Stability> = None;
let mut const_stab: Option<ConstStability> = None;
let mut promotable = false;
- let mut allow_const_fn_ptr = false;
let diagnostic = &sess.parse_sess.span_diagnostic;
'outer: for attr in attrs_iter {
sym::unstable,
sym::stable,
sym::rustc_promotable,
- sym::rustc_allow_const_fn_ptr,
]
.iter()
.any(|&s| attr.has_name(s))
if attr.has_name(sym::rustc_promotable) {
promotable = true;
}
- if attr.has_name(sym::rustc_allow_const_fn_ptr) {
- allow_const_fn_ptr = true;
- }
// attributes with data
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
let meta = meta.as_ref().unwrap();
if sym::unstable == meta_name {
stab = Some(Stability { level, feature });
} else {
- const_stab = Some(ConstStability {
- level,
- feature,
- promotable: false,
- allow_const_fn_ptr: false,
- });
+ const_stab =
+ Some(ConstStability { level, feature, promotable: false });
}
}
(None, _, _) => {
if sym::stable == meta_name {
stab = Some(Stability { level, feature });
} else {
- const_stab = Some(ConstStability {
- level,
- feature,
- promotable: false,
- allow_const_fn_ptr: false,
- });
+ const_stab =
+ Some(ConstStability { level, feature, promotable: false });
}
}
(None, _) => {
}
// Merge the const-unstable info into the stability info
- if promotable || allow_const_fn_ptr {
+ if promotable {
if let Some(ref mut stab) = const_stab {
stab.promotable = promotable;
- stab.allow_const_fn_ptr = allow_const_fn_ptr;
} else {
struct_span_err!(
diagnostic,
item_sp,
E0717,
- "rustc_promotable and rustc_allow_const_fn_ptr attributes \
- must be paired with either a rustc_const_unstable or a rustc_const_stable \
- attribute"
+ "`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` \
+ or a `rustc_const_stable` attribute"
)
.emit();
}
pub fn allow_internal_unstable<'a>(
sess: &'a Session,
- attrs: &[Attribute],
+ attrs: &'a [Attribute],
) -> Option<impl Iterator<Item = Symbol> + 'a> {
- let attr = sess.find_by_name(attrs, sym::allow_internal_unstable)?;
- let list = attr.meta_item_list().or_else(|| {
- sess.diagnostic()
- .span_err(attr.span, "allow_internal_unstable expects list of feature names");
- None
- })?;
+ let attrs = sess.filter_by_name(attrs, sym::allow_internal_unstable);
+ let list = attrs
+ .filter_map(move |attr| {
+ attr.meta_item_list().or_else(|| {
+ sess.diagnostic().span_err(
+ attr.span,
+ "`allow_internal_unstable` expects a list of feature names",
+ );
+ None
+ })
+ })
+ .flatten();
+
Some(list.into_iter().filter_map(move |it| {
let name = it.ident().map(|ident| ident.name);
if name.is_none() {