@@ -1580,7 +1580,6 @@ impl<'tcx> Liveness<'_, 'tcx> {
1580
1580
opt_body : Option < & hir:: Body < ' _ > > ,
1581
1581
) {
1582
1582
let first_hir_id = hir_ids_and_spans[ 0 ] . 0 ;
1583
-
1584
1583
if let Some ( name) = self . should_warn ( var) . filter ( |name| name != "self" ) {
1585
1584
// annoying: for parameters in funcs like `fn(x: i32)
1586
1585
// {ret}`, there is only one node, so asking about
@@ -1652,11 +1651,29 @@ impl<'tcx> Liveness<'_, 'tcx> {
1652
1651
} ,
1653
1652
) ;
1654
1653
} else {
1654
+ // #117284, when `pat_span` and `ident_span` have different contexts
1655
+ // we can't provide a good suggestion, instead we pointed out the spans from macro
1656
+ let from_macro = non_shorthands
1657
+ . iter ( )
1658
+ . find ( |( _, pat_span, ident_span) | {
1659
+ pat_span. ctxt ( ) != ident_span. ctxt ( ) && pat_span. from_expansion ( )
1660
+ } )
1661
+ . map ( |( _, pat_span, _) | * pat_span) ;
1655
1662
let non_shorthands = non_shorthands
1656
1663
. into_iter ( )
1657
1664
. map ( |( _, _, ident_span) | ident_span)
1658
1665
. collect :: < Vec < _ > > ( ) ;
1666
+
1659
1667
let suggestions = self . string_interp_suggestions ( & name, opt_body) ;
1668
+ let sugg = if let Some ( span) = from_macro {
1669
+ errors:: UnusedVariableSugg :: NoSugg { span, name : name. clone ( ) }
1670
+ } else {
1671
+ errors:: UnusedVariableSugg :: TryPrefixSugg {
1672
+ spans : non_shorthands,
1673
+ name : name. clone ( ) ,
1674
+ }
1675
+ } ;
1676
+
1660
1677
self . ir . tcx . emit_spanned_lint (
1661
1678
lint:: builtin:: UNUSED_VARIABLES ,
1662
1679
first_hir_id,
@@ -1666,10 +1683,8 @@ impl<'tcx> Liveness<'_, 'tcx> {
1666
1683
. collect :: < Vec < _ > > ( ) ,
1667
1684
errors:: UnusedVariableTryPrefix {
1668
1685
label : if !suggestions. is_empty ( ) { Some ( pat. span ) } else { None } ,
1669
- sugg : errors:: UnusedVariableTryPrefixSugg {
1670
- spans : non_shorthands,
1671
- name,
1672
- } ,
1686
+ name,
1687
+ sugg,
1673
1688
string_interp : suggestions,
1674
1689
} ,
1675
1690
) ;
0 commit comments