1
- use clippy_utils:: diagnostics:: span_lint_and_help;
1
+ use clippy_utils:: { diagnostics:: span_lint_and_help, source :: snippet } ;
2
2
use rustc_ast:: {
3
3
node_id:: NodeSet ,
4
4
visit:: { walk_block, walk_item, Visitor } ,
@@ -86,6 +86,10 @@ impl ExcessiveNesting {
86
86
87
87
impl EarlyLintPass for ExcessiveNesting {
88
88
fn check_crate ( & mut self , cx : & EarlyContext < ' _ > , krate : & Crate ) {
89
+ if self . excessive_nesting_threshold == 0 {
90
+ return ;
91
+ }
92
+
89
93
let mut visitor = NestingVisitor {
90
94
conf : self ,
91
95
cx,
@@ -114,9 +118,7 @@ struct NestingVisitor<'conf, 'cx> {
114
118
115
119
impl NestingVisitor < ' _ , ' _ > {
116
120
fn check_indent ( & mut self , span : Span , id : NodeId ) -> bool {
117
- let threshold = self . conf . excessive_nesting_threshold ;
118
-
119
- if threshold != 0 && self . nest_level > threshold && !in_external_macro ( self . cx . sess ( ) , span) {
121
+ if self . nest_level > self . conf . excessive_nesting_threshold && !in_external_macro ( self . cx . sess ( ) , span) {
120
122
self . conf . nodes . insert ( id) ;
121
123
122
124
return true ;
@@ -132,6 +134,13 @@ impl<'conf, 'cx> Visitor<'_> for NestingVisitor<'conf, 'cx> {
132
134
return ;
133
135
}
134
136
137
+ // TODO: This should be rewritten using `LateLintPass` so we can use `is_from_proc_macro` instead,
138
+ // but for now, this is fine.
139
+ let snippet = snippet ( self . cx , block. span , "{}" ) . trim ( ) . to_owned ( ) ;
140
+ if !snippet. starts_with ( '{' ) || !snippet. ends_with ( '}' ) {
141
+ return ;
142
+ }
143
+
135
144
self . nest_level += 1 ;
136
145
137
146
if !self . check_indent ( block. span , block. id ) {
0 commit comments