1- use clippy_utils:: diagnostics:: span_lint_and_help;
1+ use clippy_utils:: { diagnostics:: span_lint_and_help, source :: snippet } ;
22use rustc_ast:: {
33 node_id:: NodeSet ,
44 visit:: { walk_block, walk_item, Visitor } ,
@@ -86,6 +86,10 @@ impl ExcessiveNesting {
8686
8787impl EarlyLintPass for ExcessiveNesting {
8888 fn check_crate ( & mut self , cx : & EarlyContext < ' _ > , krate : & Crate ) {
89+ if self . excessive_nesting_threshold == 0 {
90+ return ;
91+ }
92+
8993 let mut visitor = NestingVisitor {
9094 conf : self ,
9195 cx,
@@ -114,9 +118,7 @@ struct NestingVisitor<'conf, 'cx> {
114118
115119impl NestingVisitor < ' _ , ' _ > {
116120 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) {
120122 self . conf . nodes . insert ( id) ;
121123
122124 return true ;
@@ -132,6 +134,13 @@ impl<'conf, 'cx> Visitor<'_> for NestingVisitor<'conf, 'cx> {
132134 return ;
133135 }
134136
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+
135144 self . nest_level += 1 ;
136145
137146 if !self . check_indent ( block. span , block. id ) {
0 commit comments