Skip to content

Commit c12b700

Browse files
committed
Rustup "Minimize uses of LocalInternedString"
1 parent abbb7ee commit c12b700

File tree

4 files changed

+20
-28
lines changed

4 files changed

+20
-28
lines changed

clippy_lints/src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
319319
let name = meta_item.path.segments.last().unwrap().ident.name;
320320
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(
321321
&name.as_str(),
322-
Some(tool_name.as_str()),
322+
Some(tool_name.name),
323323
);
324324
then {
325325
span_lint_and_then(
@@ -332,7 +332,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
332332
let name_lower = name.as_str().to_lowercase();
333333
match lint_store.check_lint_name(
334334
&name_lower,
335-
Some(tool_name.as_str())
335+
Some(tool_name.name)
336336
) {
337337
// FIXME: can we suggest similar lint names here?
338338
// https://github.com/rust-lang/rust/pull/56992

clippy_lints/src/copies.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_data_structures::fx::FxHashMap;
88
use smallvec::SmallVec;
99
use std::collections::hash_map::Entry;
1010
use std::hash::BuildHasherDefault;
11-
use syntax::symbol::LocalInternedString;
11+
use syntax::symbol::Symbol;
1212

1313
declare_clippy_lint! {
1414
/// **What it does:** Checks for consecutive `if`s with the same condition.
@@ -168,8 +168,8 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
168168
fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
169169
fn same_bindings<'tcx>(
170170
cx: &LateContext<'_, 'tcx>,
171-
lhs: &FxHashMap<LocalInternedString, Ty<'tcx>>,
172-
rhs: &FxHashMap<LocalInternedString, Ty<'tcx>>,
171+
lhs: &FxHashMap<Symbol, Ty<'tcx>>,
172+
rhs: &FxHashMap<Symbol, Ty<'tcx>>,
173173
) -> bool {
174174
lhs.len() == rhs.len()
175175
&& lhs
@@ -275,12 +275,8 @@ fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>)
275275
}
276276

277277
/// Returns the list of bindings in a pattern.
278-
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalInternedString, Ty<'tcx>> {
279-
fn bindings_impl<'a, 'tcx>(
280-
cx: &LateContext<'a, 'tcx>,
281-
pat: &Pat,
282-
map: &mut FxHashMap<LocalInternedString, Ty<'tcx>>,
283-
) {
278+
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<Symbol, Ty<'tcx>> {
279+
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
284280
match pat.node {
285281
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
286282
PatKind::TupleStruct(_, ref pats, _) => {
@@ -289,7 +285,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalI
289285
}
290286
},
291287
PatKind::Binding(.., ident, ref as_pat) => {
292-
if let Entry::Vacant(v) = map.entry(ident.as_str()) {
288+
if let Entry::Vacant(v) = map.entry(ident.name) {
293289
v.insert(cx.tables.pat_ty(pat));
294290
}
295291
if let Some(ref as_pat) = *as_pat {

clippy_lints/src/enum_variants.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass};
66
use rustc::{declare_tool_lint, impl_lint_pass};
77
use syntax::ast::*;
88
use syntax::source_map::Span;
9-
use syntax::symbol::{InternedString, LocalInternedString};
9+
use syntax::symbol::Symbol;
1010

1111
declare_clippy_lint! {
1212
/// **What it does:** Detects enumeration variants that are prefixed or suffixed
@@ -102,7 +102,7 @@ declare_clippy_lint! {
102102
}
103103

104104
pub struct EnumVariantNames {
105-
modules: Vec<(InternedString, String)>,
105+
modules: Vec<(Symbol, String)>,
106106
threshold: u64,
107107
}
108108

@@ -122,10 +122,6 @@ impl_lint_pass!(EnumVariantNames => [
122122
MODULE_INCEPTION
123123
]);
124124

125-
fn var2str(var: &Variant) -> LocalInternedString {
126-
var.ident.as_str()
127-
}
128-
129125
/// Returns the number of chars that match from the start
130126
fn partial_match(pre: &str, name: &str) -> usize {
131127
let mut name_iter = name.chars();
@@ -157,7 +153,7 @@ fn check_variant(
157153
return;
158154
}
159155
for var in &def.variants {
160-
let name = var2str(var);
156+
let name = var.ident.name.as_str();
161157
if partial_match(item_name, &name) == item_name_chars
162158
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
163159
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
@@ -168,11 +164,11 @@ fn check_variant(
168164
span_lint(cx, lint, var.span, "Variant name ends with the enum's name");
169165
}
170166
}
171-
let first = var2str(&def.variants[0]);
167+
let first = &def.variants[0].ident.name.as_str();
172168
let mut pre = &first[..camel_case::until(&*first)];
173169
let mut post = &first[camel_case::from(&*first)..];
174170
for var in &def.variants {
175-
let name = var2str(var);
171+
let name = var.ident.name.as_str();
176172

177173
let pre_match = partial_match(pre, &name);
178174
pre = &pre[..pre_match];
@@ -245,14 +241,14 @@ impl EarlyLintPass for EnumVariantNames {
245241

246242
#[allow(clippy::similar_names)]
247243
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
248-
let item_name = item.ident.as_str();
244+
let item_name = item.ident.name.as_str();
249245
let item_name_chars = item_name.chars().count();
250246
let item_camel = to_camel_case(&item_name);
251247
if !item.span.from_expansion() && is_present_in_source(cx, item.span) {
252248
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
253249
// constants don't have surrounding modules
254250
if !mod_camel.is_empty() {
255-
if mod_name.as_symbol() == item.ident.name {
251+
if mod_name == &item.ident.name {
256252
if let ItemKind::Mod(..) = item.node {
257253
span_lint(
258254
cx,
@@ -299,6 +295,6 @@ impl EarlyLintPass for EnumVariantNames {
299295
};
300296
check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span, lint);
301297
}
302-
self.modules.push((item_name.as_interned_str(), item_camel));
298+
self.modules.push((item.ident.name, item_camel));
303299
}
304300
}

clippy_lints/src/unused_label.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
55
use rustc::{declare_lint_pass, declare_tool_lint};
66
use rustc_data_structures::fx::FxHashMap;
77
use syntax::source_map::Span;
8-
use syntax::symbol::LocalInternedString;
8+
use syntax::symbol::Symbol;
99

1010
declare_clippy_lint! {
1111
/// **What it does:** Checks for unused labels.
@@ -28,7 +28,7 @@ declare_clippy_lint! {
2828
}
2929

3030
struct UnusedLabelVisitor<'a, 'tcx> {
31-
labels: FxHashMap<LocalInternedString, Span>,
31+
labels: FxHashMap<Symbol, Span>,
3232
cx: &'a LateContext<'a, 'tcx>,
3333
}
3434

@@ -65,11 +65,11 @@ impl<'a, 'tcx> Visitor<'tcx> for UnusedLabelVisitor<'a, 'tcx> {
6565
match expr.node {
6666
hir::ExprKind::Break(destination, _) | hir::ExprKind::Continue(destination) => {
6767
if let Some(label) = destination.label {
68-
self.labels.remove(&label.ident.as_str());
68+
self.labels.remove(&label.ident.name);
6969
}
7070
},
7171
hir::ExprKind::Loop(_, Some(label), _) => {
72-
self.labels.insert(label.ident.as_str(), expr.span);
72+
self.labels.insert(label.ident.name, expr.span);
7373
},
7474
_ => (),
7575
}

0 commit comments

Comments
 (0)