@@ -12,29 +12,6 @@ use rustc_session::Session;
1212use rustc_span:: { Span , Symbol } ;
1313use std:: str:: FromStr ;
1414
15- /// Deprecation status of attributes known by Clippy.
16- pub enum DeprecationStatus {
17- /// Attribute is deprecated
18- Deprecated ,
19- /// Attribute is deprecated and was replaced by the named attribute
20- Replaced ( & ' static str ) ,
21- None ,
22- }
23-
24- #[ rustfmt:: skip]
25- pub const BUILTIN_ATTRIBUTES : & [ ( Symbol , DeprecationStatus ) ] = & [
26- ( sym:: author, DeprecationStatus :: None ) ,
27- ( sym:: version, DeprecationStatus :: None ) ,
28- ( sym:: cognitive_complexity, DeprecationStatus :: None ) ,
29- ( sym:: cyclomatic_complexity, DeprecationStatus :: Replaced ( "cognitive_complexity" ) ) ,
30- ( sym:: dump, DeprecationStatus :: None ) ,
31- ( sym:: msrv, DeprecationStatus :: None ) ,
32- // The following attributes are for the 3rd party crate authors.
33- // See book/src/attribs.md
34- ( sym:: has_significant_drop, DeprecationStatus :: None ) ,
35- ( sym:: format_args, DeprecationStatus :: None ) ,
36- ] ;
37-
3815pub struct LimitStack {
3916 stack : Vec < u64 > ,
4017}
@@ -72,36 +49,37 @@ pub fn get_attr<'a, A: AttributeExt + 'a>(
7249 if let Some ( [ clippy, segment2] ) = attr. ident_path ( ) . as_deref ( )
7350 && clippy. name == sym:: clippy
7451 {
75- let Some ( ( _, deprecation_status) ) = BUILTIN_ATTRIBUTES
76- . iter ( )
77- . find ( |( builtin_name, _) | segment2. name == * builtin_name)
78- else {
79- sess. dcx ( ) . span_err ( segment2. span , "usage of unknown attribute" ) ;
80- return false ;
52+ let new_name = match segment2. name {
53+ sym:: cyclomatic_complexity => Some ( "cognitive_complexity" ) ,
54+ sym:: author
55+ | sym:: version
56+ | sym:: cognitive_complexity
57+ | sym:: dump
58+ | sym:: msrv
59+ // The following attributes are for the 3rd party crate authors.
60+ // See book/src/attribs.md
61+ | sym:: has_significant_drop
62+ | sym:: format_args => None ,
63+ _ => {
64+ sess. dcx ( ) . span_err ( segment2. span , "usage of unknown attribute" ) ;
65+ return false ;
66+ } ,
8167 } ;
8268
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 ( ) ;
69+ match new_name {
70+ Some ( new_name) => {
71+ sess. dcx ( )
72+ . struct_span_err ( segment2. span , "usage of deprecated attribute" )
73+ . with_span_suggestion (
74+ segment2. span ,
75+ "consider using" ,
76+ new_name,
77+ Applicability :: MachineApplicable ,
78+ )
79+ . emit ( ) ;
8980 false
9081 } ,
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- } ,
82+ None => segment2. name == name,
10583 }
10684 } else {
10785 false
0 commit comments