@@ -261,60 +261,65 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
261
261
}
262
262
}
263
263
264
- fn check_stmt ( & mut self , cx : & LateContext < ' a , ' tcx > , s : & ' tcx Stmt ) {
264
+ fn check_stmt ( & mut self , cx : & LateContext < ' a , ' tcx > , stmt : & ' tcx Stmt ) {
265
265
if_chain ! {
266
- if let StmtKind :: Local ( ref l ) = s . node;
267
- if let PatKind :: Binding ( an, .., i , None ) = l . pat. node;
268
- if let Some ( ref init) = l . init;
266
+ if let StmtKind :: Local ( ref local ) = stmt . node;
267
+ if let PatKind :: Binding ( an, .., name , None ) = local . pat. node;
268
+ if let Some ( ref init) = local . init;
269
269
then {
270
270
if an == BindingAnnotation :: Ref || an == BindingAnnotation :: RefMut {
271
- let sugg_init = Sugg :: hir( cx, init, ".." ) ;
272
- let ( mutopt, initref) = if an == BindingAnnotation :: RefMut {
271
+ let sugg_init = if init. span. from_expansion( ) {
272
+ Sugg :: hir_with_macro_callsite( cx, init, ".." )
273
+ } else {
274
+ Sugg :: hir( cx, init, ".." )
275
+ } ;
276
+ let ( mutopt, initref) = if an == BindingAnnotation :: RefMut {
273
277
( "mut " , sugg_init. mut_addr( ) )
274
278
} else {
275
279
( "" , sugg_init. addr( ) )
276
280
} ;
277
- let tyopt = if let Some ( ref ty) = l . ty {
281
+ let tyopt = if let Some ( ref ty) = local . ty {
278
282
format!( ": &{mutopt}{ty}" , mutopt=mutopt, ty=snippet( cx, ty. span, "_" ) )
279
283
} else {
280
284
String :: new( )
281
285
} ;
282
- span_lint_hir_and_then( cx,
286
+ span_lint_hir_and_then(
287
+ cx,
283
288
TOPLEVEL_REF_ARG ,
284
289
init. hir_id,
285
- l . pat. span,
290
+ local . pat. span,
286
291
"`ref` on an entire `let` pattern is discouraged, take a reference with `&` instead" ,
287
292
|db| {
288
293
db. span_suggestion(
289
- s . span,
294
+ stmt . span,
290
295
"try" ,
291
296
format!(
292
297
"let {name}{tyopt} = {initref};" ,
293
- name=snippet( cx, i . span, "_" ) ,
298
+ name=snippet( cx, name . span, "_" ) ,
294
299
tyopt=tyopt,
295
300
initref=initref,
296
301
) ,
297
- Applicability :: MachineApplicable , // snippet
302
+ Applicability :: MachineApplicable ,
298
303
) ;
299
304
}
300
305
) ;
301
306
}
302
307
}
303
308
} ;
304
309
if_chain ! {
305
- if let StmtKind :: Semi ( ref expr) = s . node;
310
+ if let StmtKind :: Semi ( ref expr) = stmt . node;
306
311
if let ExprKind :: Binary ( ref binop, ref a, ref b) = expr. node;
307
312
if binop. node == BinOpKind :: And || binop. node == BinOpKind :: Or ;
308
313
if let Some ( sugg) = Sugg :: hir_opt( cx, a) ;
309
314
then {
310
315
span_lint_and_then( cx,
311
316
SHORT_CIRCUIT_STATEMENT ,
312
- s . span,
317
+ stmt . span,
313
318
"boolean short circuit operator in statement may be clearer using an explicit test" ,
314
319
|db| {
315
320
let sugg = if binop. node == BinOpKind :: Or { !sugg } else { sugg } ;
316
321
db. span_suggestion(
317
- s . span,
322
+ stmt . span,
318
323
"replace it with" ,
319
324
format!(
320
325
"if {} {{ {}; }}" ,
0 commit comments