Skip to content

Commit f2b4234

Browse files
committed
Remove Option from the return type of Attribute::name()
1 parent b93af01 commit f2b4234

File tree

17 files changed

+46
-36
lines changed

17 files changed

+46
-36
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
5050
self.tcx.target_features_enabled(self.tcx.hir.local_def_id(item.id));
5151

5252
for attr in &item.attrs {
53-
if let Some(name) = attr.name() {
54-
if name == "inline" {
55-
self.check_inline(attr, item, target)
56-
}
53+
if attr.name() == "inline" {
54+
self.check_inline(attr, item, target)
5755
}
5856
}
5957

@@ -81,10 +79,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
8179
// ```
8280
let hints: Vec<_> = item.attrs
8381
.iter()
84-
.filter(|attr| match attr.name() {
85-
Some(name) => name == "repr",
86-
None => false,
87-
})
82+
.filter(|attr| attr.name() == "repr")
8883
.filter_map(|attr| attr.meta_item_list())
8984
.flat_map(|hints| hints)
9085
.collect();

src/librustc/ich/impls_syntax.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for [ast::Attribute] {
178178
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
179179
.iter()
180180
.filter(|attr| {
181-
!attr.is_sugared_doc &&
182-
attr.name().map(|name| !hcx.is_ignored_attr(name)).unwrap_or(true)
181+
!attr.is_sugared_doc && !hcx.is_ignored_attr(attr.name())
183182
})
184183
.collect();
185184

@@ -206,7 +205,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::Attribute {
206205
hcx: &mut StableHashingContext<'gcx>,
207206
hasher: &mut StableHasher<W>) {
208207
// Make sure that these have been filtered out.
209-
debug_assert!(self.name().map(|name| !hcx.is_ignored_attr(name)).unwrap_or(true));
208+
debug_assert!(!hcx.is_ignored_attr(self.name()));
210209
debug_assert!(!self.is_sugared_doc);
211210

212211
let ast::Attribute {

src/librustc/lint/levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'a> LintLevelsBuilder<'a> {
197197
"malformed lint attribute");
198198
};
199199
for attr in attrs {
200-
let level = match attr.name().and_then(|name| Level::from_str(&name.as_str())) {
200+
let level = match Level::from_str(&attr.name().as_str()) {
201201
None => continue,
202202
Some(lvl) => lvl,
203203
};

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
205205
} else {
206206
// Emit errors for non-staged-api crates.
207207
for attr in attrs {
208-
let tag = unwrap_or!(attr.name(), continue);
208+
let tag = attr.name();
209209
if tag == "unstable" || tag == "stable" || tag == "rustc_deprecated" {
210210
attr::mark_used(attr);
211211
self.tcx.sess.span_err(attr.span(), "stability attributes may not be used \

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,8 @@ impl LintPass for DeprecatedAttr {
663663

664664
impl EarlyLintPass for DeprecatedAttr {
665665
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
666-
let name = unwrap_or!(attr.name(), return);
667666
for &&(n, _, ref g) in &self.depr_attrs {
668-
if name == n {
667+
if attr.name() == n {
669668
if let &AttributeGate::Gated(Stability::Deprecated(link),
670669
ref name,
671670
ref reason,

src/librustc_lint/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#![feature(rustc_diagnostic_macros)]
3434
#![feature(slice_patterns)]
3535

36-
#[macro_use]
3736
extern crate syntax;
3837
#[macro_use]
3938
extern crate rustc;

src/librustc_lint/unused.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ impl LintPass for UnusedAttributes {
174174
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
175175
fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
176176
debug!("checking attribute: {:?}", attr);
177-
let name = unwrap_or!(attr.name(), return);
178-
179177
// Note that check_name() marks the attribute as used if it matches.
180178
for &(ref name, ty, _) in BUILTIN_ATTRIBUTES {
181179
match ty {
@@ -195,6 +193,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
195193
}
196194
}
197195

196+
let name = attr.name();
198197
if !attr::is_used(attr) {
199198
debug!("Emitting warning for: {:?}", attr);
200199
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");

src/librustc_resolve/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'a> base::Resolver for Resolver<'a> {
210210
fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>)
211211
-> Option<ast::Attribute> {
212212
for i in 0..attrs.len() {
213-
let name = unwrap_or!(attrs[i].name(), continue);
213+
let name = attrs[i].name();
214214

215215
if self.session.plugin_attributes.borrow().iter()
216216
.any(|&(ref attr_nm, _)| name == &**attr_nm) {
@@ -230,11 +230,11 @@ impl<'a> base::Resolver for Resolver<'a> {
230230

231231
// Check for legacy derives
232232
for i in 0..attrs.len() {
233-
let name = unwrap_or!(attrs[i].name(), continue);
233+
let name = attrs[i].name();
234234

235235
if name == "derive" {
236236
let result = attrs[i].parse_list(&self.session.parse_sess, |parser| {
237-
parser.parse_path(PathStyle::Mod)
237+
parser.parse_path_allowing_meta(PathStyle::Mod)
238238
});
239239

240240
let mut traits = match result {

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3359,7 +3359,7 @@ impl Clean<Vec<Item>> for doctree::Import {
33593359
// #[doc(no_inline)] attribute is present.
33603360
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
33613361
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
3362-
a.name().unwrap() == "doc" && match a.meta_item_list() {
3362+
a.name() == "doc" && match a.meta_item_list() {
33633363
Some(l) => attr::list_contains_name(&l, "no_inline") ||
33643364
attr::list_contains_name(&l, "hidden"),
33653365
None => false,

src/librustdoc/html/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3077,7 +3077,7 @@ fn render_attributes(w: &mut fmt::Formatter, it: &clean::Item) -> fmt::Result {
30773077
let mut attrs = String::new();
30783078

30793079
for attr in &it.attrs.other_attrs {
3080-
let name = attr.name().unwrap();
3080+
let name = attr.name();
30813081
if !ATTRIBUTE_WHITELIST.contains(&&*name.as_str()) {
30823082
continue;
30833083
}

0 commit comments

Comments
 (0)