@@ -96,7 +96,7 @@ use rustc_middle::hir::map::Map;
96
96
use rustc_middle:: ty:: query:: Providers ;
97
97
use rustc_middle:: ty:: { self , TyCtxt } ;
98
98
use rustc_session:: lint;
99
- use rustc_span:: symbol:: { sym, Symbol } ;
99
+ use rustc_span:: symbol:: { kw , sym, Symbol } ;
100
100
use rustc_span:: Span ;
101
101
102
102
use std:: collections:: VecDeque ;
@@ -309,9 +309,9 @@ impl IrMaps<'tcx> {
309
309
}
310
310
}
311
311
312
- fn variable_name ( & self , var : Variable ) -> String {
312
+ fn variable_name ( & self , var : Variable ) -> Symbol {
313
313
match self . var_kinds [ var. get ( ) ] {
314
- Local ( LocalInfo { name, .. } ) | Param ( _, name) | Upvar ( _, name) => name. to_string ( ) ,
314
+ Local ( LocalInfo { name, .. } ) | Param ( _, name) | Upvar ( _, name) => name,
315
315
}
316
316
}
317
317
@@ -1587,7 +1587,14 @@ impl<'tcx> Liveness<'_, 'tcx> {
1587
1587
1588
1588
fn should_warn ( & self , var : Variable ) -> Option < String > {
1589
1589
let name = self . ir . variable_name ( var) ;
1590
- if name. is_empty ( ) || name. as_bytes ( ) [ 0 ] == b'_' { None } else { Some ( name) }
1590
+ if name == kw:: Invalid {
1591
+ return None ;
1592
+ }
1593
+ let name: & str = & name. as_str ( ) ;
1594
+ if name. as_bytes ( ) [ 0 ] == b'_' {
1595
+ return None ;
1596
+ }
1597
+ Some ( name. to_owned ( ) )
1591
1598
}
1592
1599
1593
1600
fn warn_about_unused_upvars ( & self , entry_ln : LiveNode ) {
@@ -1659,7 +1666,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
1659
1666
// bindings, and we also consider the first pattern to be the "authoritative" set of ids.
1660
1667
// However, we should take the ids and spans of variables with the same name from the later
1661
1668
// patterns so the suggestions to prefix with underscores will apply to those too.
1662
- let mut vars: FxIndexMap < String , ( LiveNode , Variable , Vec < ( HirId , Span ) > ) > = <_ >:: default ( ) ;
1669
+ let mut vars: FxIndexMap < Symbol , ( LiveNode , Variable , Vec < ( HirId , Span ) > ) > = <_ >:: default ( ) ;
1663
1670
1664
1671
pat. each_binding ( |_, hir_id, pat_sp, ident| {
1665
1672
let ln = entry_ln. unwrap_or_else ( || self . live_node ( hir_id, pat_sp) ) ;
0 commit comments