]> git.lizzy.rs Git - rust.git/commitdiff
Rustup "Minimize uses of `LocalInternedString`"
authorLzu Tao <taolzu@gmail.com>
Thu, 5 Sep 2019 06:56:10 +0000 (13:56 +0700)
committerLzu Tao <taolzu@gmail.com>
Thu, 5 Sep 2019 07:16:57 +0000 (07:16 +0000)
clippy_lints/src/attrs.rs
clippy_lints/src/copies.rs
clippy_lints/src/enum_variants.rs
clippy_lints/src/unused_label.rs

index 558298c2e0e0786bf756973b5c5915d3c9369584..a4b411d751998ec3f897373929ee52190d40c9f5 100644 (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
index df354073df80fbd8b630a16c53539e0c1582b1a6..b01ce7eeb77d4c8d5d346f0ff750f0ba32a263fa 100644 (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 {
index 277844983658cd15f8d620c51eb5eb7c66a89b13..e24d5d72e73ea78543106a6cf125b8a7a0968414 100644 (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
 }
 
 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));
     }
 }
index 197b9a8146edcffbbcb95e87bd8f3b1192f17377..8323078df7e9e34fd60cecfe44b4d9c99b12cbc2 100644 (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);
             },
             _ => (),
         }