Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup "Minimize uses of LocalInternedString" #4502

Merged
merged 1 commit into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
let name = meta_item.path.segments.last().unwrap().ident.name;
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(
&name.as_str(),
Some(tool_name.as_str()),
Some(tool_name.name),
);
then {
span_lint_and_then(
Expand All @@ -332,7 +332,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
let name_lower = name.as_str().to_lowercase();
match lint_store.check_lint_name(
&name_lower,
Some(tool_name.as_str())
Some(tool_name.name)
) {
// FIXME: can we suggest similar lint names here?
// https://github.com/rust-lang/rust/pull/56992
Expand Down
16 changes: 6 additions & 10 deletions clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_data_structures::fx::FxHashMap;
use smallvec::SmallVec;
use std::collections::hash_map::Entry;
use std::hash::BuildHasherDefault;
use syntax::symbol::LocalInternedString;
use syntax::symbol::Symbol;

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

/// Returns the list of bindings in a pattern.
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalInternedString, Ty<'tcx>> {
fn bindings_impl<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
pat: &Pat,
map: &mut FxHashMap<LocalInternedString, Ty<'tcx>>,
) {
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<Symbol, Ty<'tcx>> {
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
match pat.node {
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
PatKind::TupleStruct(_, ref pats, _) => {
Expand All @@ -289,7 +285,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalI
}
},
PatKind::Binding(.., ident, ref as_pat) => {
if let Entry::Vacant(v) = map.entry(ident.as_str()) {
if let Entry::Vacant(v) = map.entry(ident.name) {
v.insert(cx.tables.pat_ty(pat));
}
if let Some(ref as_pat) = *as_pat {
Expand Down
20 changes: 8 additions & 12 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc::lint::{EarlyContext, EarlyLintPass, Lint, LintArray, LintPass};
use rustc::{declare_tool_lint, impl_lint_pass};
use syntax::ast::*;
use syntax::source_map::Span;
use syntax::symbol::{InternedString, LocalInternedString};
use syntax::symbol::Symbol;

declare_clippy_lint! {
/// **What it does:** Detects enumeration variants that are prefixed or suffixed
Expand Down Expand Up @@ -102,7 +102,7 @@ declare_clippy_lint! {
}

pub struct EnumVariantNames {
modules: Vec<(InternedString, String)>,
modules: Vec<(Symbol, String)>,
threshold: u64,
}

Expand All @@ -122,10 +122,6 @@ impl_lint_pass!(EnumVariantNames => [
MODULE_INCEPTION
]);

fn var2str(var: &Variant) -> LocalInternedString {
var.ident.as_str()
}

/// Returns the number of chars that match from the start
fn partial_match(pre: &str, name: &str) -> usize {
let mut name_iter = name.chars();
Expand Down Expand Up @@ -157,7 +153,7 @@ fn check_variant(
return;
}
for var in &def.variants {
let name = var2str(var);
let name = var.ident.name.as_str();
if partial_match(item_name, &name) == item_name_chars
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
Expand All @@ -168,11 +164,11 @@ fn check_variant(
span_lint(cx, lint, var.span, "Variant name ends with the enum's name");
}
}
let first = var2str(&def.variants[0]);
let first = &def.variants[0].ident.name.as_str();
let mut pre = &first[..camel_case::until(&*first)];
let mut post = &first[camel_case::from(&*first)..];
for var in &def.variants {
let name = var2str(var);
let name = var.ident.name.as_str();

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

#[allow(clippy::similar_names)]
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
let item_name = item.ident.as_str();
let item_name = item.ident.name.as_str();
let item_name_chars = item_name.chars().count();
let item_camel = to_camel_case(&item_name);
if !item.span.from_expansion() && is_present_in_source(cx, item.span) {
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {
if mod_name.as_symbol() == item.ident.name {
if mod_name == &item.ident.name {
if let ItemKind::Mod(..) = item.node {
span_lint(
cx,
Expand Down Expand Up @@ -299,6 +295,6 @@ impl EarlyLintPass for EnumVariantNames {
};
check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span, lint);
}
self.modules.push((item_name.as_interned_str(), item_camel));
self.modules.push((item.ident.name, item_camel));
}
}
8 changes: 4 additions & 4 deletions clippy_lints/src/unused_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_data_structures::fx::FxHashMap;
use syntax::source_map::Span;
use syntax::symbol::LocalInternedString;
use syntax::symbol::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for unused labels.
Expand All @@ -28,7 +28,7 @@ declare_clippy_lint! {
}

struct UnusedLabelVisitor<'a, 'tcx> {
labels: FxHashMap<LocalInternedString, Span>,
labels: FxHashMap<Symbol, Span>,
cx: &'a LateContext<'a, 'tcx>,
}

Expand Down Expand Up @@ -65,11 +65,11 @@ impl<'a, 'tcx> Visitor<'tcx> for UnusedLabelVisitor<'a, 'tcx> {
match expr.node {
hir::ExprKind::Break(destination, _) | hir::ExprKind::Continue(destination) => {
if let Some(label) = destination.label {
self.labels.remove(&label.ident.as_str());
self.labels.remove(&label.ident.name);
}
},
hir::ExprKind::Loop(_, Some(label), _) => {
self.labels.insert(label.ident.as_str(), expr.span);
self.labels.insert(label.ident.name, expr.span);
},
_ => (),
}
Expand Down