Skip to content

Commit a5c08fd

Browse files
committed
merge DeprecationStatus::{Replaced,Deprecated}
Their meanings, and the way they're handled in `get_attr`, are pretty similar
1 parent d2be8d9 commit a5c08fd

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

clippy_utils/src/attrs.rs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ use std::str::FromStr;
1414

1515
/// Deprecation status of attributes known by Clippy.
1616
pub enum DeprecationStatus {
17-
/// Attribute is deprecated
18-
Deprecated,
19-
/// Attribute is deprecated and was replaced by the named attribute
20-
Replaced(&'static str),
17+
/// Attribute is deprecated and was possibly replaced by the named attribute
18+
Deprecated(Option<&'static str>),
2119
None,
2220
}
2321

@@ -26,7 +24,7 @@ pub const BUILTIN_ATTRIBUTES: &[(Symbol, DeprecationStatus)] = &[
2624
(sym::author, DeprecationStatus::None),
2725
(sym::version, DeprecationStatus::None),
2826
(sym::cognitive_complexity, DeprecationStatus::None),
29-
(sym::cyclomatic_complexity, DeprecationStatus::Replaced("cognitive_complexity")),
27+
(sym::cyclomatic_complexity, DeprecationStatus::Deprecated(Some("cognitive_complexity"))),
3028
(sym::dump, DeprecationStatus::None),
3129
(sym::msrv, DeprecationStatus::None),
3230
// The following attributes are for the 3rd party crate authors.
@@ -81,28 +79,23 @@ pub fn get_attr<'a, A: AttributeExt + 'a>(
8179
return false;
8280
};
8381

84-
let mut diag = sess
85-
.dcx()
86-
.struct_span_err(segment2.span, "usage of deprecated attribute");
8782
match deprecation_status {
88-
DeprecationStatus::Deprecated => {
83+
DeprecationStatus::Deprecated(new_name) => {
84+
let mut diag = sess
85+
.dcx()
86+
.struct_span_err(segment2.span, "usage of deprecated attribute");
87+
if let Some(new_name) = new_name {
88+
diag.span_suggestion(
89+
segment2.span,
90+
"consider using",
91+
new_name,
92+
Applicability::MachineApplicable,
93+
);
94+
}
8995
diag.emit();
9096
false
9197
},
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-
},
98+
DeprecationStatus::None => segment2.name == name,
10699
}
107100
} else {
108101
false

0 commit comments

Comments
 (0)