Allow multiple allow_internal_unstable attributes
Co-authored-by: varkor <github@varkor.com>
This commit is contained in:
parent
9d74efe32e
commit
54c9c949a1
4 changed files with 28 additions and 11 deletions
|
@ -1022,14 +1022,21 @@ pub fn find_transparency(
|
||||||
|
|
||||||
pub fn allow_internal_unstable<'a>(
|
pub fn allow_internal_unstable<'a>(
|
||||||
sess: &'a Session,
|
sess: &'a Session,
|
||||||
attrs: &[Attribute],
|
attrs: &'a [Attribute],
|
||||||
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
) -> Option<impl Iterator<Item = Symbol> + 'a> {
|
||||||
let attr = sess.find_by_name(attrs, sym::allow_internal_unstable)?;
|
let attrs = sess.filter_by_name(attrs, sym::allow_internal_unstable);
|
||||||
let list = attr.meta_item_list().or_else(|| {
|
let list = attrs
|
||||||
sess.diagnostic()
|
.filter_map(move |attr| {
|
||||||
.span_err(attr.span, "allow_internal_unstable expects list of feature names");
|
attr.meta_item_list().or_else(|| {
|
||||||
|
sess.diagnostic().span_err(
|
||||||
|
attr.span,
|
||||||
|
"`allow_internal_unstable` expects a list of feature names",
|
||||||
|
);
|
||||||
None
|
None
|
||||||
})?;
|
})
|
||||||
|
})
|
||||||
|
.flatten();
|
||||||
|
|
||||||
Some(list.into_iter().filter_map(move |it| {
|
Some(list.into_iter().filter_map(move |it| {
|
||||||
let name = it.ident().map(|ident| ident.name);
|
let name = it.ident().map(|ident| ident.name);
|
||||||
if name.is_none() {
|
if name.is_none() {
|
||||||
|
|
|
@ -52,6 +52,15 @@ macro_rules! access_field_allow {
|
||||||
($e: expr) => { $e.x }
|
($e: expr) => { $e.x }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// regression test for #77088
|
||||||
|
#[stable(feature = "stable", since = "1.0.0")]
|
||||||
|
#[allow_internal_unstable(struct_field)]
|
||||||
|
#[allow_internal_unstable(struct2_field)]
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! access_field_allow2 {
|
||||||
|
($e: expr) => { $e.x }
|
||||||
|
}
|
||||||
|
|
||||||
#[stable(feature = "stable", since = "1.0.0")]
|
#[stable(feature = "stable", since = "1.0.0")]
|
||||||
#[allow_internal_unstable()]
|
#[allow_internal_unstable()]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
|
@ -28,6 +28,7 @@ fn main() {
|
||||||
construct_unstable_allow!(0);
|
construct_unstable_allow!(0);
|
||||||
|x: internal_unstable::Foo| { call_method_allow!(x) };
|
|x: internal_unstable::Foo| { call_method_allow!(x) };
|
||||||
|x: internal_unstable::Bar| { access_field_allow!(x) };
|
|x: internal_unstable::Bar| { access_field_allow!(x) };
|
||||||
|
|x: internal_unstable::Bar| { access_field_allow2!(x) }; // regression test for #77088
|
||||||
|
|
||||||
// bad.
|
// bad.
|
||||||
pass_through_allow!(internal_unstable::unstable()); //~ ERROR use of unstable
|
pass_through_allow!(internal_unstable::unstable()); //~ ERROR use of unstable
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0658]: use of unstable library feature 'function'
|
error[E0658]: use of unstable library feature 'function'
|
||||||
--> $DIR/internal-unstable.rs:33:25
|
--> $DIR/internal-unstable.rs:34:25
|
||||||
|
|
|
|
||||||
LL | pass_through_allow!(internal_unstable::unstable());
|
LL | pass_through_allow!(internal_unstable::unstable());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -7,7 +7,7 @@ LL | pass_through_allow!(internal_unstable::unstable());
|
||||||
= help: add `#![feature(function)]` to the crate attributes to enable
|
= help: add `#![feature(function)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: use of unstable library feature 'function'
|
error[E0658]: use of unstable library feature 'function'
|
||||||
--> $DIR/internal-unstable.rs:35:27
|
--> $DIR/internal-unstable.rs:36:27
|
||||||
|
|
|
|
||||||
LL | pass_through_noallow!(internal_unstable::unstable());
|
LL | pass_through_noallow!(internal_unstable::unstable());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -15,7 +15,7 @@ LL | pass_through_noallow!(internal_unstable::unstable());
|
||||||
= help: add `#![feature(function)]` to the crate attributes to enable
|
= help: add `#![feature(function)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: use of unstable library feature 'function'
|
error[E0658]: use of unstable library feature 'function'
|
||||||
--> $DIR/internal-unstable.rs:39:22
|
--> $DIR/internal-unstable.rs:40:22
|
||||||
|
|
|
|
||||||
LL | println!("{:?}", internal_unstable::unstable());
|
LL | println!("{:?}", internal_unstable::unstable());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -23,7 +23,7 @@ LL | println!("{:?}", internal_unstable::unstable());
|
||||||
= help: add `#![feature(function)]` to the crate attributes to enable
|
= help: add `#![feature(function)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: use of unstable library feature 'function'
|
error[E0658]: use of unstable library feature 'function'
|
||||||
--> $DIR/internal-unstable.rs:41:10
|
--> $DIR/internal-unstable.rs:42:10
|
||||||
|
|
|
|
||||||
LL | bar!(internal_unstable::unstable());
|
LL | bar!(internal_unstable::unstable());
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue