@@ -37,35 +37,6 @@ pub const BUILTIN_ATTRIBUTES: &[(Symbol, DeprecationStatus)] = &[
37
37
( sym:: format_args, DeprecationStatus :: None ) ,
38
38
] ;
39
39
40
- pub struct LimitStack {
41
- stack : Vec < u64 > ,
42
- }
43
-
44
- impl Drop for LimitStack {
45
- fn drop ( & mut self ) {
46
- assert_eq ! ( self . stack. len( ) , 1 ) ;
47
- }
48
- }
49
-
50
- #[ expect( missing_docs, reason = "they're all trivial..." ) ]
51
- impl LimitStack {
52
- #[ must_use]
53
- pub fn new ( limit : u64 ) -> Self {
54
- Self { stack : vec ! [ limit] }
55
- }
56
- pub fn limit ( & self ) -> u64 {
57
- * self . stack . last ( ) . expect ( "there should always be a value in the stack" )
58
- }
59
- pub fn push_attrs ( & mut self , sess : & Session , attrs : & [ impl AttributeExt ] , name : Symbol ) {
60
- let stack = & mut self . stack ;
61
- parse_attrs ( sess, attrs, name, |val| stack. push ( val) ) ;
62
- }
63
- pub fn pop_attrs ( & mut self , sess : & Session , attrs : & [ impl AttributeExt ] , name : Symbol ) {
64
- let stack = & mut self . stack ;
65
- parse_attrs ( sess, attrs, name, |val| assert_eq ! ( stack. pop( ) , Some ( val) ) ) ;
66
- }
67
- }
68
-
69
40
/// Given `attrs`, extract all the instances of a built-in Clippy attribute called `name`
70
41
pub fn get_builtin_attr < ' a , A : AttributeExt + ' a > (
71
42
sess : & ' a Session ,
@@ -109,20 +80,6 @@ pub fn get_builtin_attr<'a, A: AttributeExt + 'a>(
109
80
} )
110
81
}
111
82
112
- fn parse_attrs < F : FnMut ( u64 ) > ( sess : & Session , attrs : & [ impl AttributeExt ] , name : Symbol , mut f : F ) {
113
- for attr in get_builtin_attr ( sess, attrs, name) {
114
- let Some ( value) = attr. value_str ( ) else {
115
- sess. dcx ( ) . span_err ( attr. span ( ) , "bad clippy attribute" ) ;
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) ;
123
- }
124
- }
125
-
126
83
/// If `attrs` contain exactly one instance of a built-in Clippy attribute called `name`,
127
84
/// returns that attribute, and `None` otherwise
128
85
pub fn get_unique_builtin_attr < ' a , A : AttributeExt > ( sess : & ' a Session , attrs : & ' a [ A ] , name : Symbol ) -> Option < & ' a A > {
@@ -190,3 +147,51 @@ pub fn span_contains_cfg(cx: &LateContext<'_>, s: Span) -> bool {
190
147
false
191
148
} )
192
149
}
150
+
151
+ /// Currently used to keep track of the current value of `#[clippy::cognitive_complexity(N)]`
152
+ pub struct LimitStack {
153
+ default : u64 ,
154
+ stack : Vec < u64 > ,
155
+ }
156
+
157
+ impl Drop for LimitStack {
158
+ fn drop ( & mut self ) {
159
+ assert_eq ! ( self . stack, Vec :: <u64 >:: new( ) ) ; // avoid `.is_empty()`, for a nicer error message
160
+ }
161
+ }
162
+
163
+ #[ expect( missing_docs, reason = "they're all trivial..." ) ]
164
+ impl LimitStack {
165
+ #[ must_use]
166
+ pub fn new ( limit : u64 ) -> Self {
167
+ Self {
168
+ default : limit,
169
+ stack : vec ! [ ] ,
170
+ }
171
+ }
172
+ pub fn limit ( & self ) -> u64 {
173
+ self . stack . last ( ) . copied ( ) . unwrap_or ( self . default )
174
+ }
175
+ pub fn push_attrs ( & mut self , sess : & Session , attrs : & [ impl AttributeExt ] , name : Symbol ) {
176
+ let stack = & mut self . stack ;
177
+ parse_attrs ( sess, attrs, name, |val| stack. push ( val) ) ;
178
+ }
179
+ pub fn pop_attrs ( & mut self , sess : & Session , attrs : & [ impl AttributeExt ] , name : Symbol ) {
180
+ let stack = & mut self . stack ;
181
+ parse_attrs ( sess, attrs, name, |val| assert_eq ! ( stack. pop( ) , Some ( val) ) ) ;
182
+ }
183
+ }
184
+
185
+ fn parse_attrs < F : FnMut ( u64 ) > ( sess : & Session , attrs : & [ impl AttributeExt ] , name : Symbol , mut f : F ) {
186
+ for attr in get_builtin_attr ( sess, attrs, name) {
187
+ let Some ( value) = attr. value_str ( ) else {
188
+ sess. dcx ( ) . span_err ( attr. span ( ) , "bad clippy attribute" ) ;
189
+ continue ;
190
+ } ;
191
+ let Ok ( value) = u64:: from_str ( value. as_str ( ) ) else {
192
+ sess. dcx ( ) . span_err ( attr. span ( ) , "not a number" ) ;
193
+ continue ;
194
+ } ;
195
+ f ( value) ;
196
+ }
197
+ }
0 commit comments