Remove Option from the return type of Attribute::name()
This commit is contained in:
parent
759bd01e03
commit
9b3aea602c
17 changed files with 28 additions and 36 deletions
|
@ -153,10 +153,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
||||||
// ```
|
// ```
|
||||||
let hints: Vec<_> = item.attrs
|
let hints: Vec<_> = item.attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|attr| match attr.name() {
|
.filter(|attr| attr.name() == "repr")
|
||||||
Some(name) => name == "repr",
|
|
||||||
None => false,
|
|
||||||
})
|
|
||||||
.filter_map(|attr| attr.meta_item_list())
|
.filter_map(|attr| attr.meta_item_list())
|
||||||
.flat_map(|hints| hints)
|
.flat_map(|hints| hints)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -199,8 +199,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
|
||||||
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
|
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|attr| {
|
.filter(|attr| {
|
||||||
!attr.is_sugared_doc &&
|
!attr.is_sugared_doc && !hcx.is_ignored_attr(attr.name())
|
||||||
attr.name().map(|name| !hcx.is_ignored_attr(name)).unwrap_or(true)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -227,7 +226,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Attribute {
|
||||||
hcx: &mut StableHashingContext<'a>,
|
hcx: &mut StableHashingContext<'a>,
|
||||||
hasher: &mut StableHasher<W>) {
|
hasher: &mut StableHasher<W>) {
|
||||||
// Make sure that these have been filtered out.
|
// Make sure that these have been filtered out.
|
||||||
debug_assert!(self.name().map(|name| !hcx.is_ignored_attr(name)).unwrap_or(true));
|
debug_assert!(!hcx.is_ignored_attr(self.name()));
|
||||||
debug_assert!(!self.is_sugared_doc);
|
debug_assert!(!self.is_sugared_doc);
|
||||||
|
|
||||||
let ast::Attribute {
|
let ast::Attribute {
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl<'a> LintLevelsBuilder<'a> {
|
||||||
"malformed lint attribute");
|
"malformed lint attribute");
|
||||||
};
|
};
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
let level = match attr.name().and_then(|name| Level::from_str(&name.as_str())) {
|
let level = match Level::from_str(&attr.name().as_str()) {
|
||||||
None => continue,
|
None => continue,
|
||||||
Some(lvl) => lvl,
|
Some(lvl) => lvl,
|
||||||
};
|
};
|
||||||
|
|
|
@ -205,7 +205,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
// Emit errors for non-staged-api crates.
|
// Emit errors for non-staged-api crates.
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
let tag = unwrap_or!(attr.name(), continue);
|
let tag = attr.name();
|
||||||
if tag == "unstable" || tag == "stable" || tag == "rustc_deprecated" {
|
if tag == "unstable" || tag == "stable" || tag == "rustc_deprecated" {
|
||||||
attr::mark_used(attr);
|
attr::mark_used(attr);
|
||||||
self.tcx.sess.span_err(attr.span(), "stability attributes may not be used \
|
self.tcx.sess.span_err(attr.span(), "stability attributes may not be used \
|
||||||
|
|
|
@ -675,9 +675,8 @@ impl LintPass for DeprecatedAttr {
|
||||||
|
|
||||||
impl EarlyLintPass for DeprecatedAttr {
|
impl EarlyLintPass for DeprecatedAttr {
|
||||||
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
|
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
|
||||||
let name = unwrap_or!(attr.name(), return);
|
|
||||||
for &&(n, _, ref g) in &self.depr_attrs {
|
for &&(n, _, ref g) in &self.depr_attrs {
|
||||||
if name == n {
|
if attr.name() == n {
|
||||||
if let &AttributeGate::Gated(Stability::Deprecated(link),
|
if let &AttributeGate::Gated(Stability::Deprecated(link),
|
||||||
ref name,
|
ref name,
|
||||||
ref reason,
|
ref reason,
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#![feature(quote)]
|
#![feature(quote)]
|
||||||
#![feature(rustc_diagnostic_macros)]
|
#![feature(rustc_diagnostic_macros)]
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
|
|
|
@ -192,8 +192,6 @@ impl LintPass for UnusedAttributes {
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
|
||||||
fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
|
fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
|
||||||
debug!("checking attribute: {:?}", attr);
|
debug!("checking attribute: {:?}", attr);
|
||||||
let name = unwrap_or!(attr.name(), return);
|
|
||||||
|
|
||||||
// Note that check_name() marks the attribute as used if it matches.
|
// Note that check_name() marks the attribute as used if it matches.
|
||||||
for &(ref name, ty, _) in BUILTIN_ATTRIBUTES {
|
for &(ref name, ty, _) in BUILTIN_ATTRIBUTES {
|
||||||
match ty {
|
match ty {
|
||||||
|
@ -213,6 +211,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let name = attr.name();
|
||||||
if !attr::is_used(attr) {
|
if !attr::is_used(attr) {
|
||||||
debug!("Emitting warning for: {:?}", attr);
|
debug!("Emitting warning for: {:?}", attr);
|
||||||
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
|
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
|
||||||
|
|
|
@ -209,7 +209,7 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>, allow_derive: bool)
|
fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>, allow_derive: bool)
|
||||||
-> Option<ast::Attribute> {
|
-> Option<ast::Attribute> {
|
||||||
for i in 0..attrs.len() {
|
for i in 0..attrs.len() {
|
||||||
let name = unwrap_or!(attrs[i].name(), continue);
|
let name = attrs[i].name();
|
||||||
|
|
||||||
if self.session.plugin_attributes.borrow().iter()
|
if self.session.plugin_attributes.borrow().iter()
|
||||||
.any(|&(ref attr_nm, _)| name == &**attr_nm) {
|
.any(|&(ref attr_nm, _)| name == &**attr_nm) {
|
||||||
|
@ -231,11 +231,11 @@ impl<'a> base::Resolver for Resolver<'a> {
|
||||||
|
|
||||||
// Check for legacy derives
|
// Check for legacy derives
|
||||||
for i in 0..attrs.len() {
|
for i in 0..attrs.len() {
|
||||||
let name = unwrap_or!(attrs[i].name(), continue);
|
let name = attrs[i].name();
|
||||||
|
|
||||||
if name == "derive" {
|
if name == "derive" {
|
||||||
let result = attrs[i].parse_list(&self.session.parse_sess, |parser| {
|
let result = attrs[i].parse_list(&self.session.parse_sess, |parser| {
|
||||||
parser.parse_path(PathStyle::Mod)
|
parser.parse_path_allowing_meta(PathStyle::Mod)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut traits = match result {
|
let mut traits = match result {
|
||||||
|
|
|
@ -3661,7 +3661,7 @@ impl Clean<Vec<Item>> for doctree::Import {
|
||||||
// #[doc(no_inline)] attribute is present.
|
// #[doc(no_inline)] attribute is present.
|
||||||
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
||||||
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
|
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
|
||||||
a.name().unwrap() == "doc" && match a.meta_item_list() {
|
a.name() == "doc" && match a.meta_item_list() {
|
||||||
Some(l) => attr::list_contains_name(&l, "no_inline") ||
|
Some(l) => attr::list_contains_name(&l, "no_inline") ||
|
||||||
attr::list_contains_name(&l, "hidden"),
|
attr::list_contains_name(&l, "hidden"),
|
||||||
None => false,
|
None => false,
|
||||||
|
|
|
@ -3319,7 +3319,7 @@ fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
|
||||||
let mut attrs = String::new();
|
let mut attrs = String::new();
|
||||||
|
|
||||||
for attr in &it.attrs.other_attrs {
|
for attr in &it.attrs.other_attrs {
|
||||||
let name = attr.name().unwrap();
|
let name = attr.name();
|
||||||
if !ATTRIBUTE_WHITELIST.contains(&&*name.as_str()) {
|
if !ATTRIBUTE_WHITELIST.contains(&&*name.as_str()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,11 +217,10 @@ impl Attribute {
|
||||||
matches
|
matches
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> Option<Name> {
|
/// Returns the first segment of the name of this attribute.
|
||||||
match self.path.segments.len() {
|
/// E.g. `foo` for `#[foo]`, `rustfmt` for `#[rustfmt::skip]`.
|
||||||
1 => Some(self.path.segments[0].identifier.name),
|
pub fn name(&self) -> Name {
|
||||||
_ => None,
|
name_from_path(&self.path)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value_str(&self) -> Option<Symbol> {
|
pub fn value_str(&self) -> Option<Symbol> {
|
||||||
|
|
|
@ -26,7 +26,8 @@ pub fn collect_derives(cx: &mut ExtCtxt, attrs: &mut Vec<ast::Attribute>) -> Vec
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
match attr.parse_list(cx.parse_sess, |parser| parser.parse_path(PathStyle::Mod)) {
|
match attr.parse_list(cx.parse_sess,
|
||||||
|
|parser| parser.parse_path_allowing_meta(PathStyle::Mod)) {
|
||||||
Ok(ref traits) if traits.is_empty() => {
|
Ok(ref traits) if traits.is_empty() => {
|
||||||
cx.span_warn(attr.span, "empty trait list in `derive`");
|
cx.span_warn(attr.span, "empty trait list in `derive`");
|
||||||
false
|
false
|
||||||
|
|
|
@ -1132,7 +1132,7 @@ macro_rules! gate_feature {
|
||||||
impl<'a> Context<'a> {
|
impl<'a> Context<'a> {
|
||||||
fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) {
|
fn check_attribute(&self, attr: &ast::Attribute, is_macro: bool) {
|
||||||
debug!("check_attribute(attr = {:?})", attr);
|
debug!("check_attribute(attr = {:?})", attr);
|
||||||
let name = unwrap_or!(attr.name(), return).as_str();
|
let name = attr.name().as_str();
|
||||||
for &(n, ty, ref gateage) in BUILTIN_ATTRIBUTES {
|
for &(n, ty, ref gateage) in BUILTIN_ATTRIBUTES {
|
||||||
if name == n {
|
if name == n {
|
||||||
if let Gated(_, name, desc, ref has_feature) = *gateage {
|
if let Gated(_, name, desc, ref has_feature) = *gateage {
|
||||||
|
|
|
@ -1955,19 +1955,19 @@ impl<'a> Parser<'a> {
|
||||||
/// Like `parse_path`, but also supports parsing `Word` meta items into paths for back-compat.
|
/// Like `parse_path`, but also supports parsing `Word` meta items into paths for back-compat.
|
||||||
/// This is used when parsing derive macro paths in `#[derive]` attributes.
|
/// This is used when parsing derive macro paths in `#[derive]` attributes.
|
||||||
pub fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
|
pub fn parse_path_allowing_meta(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
|
||||||
let meta_ident = match self.token {
|
let meta_name = match self.token {
|
||||||
token::Interpolated(ref nt) => match nt.0 {
|
token::Interpolated(ref nt) => match nt.0 {
|
||||||
token::NtMeta(ref meta) => match meta.node {
|
token::NtMeta(ref meta) => match meta.node {
|
||||||
ast::MetaItemKind::Word => Some(meta.ident),
|
ast::MetaItemKind::Word => Some(meta.name.clone()),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
if let Some(ident) = meta_ident {
|
if let Some(path) = meta_name {
|
||||||
self.bump();
|
self.bump();
|
||||||
return Ok(ast::Path::from_ident(ident));
|
return Ok(path);
|
||||||
}
|
}
|
||||||
self.parse_path(style)
|
self.parse_path(style)
|
||||||
}
|
}
|
||||||
|
|
|
@ -776,6 +776,7 @@ pub trait PrintState<'a> {
|
||||||
ast::MetaItemKind::Word => self.print_attribute_path(&item.name)?,
|
ast::MetaItemKind::Word => self.print_attribute_path(&item.name)?,
|
||||||
ast::MetaItemKind::NameValue(ref value) => {
|
ast::MetaItemKind::NameValue(ref value) => {
|
||||||
self.print_attribute_path(&item.name)?;
|
self.print_attribute_path(&item.name)?;
|
||||||
|
self.writer().space()?;
|
||||||
self.word_space("=")?;
|
self.word_space("=")?;
|
||||||
self.print_literal(value)?;
|
self.print_literal(value)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,11 @@ struct MarkAttrs<'a>(&'a [ast::Name]);
|
||||||
|
|
||||||
impl<'a> Visitor<'a> for MarkAttrs<'a> {
|
impl<'a> Visitor<'a> for MarkAttrs<'a> {
|
||||||
fn visit_attribute(&mut self, attr: &Attribute) {
|
fn visit_attribute(&mut self, attr: &Attribute) {
|
||||||
if let Some(name) = attr.name() {
|
if self.0.contains(&attr.name()) {
|
||||||
if self.0.contains(&name) {
|
|
||||||
mark_used(attr);
|
mark_used(attr);
|
||||||
mark_known(attr);
|
mark_known(attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_mac(&mut self, _mac: &Mac) {}
|
fn visit_mac(&mut self, _mac: &Mac) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,7 +472,7 @@ impl<'a> TraitDef<'a> {
|
||||||
attrs.extend(item.attrs
|
attrs.extend(item.attrs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|a| {
|
.filter(|a| {
|
||||||
a.name().is_some() && match &*a.name().unwrap().as_str() {
|
match &*a.name().as_str() {
|
||||||
"allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true,
|
"allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue