Skip to content

Commit dafd683

Browse files
committed
clean-up
1 parent 4b236fc commit dafd683

File tree

1 file changed

+41
-52
lines changed

1 file changed

+41
-52
lines changed

clippy_utils/src/attrs.rs

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,40 @@ pub fn get_attr<'a, A: AttributeExt + 'a>(
6969
name: Symbol,
7070
) -> impl Iterator<Item = &'a A> {
7171
attrs.iter().filter(move |attr| {
72-
let Some(attr_segments) = attr.ident_path() else {
73-
return false;
74-
};
75-
76-
if attr_segments.len() == 2 && attr_segments[0].name == sym::clippy {
77-
BUILTIN_ATTRIBUTES
72+
if let Some([clippy, segment2]) = attr.ident_path().as_deref()
73+
&& clippy.name == sym::clippy
74+
{
75+
let Some((_, deprecation_status)) = BUILTIN_ATTRIBUTES
7876
.iter()
79-
.find_map(|(builtin_name, deprecation_status)| {
80-
if attr_segments[1].name == *builtin_name {
81-
Some(deprecation_status)
82-
} else {
83-
None
84-
}
85-
})
86-
.map_or_else(
87-
|| {
88-
sess.dcx().span_err(attr_segments[1].span, "usage of unknown attribute");
89-
false
90-
},
91-
|deprecation_status| {
92-
let mut diag = sess
93-
.dcx()
94-
.struct_span_err(attr_segments[1].span, "usage of deprecated attribute");
95-
match *deprecation_status {
96-
DeprecationStatus::Deprecated => {
97-
diag.emit();
98-
false
99-
},
100-
DeprecationStatus::Replaced(new_name) => {
101-
diag.span_suggestion(
102-
attr_segments[1].span,
103-
"consider using",
104-
new_name,
105-
Applicability::MachineApplicable,
106-
);
107-
diag.emit();
108-
false
109-
},
110-
DeprecationStatus::None => {
111-
diag.cancel();
112-
attr_segments[1].name == name
113-
},
114-
}
115-
},
116-
)
77+
.find(|(builtin_name, _)| segment2.name == *builtin_name)
78+
else {
79+
sess.dcx().span_err(segment2.span, "usage of unknown attribute");
80+
return false;
81+
};
82+
83+
let mut diag = sess
84+
.dcx()
85+
.struct_span_err(segment2.span, "usage of deprecated attribute");
86+
match deprecation_status {
87+
DeprecationStatus::Deprecated => {
88+
diag.emit();
89+
false
90+
},
91+
DeprecationStatus::Replaced(new_name) => {
92+
diag.span_suggestion(
93+
segment2.span,
94+
"consider using",
95+
new_name,
96+
Applicability::MachineApplicable,
97+
);
98+
diag.emit();
99+
false
100+
},
101+
DeprecationStatus::None => {
102+
diag.cancel();
103+
segment2.name == name
104+
},
105+
}
117106
} else {
118107
false
119108
}
@@ -122,15 +111,15 @@ pub fn get_attr<'a, A: AttributeExt + 'a>(
122111

123112
fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[impl AttributeExt], name: Symbol, mut f: F) {
124113
for attr in get_attr(sess, attrs, name) {
125-
if let Some(value) = attr.value_str() {
126-
if let Ok(value) = FromStr::from_str(value.as_str()) {
127-
f(value);
128-
} else {
129-
sess.dcx().span_err(attr.span(), "not a number");
130-
}
131-
} else {
114+
let Some(value) = attr.value_str() else {
132115
sess.dcx().span_err(attr.span(), "bad clippy attribute");
133-
}
116+
continue;
117+
};
118+
let Ok(value) = u64::from_str(value.as_str()) else {
119+
sess.dcx().span_err(attr.span(), "not a number");
120+
continue;
121+
};
122+
f(value);
134123
}
135124
}
136125

0 commit comments

Comments
 (0)