Skip to content

Commit 9b3aea6

Browse files
topecongiroflip1995
authored andcommitted
Remove Option from the return type of Attribute::name()
1 parent 759bd01 commit 9b3aea6

File tree

17 files changed

+28
-36
lines changed

17 files changed

+28
-36
lines changed

src/librustc/hir/check_attr.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
153153
// ```
154154
let hints: Vec<_> = item.attrs
155155
.iter()
156-
.filter(|attr| match attr.name() {
157-
Some(name) => name == "repr",
158-
None => false,
159-
})
156+
.filter(|attr| attr.name() == "repr")
160157
.filter_map(|attr| attr.meta_item_list())
161158
.flat_map(|hints| hints)
162159
.collect();

src/librustc/ich/impls_syntax.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
199199
let filtered: AccumulateVec<[&ast::Attribute; 8]> = self
200200
.iter()
201201
.filter(|attr| {
202-
!attr.is_sugared_doc &&
203-
attr.name().map(|name| !hcx.is_ignored_attr(name)).unwrap_or(true)
202+
!attr.is_sugared_doc && !hcx.is_ignored_attr(attr.name())
204203
})
205204
.collect();
206205

@@ -227,7 +226,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Attribute {
227226
hcx: &mut StableHashingContext<'a>,
228227
hasher: &mut StableHasher<W>) {
229228
// Make sure that these have been filtered out.
230-
debug_assert!(self.name().map(|name| !hcx.is_ignored_attr(name)).unwrap_or(true));
229+
debug_assert!(!hcx.is_ignored_attr(self.name()));
231230
debug_assert!(!self.is_sugared_doc);
232231

233232
let ast::Attribute {

src/librustc/lint/levels.rs

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

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
@@ -675,9 +675,8 @@ impl LintPass for DeprecatedAttr {
675675

676676
impl EarlyLintPass for DeprecatedAttr {
677677
fn check_attribute(&mut self, cx: &EarlyContext, attr: &ast::Attribute) {
678-
let name = unwrap_or!(attr.name(), return);
679678
for &&(n, _, ref g) in &self.depr_attrs {
680-
if name == n {
679+
if attr.name() == n {
681680
if let &AttributeGate::Gated(Stability::Deprecated(link),
682681
ref name,
683682
ref reason,

src/librustc_lint/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#![feature(quote)]
3131
#![feature(rustc_diagnostic_macros)]
3232

33-
#[macro_use]
3433
extern crate syntax;
3534
#[macro_use]
3635
extern crate rustc;

src/librustc_lint/unused.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ impl LintPass for UnusedAttributes {
192192
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
193193
fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) {
194194
debug!("checking attribute: {:?}", attr);
195-
let name = unwrap_or!(attr.name(), return);
196-
197195
// Note that check_name() marks the attribute as used if it matches.
198196
for &(ref name, ty, _) in BUILTIN_ATTRIBUTES {
199197
match ty {
@@ -213,6 +211,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes {
213211
}
214212
}
215213

214+
let name = attr.name();
216215
if !attr::is_used(attr) {
217216
debug!("Emitting warning for: {:?}", attr);
218217
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
@@ -209,7 +209,7 @@ impl<'a> base::Resolver for Resolver<'a> {
209209
fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>, allow_derive: bool)
210210
-> Option<ast::Attribute> {
211211
for i in 0..attrs.len() {
212-
let name = unwrap_or!(attrs[i].name(), continue);
212+
let name = attrs[i].name();
213213

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

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

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

241241
let mut traits = match result {

src/librustdoc/clean/mod.rs

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

src/librustdoc/html/render.rs

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

33213321
for attr in &it.attrs.other_attrs {
3322-
let name = attr.name().unwrap();
3322+
let name = attr.name();
33233323
if !ATTRIBUTE_WHITELIST.contains(&&*name.as_str()) {
33243324
continue;
33253325
}

0 commit comments

Comments
 (0)