diff options
| author | kennytm <kennytm@gmail.com> | 2018-11-07 18:01:53 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-07 18:01:53 +0800 |
| commit | 0708a6a7174d1dcff84cb44d2481fa3ff98cadac (patch) | |
| tree | 407fe8336093ce63493477cd009f570116c3408d | |
| parent | d64142bb2ebf1ce134142601868955b661d61b6a (diff) | |
| parent | d22ae75c9d6aeb4bb79b51e7c6fc3d824c736ac6 (diff) | |
| download | rust-0708a6a7174d1dcff84cb44d2481fa3ff98cadac.tar.gz rust-0708a6a7174d1dcff84cb44d2481fa3ff98cadac.zip | |
Rollup merge of #55510 - bitshifter:repr-feature-gate-fix, r=petrochenkov
Fix feature gate only being checked on first repr attr. Reported in https://github.com/rust-lang/rust/issues/33158#issuecomment-412185357.
| -rw-r--r-- | src/libsyntax/attr/mod.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-repr-simd.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-repr-simd.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-repr_packed.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/feature-gates/feature-gate-repr_packed.stderr | 10 |
6 files changed, 32 insertions, 3 deletions
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 5404420988c..64876659477 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -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)) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index cb15c517c17..55652c481bd 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1614,7 +1614,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") { 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, diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.rs b/src/test/ui/feature-gates/feature-gate-repr-simd.rs index 429cec7ec90..a70f2758abb 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.rs +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.rs @@ -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() {} diff --git a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr index 8174f82060a..2f98bd24d4f 100644 --- a/src/test/ui/feature-gates/feature-gate-repr-simd.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr-simd.stderr @@ -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`. diff --git a/src/test/ui/feature-gates/feature-gate-repr_packed.rs b/src/test/ui/feature-gates/feature-gate-repr_packed.rs index 12bb152b467..65e3be288fd 100644 --- a/src/test/ui/feature-gates/feature-gate-repr_packed.rs +++ b/src/test/ui/feature-gates/feature-gate-repr_packed.rs @@ -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() {} diff --git a/src/test/ui/feature-gates/feature-gate-repr_packed.stderr b/src/test/ui/feature-gates/feature-gate-repr_packed.stderr index d0faf9d90bd..ed89a3f6b31 100644 --- a/src/test/ui/feature-gates/feature-gate-repr_packed.stderr +++ b/src/test/ui/feature-gates/feature-gate-repr_packed.stderr @@ -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`. |
