Auto merge of #4502 - lzutao:rustup-64141, r=phansch

Rustup "Minimize uses of `LocalInternedString`"

Rustup https://github.com/rust-lang/rust/pull/64141

changelog: none
This commit is contained in:
bors 2019-09-05 08:26:00 +00:00
commit 5f28fda13e
4 changed files with 20 additions and 28 deletions

View File

@ -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(
@ -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

View File

@ -8,7 +8,7 @@
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.
@ -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
@ -275,12 +275,8 @@ fn same_bindings<'tcx>(
}
/// 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, _) => {
@ -289,7 +285,7 @@ fn bindings_impl<'a, 'tcx>(
}
},
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 {

View File

@ -6,7 +6,7 @@
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
@ -102,7 +102,7 @@
}
pub struct EnumVariantNames {
modules: Vec<(InternedString, String)>,
modules: Vec<(Symbol, String)>,
threshold: u64,
}
@ -122,10 +122,6 @@ pub fn new(threshold: u64) -> Self {
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();
@ -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())
@ -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];
@ -245,14 +241,14 @@ fn check_item_post(&mut self, _cx: &EarlyContext<'_>, _item: &Item) {
#[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,
@ -299,6 +295,6 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
};
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));
}
}

View File

@ -5,7 +5,7 @@
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.
@ -28,7 +28,7 @@
}
struct UnusedLabelVisitor<'a, 'tcx> {
labels: FxHashMap<LocalInternedString, Span>,
labels: FxHashMap<Symbol, Span>,
cx: &'a LateContext<'a, 'tcx>,
}
@ -65,11 +65,11 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
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);
},
_ => (),
}