Skip to content

Commit 0708a6a

Browse files
authored
Rollup merge of rust-lang#55510 - bitshifter:repr-feature-gate-fix, r=petrochenkov
Fix feature gate only being checked on first repr attr. Reported in rust-lang#33158 (comment).
2 parents d64142b + d22ae75 commit 0708a6a

6 files changed

+32
-3
lines changed

src/libsyntax/attr/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ pub fn find_by_name<'a>(attrs: &'a [Attribute], name: &str) -> Option<&'a Attrib
455455
attrs.iter().find(|attr| attr.check_name(name))
456456
}
457457

458+
pub fn filter_by_name<'a>(attrs: &'a [Attribute], name: &'a str)
459+
-> impl Iterator<Item = &'a Attribute> {
460+
attrs.iter().filter(move |attr| attr.check_name(name))
461+
}
462+
458463
pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) -> Option<Symbol> {
459464
attrs.iter()
460465
.find(|at| at.check_name(name))

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
16141614
}
16151615

16161616
ast::ItemKind::Struct(..) => {
1617-
if let Some(attr) = attr::find_by_name(&i.attrs[..], "repr") {
1617+
for attr in attr::filter_by_name(&i.attrs[..], "repr") {
16181618
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
16191619
if item.check_name("simd") {
16201620
gate_feature_post!(&self, repr_simd, attr.span,

src/test/ui/feature-gates/feature-gate-repr-simd.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
#[repr(simd)] //~ error: SIMD types are experimental
1212
struct Foo(u64, u64);
1313

14+
#[repr(C)]
15+
#[repr(simd)] //~ error: SIMD types are experimental
16+
struct Bar(u64, u64);
17+
1418
fn main() {}

src/test/ui/feature-gates/feature-gate-repr-simd.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ LL | #[repr(simd)] //~ error: SIMD types are experimental
66
|
77
= help: add #![feature(repr_simd)] to the crate attributes to enable
88

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

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

src/test/ui/feature-gates/feature-gate-repr_packed.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
#[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experimental
1212
struct Foo(u64);
1313

14+
#[repr(C)]
15+
#[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experimental
16+
struct Bar(u64);
17+
1418
fn main() {}

src/test/ui/feature-gates/feature-gate-repr_packed.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ LL | #[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experim
66
|
77
= help: add #![feature(repr_packed)] to the crate attributes to enable
88

9-
error: aborting due to previous error
9+
error[E0658]: the `#[repr(packed(n))]` attribute is experimental (see issue #33158)
10+
--> $DIR/feature-gate-repr_packed.rs:15:1
11+
|
12+
LL | #[repr(packed(1))] //~ error: the `#[repr(packed(n))]` attribute is experimental
13+
| ^^^^^^^^^^^^^^^^^^
14+
|
15+
= help: add #![feature(repr_packed)] to the crate attributes to enable
16+
17+
error: aborting due to 2 previous errors
1018

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

0 commit comments

Comments
 (0)