@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
2
2
use clippy_utils:: higher:: IfLetOrMatch ;
3
3
use clippy_utils:: msrvs:: { self , Msrv } ;
4
4
use clippy_utils:: peel_blocks;
5
- use clippy_utils:: source:: snippet_opt ;
5
+ use clippy_utils:: source:: { snippet , snippet_with_macro_callsite } ;
6
6
use clippy_utils:: ty:: is_type_diagnostic_item;
7
7
use clippy_utils:: visitors:: { for_each_expr, Descend } ;
8
8
use if_chain:: if_chain;
@@ -143,18 +143,22 @@ fn emit_manual_let_else(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, pat:
143
143
// for this to be machine applicable.
144
144
let app = Applicability :: HasPlaceholders ;
145
145
146
- if let Some ( sn_pat) = snippet_opt ( cx, pat. span ) &&
147
- let Some ( sn_expr) = snippet_opt ( cx, expr. span ) &&
148
- let Some ( sn_else) = snippet_opt ( cx, else_body. span )
149
- {
150
- let else_bl = if matches ! ( else_body. kind, ExprKind :: Block ( ..) ) {
151
- sn_else
152
- } else {
153
- format ! ( "{{ {sn_else} }}" )
154
- } ;
155
- let sugg = format ! ( "let {sn_pat} = {sn_expr} else {else_bl};" ) ;
156
- diag. span_suggestion ( span, "consider writing" , sugg, app) ;
157
- }
146
+ let snippet_fn = if span. from_expansion ( ) {
147
+ snippet
148
+ } else {
149
+ snippet_with_macro_callsite
150
+ } ;
151
+ let sn_pat = snippet_fn ( cx, pat. span , "" ) ;
152
+ let sn_expr = snippet_fn ( cx, expr. span , "" ) ;
153
+ let sn_else = snippet_fn ( cx, else_body. span , "" ) ;
154
+
155
+ let else_bl = if matches ! ( else_body. kind, ExprKind :: Block ( ..) ) {
156
+ sn_else. into_owned ( )
157
+ } else {
158
+ format ! ( "{{ {sn_else} }}" )
159
+ } ;
160
+ let sugg = format ! ( "let {sn_pat} = {sn_expr} else {else_bl};" ) ;
161
+ diag. span_suggestion ( span, "consider writing" , sugg, app) ;
158
162
} ,
159
163
) ;
160
164
}
0 commit comments