Skip to content

Fix feature gate only being checked on first repr attr. #55510

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

Merged
merged 1 commit into from
Nov 7, 2018
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
5 changes: 5 additions & 0 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ pub fn find_by_name<'a>(attrs: &'a [Attribute], name: &str) -> Option<&'a Attrib
attrs.iter().find(|attr| attr.check_name(name))
}

pub fn filter_by_name<'a>(attrs: &'a [Attribute], name: &'a str)
-> impl Iterator<Item = &'a Attribute> {
attrs.iter().filter(move |attr| attr.check_name(name))
}

pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) -> Option<Symbol> {
attrs.iter()
.find(|at| at.check_name(name))
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

ast::ItemKind::Struct(..) => {
if let Some(attr) = attr::find_by_name(&i.attrs[..], "repr") {
for attr in attr::filter_by_name(&i.attrs[..], "repr") {
Copy link
Member

Choose a reason for hiding this comment

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

This makes me wonder in how many other cases we have the same problem...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the only one that looked like a problem for repr. I don't know about other attributes though.

for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name("simd") {
gate_feature_post!(&self, repr_simd, attr.span,
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/feature-gates/feature-gate-repr-simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
#[repr(simd)] //~ error: SIMD types are experimental
struct Foo(u64, u64);

#[repr(C)]
#[repr(simd)] //~ error: SIMD types are experimental
struct Bar(u64, u64);

fn main() {}
10 changes: 9 additions & 1 deletion src/test/ui/feature-gates/feature-gate-repr-simd.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ LL | #[repr(simd)] //~ error: SIMD types are experimental
|
= help: add #![feature(repr_simd)] to the crate attributes to enable

error: aborting due to previous error
error[E0658]: SIMD types are experimental and possibly buggy (see issue #27731)
--> $DIR/feature-gate-repr-simd.rs:15:1
|
LL | #[repr(simd)] //~ error: SIMD types are experimental
| ^^^^^^^^^^^^^
|
= help: add #![feature(repr_simd)] to the crate attributes to enable

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
4 changes: 4 additions & 0 deletions src/test/ui/feature-gates/feature-gate-repr_packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
#[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experimental
struct Foo(u64);

#[repr(C)]
#[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experimental
struct Bar(u64);

fn main() {}
10 changes: 9 additions & 1 deletion src/test/ui/feature-gates/feature-gate-repr_packed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ LL | #[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experim
|
= help: add #![feature(repr_packed)] to the crate attributes to enable

error: aborting due to previous error
error[E0658]: the `#[repr(packed(n))]` attribute is experimental (see issue #33158)
--> $DIR/feature-gate-repr_packed.rs:15:1
|
LL | #[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experimental
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(repr_packed)] to the crate attributes to enable

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.