Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple allow_internal_unstable attributes #77183

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,14 +1022,21 @@ pub fn find_transparency(

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how this PR fixes anything. All you've done is replace a ? operator with a filter map. But find_by_name will still only return a single attribute.

Please revert the PR. I'll reopen the issue, then we can discuss an actual fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not find_by_name, but filter_by_name which returns an iterator with all matching attributes, instead of the first one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 I apologize. I should not review half asleep

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine. I'll check locally if the test case I added actually fails without

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() {
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/internal/auxiliary/internal_unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ macro_rules! access_field_allow {
($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")]
#[allow_internal_unstable()]
#[macro_export]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/internal/internal-unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn main() {
construct_unstable_allow!(0);
|x: internal_unstable::Foo| { call_method_allow!(x) };
|x: internal_unstable::Bar| { access_field_allow!(x) };
|x: internal_unstable::Bar| { access_field_allow2!(x) }; // regression test for #77088

// bad.
pass_through_allow!(internal_unstable::unstable()); //~ ERROR use of unstable
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/internal/internal-unstable.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
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());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(function)]` to the crate attributes to enable

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());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(function)]` to the crate attributes to enable

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());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(function)]` to the crate attributes to enable

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());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down