Skip to content

Commit 70f150b

Browse files
committed
liveness: Delay conversion from a symbol to a string until linting
1 parent 2fb1564 commit 70f150b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler/rustc_passes/src/liveness.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ use rustc_middle::hir::map::Map;
9696
use rustc_middle::ty::query::Providers;
9797
use rustc_middle::ty::{self, TyCtxt};
9898
use rustc_session::lint;
99-
use rustc_span::symbol::{sym, Symbol};
99+
use rustc_span::symbol::{kw, sym, Symbol};
100100
use rustc_span::Span;
101101

102102
use std::collections::VecDeque;
@@ -309,9 +309,9 @@ impl IrMaps<'tcx> {
309309
}
310310
}
311311

312-
fn variable_name(&self, var: Variable) -> String {
312+
fn variable_name(&self, var: Variable) -> Symbol {
313313
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,
315315
}
316316
}
317317

@@ -1587,7 +1587,14 @@ impl<'tcx> Liveness<'_, 'tcx> {
15871587

15881588
fn should_warn(&self, var: Variable) -> Option<String> {
15891589
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())
15911598
}
15921599

15931600
fn warn_about_unused_upvars(&self, entry_ln: LiveNode) {
@@ -1659,7 +1666,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
16591666
// bindings, and we also consider the first pattern to be the "authoritative" set of ids.
16601667
// However, we should take the ids and spans of variables with the same name from the later
16611668
// 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();
16631670

16641671
pat.each_binding(|_, hir_id, pat_sp, ident| {
16651672
let ln = entry_ln.unwrap_or_else(|| self.live_node(hir_id, pat_sp));

0 commit comments

Comments
 (0)