Skip to content

Commit d2be8d9

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

File tree

1 file changed

+42
-52
lines changed

1 file changed

+42
-52
lines changed

clippy_utils/src/attrs.rs

Lines changed: 42 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,41 @@ 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(attr_segments) = attr.ident_path()
73+
&& let [clippy, segment2] = attr_segments.as_slice()
74+
&& clippy.name == sym::clippy
75+
{
76+
let Some((_, deprecation_status)) = BUILTIN_ATTRIBUTES
7877
.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-
)
78+
.find(|(builtin_name, _)| segment2.name == *builtin_name)
79+
else {
80+
sess.dcx().span_err(segment2.span, "usage of unknown attribute");
81+
return false;
82+
};
83+
84+
let mut diag = sess
85+
.dcx()
86+
.struct_span_err(segment2.span, "usage of deprecated attribute");
87+
match deprecation_status {
88+
DeprecationStatus::Deprecated => {
89+
diag.emit();
90+
false
91+
},
92+
DeprecationStatus::Replaced(new_name) => {
93+
diag.span_suggestion(
94+
segment2.span,
95+
"consider using",
96+
new_name,
97+
Applicability::MachineApplicable,
98+
);
99+
diag.emit();
100+
false
101+
},
102+
DeprecationStatus::None => {
103+
diag.cancel();
104+
segment2.name == name
105+
},
106+
}
117107
} else {
118108
false
119109
}
@@ -122,15 +112,15 @@ pub fn get_attr<'a, A: AttributeExt + 'a>(
122112

123113
fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[impl AttributeExt], name: Symbol, mut f: F) {
124114
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 {
115+
let Some(value) = attr.value_str() else {
132116
sess.dcx().span_err(attr.span(), "bad clippy attribute");
133-
}
117+
continue;
118+
};
119+
let Ok(value) = u64::from_str(value.as_str()) else {
120+
sess.dcx().span_err(attr.span(), "not a number");
121+
continue;
122+
};
123+
f(value);
134124
}
135125
}
136126

0 commit comments

Comments
 (0)