@@ -6,7 +6,7 @@ use rustc_session::declare_lint_pass;
6
6
use rustc_span:: Span ;
7
7
8
8
use clippy_utils:: diagnostics:: span_lint_and_then;
9
- use clippy_utils:: source:: snippet_with_applicability;
9
+ use clippy_utils:: source:: { snippet_with_applicability, snippet_with_context } ;
10
10
use clippy_utils:: ty:: has_iter_method;
11
11
use clippy_utils:: { is_trait_method, sym} ;
12
12
@@ -101,18 +101,23 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
101
101
102
102
let body_param_sugg = snippet_with_applicability ( cx, body. params [ 0 ] . pat . span , ".." , & mut applicability) ;
103
103
let for_each_rev_sugg = snippet_with_applicability ( cx, for_each_recv. span , ".." , & mut applicability) ;
104
- let body_value_sugg = snippet_with_applicability ( cx, body. value . span , ".." , & mut applicability) ;
104
+ let ( body_value_sugg, is_macro_call) =
105
+ snippet_with_context ( cx, body. value . span , for_each_recv. span . ctxt ( ) , ".." , & mut applicability) ;
105
106
106
107
let sugg = format ! (
107
108
"for {} in {} {}" ,
108
109
body_param_sugg,
109
110
for_each_rev_sugg,
110
- match body. value. kind {
111
- ExprKind :: Block ( block, _) if is_let_desugar( block) => {
112
- format!( "{{ {body_value_sugg} }}" )
113
- } ,
114
- ExprKind :: Block ( _, _) => body_value_sugg. to_string( ) ,
115
- _ => format!( "{{ {body_value_sugg}; }}" ) ,
111
+ if is_macro_call {
112
+ format!( "{{ {body_value_sugg}; }}" )
113
+ } else {
114
+ match body. value. kind {
115
+ ExprKind :: Block ( block, _) if is_let_desugar( block) => {
116
+ format!( "{{ {body_value_sugg} }}" )
117
+ } ,
118
+ ExprKind :: Block ( _, _) => body_value_sugg. to_string( ) ,
119
+ _ => format!( "{{ {body_value_sugg}; }}" ) ,
120
+ }
116
121
}
117
122
) ;
118
123
0 commit comments