fn visit_item(&mut self, i: &'a ast::Item) {
match i.node {
ast::ItemKind::ExternCrate(_) => {
- if attr::contains_name(&i.attrs[..], "macro_reexport") {
- gate_feature_post!(&self, macro_reexport, i.span,
+ if let Some(attr) = attr::find_by_name(&i.attrs[..], "macro_reexport") {
+ gate_feature_post!(&self, macro_reexport, attr.span,
"macros reexports are experimental \
and possibly buggy");
}
function may change over time, for now \
a top-level `fn main()` is required");
}
- if attr::contains_name(&i.attrs[..], "must_use") {
- gate_feature_post!(&self, fn_must_use, i.span,
+ if let Some(attr) = attr::find_by_name(&i.attrs[..], "must_use") {
+ gate_feature_post!(&self, fn_must_use, attr.span,
"`#[must_use]` on functions is experimental",
GateStrength::Soft);
}
}
ast::ItemKind::Struct(..) => {
- if attr::contains_name(&i.attrs[..], "simd") {
- gate_feature_post!(&self, simd, i.span,
+ if let Some(attr) = attr::find_by_name(&i.attrs[..], "simd") {
+ gate_feature_post!(&self, simd, attr.span,
"SIMD types are experimental and possibly buggy");
- self.context.parse_sess.span_diagnostic.span_warn(i.span,
+ self.context.parse_sess.span_diagnostic.span_warn(attr.span,
"the `#[simd]` attribute \
is deprecated, use \
`#[repr(simd)]` instead");
}
- for attr in &i.attrs {
- if attr.path == "repr" {
- for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
- if item.check_name("simd") {
- gate_feature_post!(&self, repr_simd, i.span,
- "SIMD types are experimental \
- and possibly buggy");
-
- }
- if item.check_name("align") {
- gate_feature_post!(&self, repr_align, i.span,
- "the struct `#[repr(align(u16))]` attribute \
- is experimental");
- }
+ if let Some(attr) = attr::find_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,
+ "SIMD types are experimental and possibly buggy");
+ }
+ if item.check_name("align") {
+ gate_feature_post!(&self, repr_align, attr.span,
+ "the struct `#[repr(align(u16))]` attribute \
+ is experimental");
}
}
}
for impl_item in impl_items {
if let ast::ImplItemKind::Method(..) = impl_item.node {
- if attr::contains_name(&impl_item.attrs[..], "must_use") {
- gate_feature_post!(&self, fn_must_use, impl_item.span,
+ if let Some(attr) = attr::find_by_name(&impl_item.attrs[..], "must_use") {
+ gate_feature_post!(&self, fn_must_use, attr.span,
"`#[must_use]` on methods is experimental",
GateStrength::Soft);
}
--- /dev/null
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(attr_literals)]
+
+#[repr(align(16))]
+struct Gem {
+ mohs_hardness: u8,
+ poofed: bool,
+ weapon: Weapon,
+}
+
+#[repr(simd)]
+struct Weapon {
+ name: String,
+ damage: u32
+}
+
+impl Gem {
+ #[must_use] fn summon_weapon(&self) -> Weapon { self.weapon }
+}
+
+#[must_use]
+fn bubble(gem: Gem) -> Result<Gem, ()> {
+ if gem.poofed {
+ Ok(gem)
+ } else {
+ Err(())
+ }
+}
+
+fn main() {}
--- /dev/null
+error: the struct `#[repr(align(u16))]` attribute is experimental (see issue #33626)
+ --> $DIR/gated-features-attr-spans.rs:13:1
+ |
+13 | #[repr(align(16))]
+ | ^^^^^^^^^^^^^^^^^^
+ |
+ = help: add #![feature(repr_align)] to the crate attributes to enable
+
+error: SIMD types are experimental and possibly buggy (see issue #27731)
+ --> $DIR/gated-features-attr-spans.rs:20:1
+ |
+20 | #[repr(simd)]
+ | ^^^^^^^^^^^^^
+ |
+ = help: add #![feature(repr_simd)] to the crate attributes to enable
+
+warning: `#[must_use]` on methods is experimental (see issue #43302)
+ --> $DIR/gated-features-attr-spans.rs:27:5
+ |
+27 | #[must_use] fn summon_weapon(&self) -> Weapon { self.weapon }
+ | ^^^^^^^^^^^
+ |
+ = help: add #![feature(fn_must_use)] to the crate attributes to enable
+
+warning: `#[must_use]` on functions is experimental (see issue #43302)
+ --> $DIR/gated-features-attr-spans.rs:30:1
+ |
+30 | #[must_use]
+ | ^^^^^^^^^^^
+ |
+ = help: add #![feature(fn_must_use)] to the crate attributes to enable
+
+error: aborting due to 2 previous errors
+