Repository: rust-analyzer/rust-analyzer
Pull request #1391 (2019-06-10 22:49:34)

rename tools -> ra_tools


Patch:
diff --git a/.cargo/config b/.cargo/config
index 51ae33910b..3ac2ce3363 100644
--- a/.cargo/config
+++ b/.cargo/config
@@ -1,22 +1,22 @@
 [alias]
 # Automatically generates the ast and syntax kinds files
-gen-syntax   = "run --package tools --bin tools -- gen-syntax"
+gen-syntax   = "run --package ra_tools --bin ra_tools -- gen-syntax"
 # Extracts the tests from
-gen-tests    = "run --package tools --bin tools -- gen-tests"
+gen-tests    = "run --package ra_tools --bin ra_tools -- gen-tests"
 # Installs ra_lsp_server
 install-lsp = "install --path crates/ra_lsp_server --force"
 # Installs ra_lsp_server with the jemalloc feature
 jinstall-lsp = "install --path crates/ra_lsp_server --force --features jemalloc"
 # Installs the visual studio code extension
-install-code = "run --package tools --bin tools -- install-code"
+install-code = "run --package ra_tools --bin ra_tools -- install-code"
 # Formats the full repository or installs the git hook to do it automatically.
-format       = "run --package tools --bin tools -- format"
-format-hook  = "run --package tools --bin tools -- format-hook"
+format       = "run --package ra_tools --bin ra_tools -- format"
+format-hook  = "run --package ra_tools --bin ra_tools -- format-hook"
 # Run clippy
-lint         = "run --package tools --bin tools -- lint"
+lint         = "run --package ra_tools --bin ra_tools -- lint"
 
 # Runs the fuzzing test suite (currently only parser)
-fuzz-tests   = "run --package tools --bin tools -- fuzz-tests"
+fuzz-tests   = "run --package ra_tools --bin ra_tools -- fuzz-tests"
 
 render-test  = "run --package ra_cli -- render-test"
 # Parse a file. This should be piped the file contents
diff --git a/Cargo.lock b/Cargo.lock
index 202c8838ca..c19b87b61d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1047,7 +1047,6 @@ dependencies = [
  "ra_ide_api 0.1.0",
  "ra_prof 0.1.0",
  "ra_syntax 0.1.0",
- "tools 0.1.0",
 ]
 
 [[package]]
@@ -1079,6 +1078,7 @@ dependencies = [
  "chalk-ir 0.1.0 (git+https://github.com/flodiebold/chalk.git?branch=fuel)",
  "chalk-rust-ir 0.1.0 (git+https://github.com/flodiebold/chalk.git?branch=fuel)",
  "chalk-solve 0.1.0 (git+https://github.com/flodiebold/chalk.git?branch=fuel)",
+ "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "flexi_logger 0.11.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "insta 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1227,6 +1227,17 @@ dependencies = [
  "text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "ra_tools"
+version = "0.1.0"
+dependencies = [
+ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "ra_tt"
 version = "0.1.0"
@@ -1765,17 +1776,6 @@ dependencies = [
  "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "tools"
-version = "0.1.0"
-dependencies = [
- "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
 [[package]]
 name = "typenum"
 version = "1.10.0"
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index 328b2436f6..3117f4fda1 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -14,7 +14,6 @@ indicatif = "0.11.0"
 
 ra_syntax = { path = "../ra_syntax" }
 ra_ide_api = { path = "../ra_ide_api" }
-tools = { path = "../tools" }
 ra_batch = { path = "../ra_batch" }
 ra_hir = { path = "../ra_hir" }
 ra_db = { path = "../ra_db" }
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index 12d849f377..78808e72f0 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -12,6 +12,7 @@ rustc-hash = "1.0"
 parking_lot = "0.8.0"
 ena = "0.11"
 join_to_string = "0.1.3"
+either = "1.5.2"
 once_cell = "0.2"
 
 ra_syntax = { path = "../ra_syntax" }
diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs
index 71c53ebc06..4073cc82e1 100644
--- a/crates/ra_hir/src/either.rs
+++ b/crates/ra_hir/src/either.rs
@@ -25,22 +25,4 @@ impl<A, B> Either<A, B> {
             Either::B(b) => Either::B(f2(b)),
         }
     }
-    pub fn a(self) -> Option<A> {
-        match self {
-            Either::A(it) => Some(it),
-            Either::B(_) => None,
-        }
-    }
-    pub fn b(self) -> Option<B> {
-        match self {
-            Either::A(_) => None,
-            Either::B(it) => Some(it),
-        }
-    }
-    pub fn as_ref(&self) -> Either<&A, &B> {
-        match self {
-            Either::A(it) => Either::A(it),
-            Either::B(it) => Either::B(it),
-        }
-    }
 }
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index d84134877e..b5938fa032 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -56,6 +56,7 @@ mod tests;
 use std::sync::Arc;
 
 use rustc_hash::{FxHashMap, FxHashSet};
+use either::Either;
 use ra_arena::{Arena, RawId, impl_arena_id};
 use ra_db::{FileId, Edition};
 use test_utils::tested_by;
@@ -69,7 +70,6 @@ use crate::{
     ids::MacroDefId,
     diagnostics::DiagnosticSink,
     nameres::diagnostics::DefDiagnostic,
-    either::Either,
     AstId,
 };
 
@@ -164,8 +164,8 @@ impl ModuleScope {
     }
     fn get_item_or_macro(&self, name: &Name) -> Option<ItemOrMacro> {
         match (self.get(name), self.macros.get(name)) {
-            (Some(item), _) if !item.def.is_none() => Some(Either::A(item.def)),
-            (_, Some(macro_)) => Some(Either::B(*macro_)),
+            (Some(item), _) if !item.def.is_none() => Some(Either::Left(item.def)),
+            (_, Some(macro_)) => Some(Either::Right(*macro_)),
             _ => None,
         }
     }
@@ -190,7 +190,7 @@ struct ResolvePathResult {
 
 impl ResolvePathResult {
     fn empty(reached_fixedpoint: ReachedFixedPoint) -> ResolvePathResult {
-        ResolvePathResult::with(Either::A(PerNs::none()), reached_fixedpoint, None)
+        ResolvePathResult::with(Either::Left(PerNs::none()), reached_fixedpoint, None)
     }
 
     fn with(
@@ -217,13 +217,13 @@ enum ReachedFixedPoint {
 /// helper function for select item or macro to use
 fn or(left: ItemOrMacro, right: ItemOrMacro) -> ItemOrMacro {
     match (left, right) {
-        (Either::A(s), Either::A(o)) => Either::A(s.or(o)),
-        (Either::B(s), _) => Either::B(s),
-        (Either::A(s), Either::B(o)) => {
+        (Either::Left(s), Either::Left(o)) => Either::Left(s.or(o)),
+        (Either::Right(s), _) => Either::Right(s),
+        (Either::Left(s), Either::Right(o)) => {
             if !s.is_none() {
-                Either::A(s)
+                Either::Left(s)
             } else {
-                Either::B(o)
+                Either::Right(o)
             }
         }
     }
@@ -306,7 +306,7 @@ impl CrateDefMap {
         path: &Path,
     ) -> (PerNs<ModuleDef>, Option<usize>) {
         let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
-        (res.resolved_def.a().unwrap_or_else(PerNs::none), res.segment_index)
+        (res.resolved_def.left().unwrap_or_else(PerNs::none), res.segment_index)
     }
 
     pub(crate) fn resolve_path_with_macro(
@@ -330,10 +330,10 @@ impl CrateDefMap {
     ) -> ResolvePathResult {
         let mut segments = path.segments.iter().enumerate();
         let mut curr_per_ns: ItemOrMacro = match path.kind {
-            PathKind::Crate => {
-                Either::A(PerNs::types(Module { krate: self.krate, module_id: self.root }.into()))
-            }
-            PathKind::Self_ => Either::A(PerNs::types(
+            PathKind::Crate => Either::Left(PerNs::types(
+                Module { krate: self.krate, module_id: self.root }.into(),
+            )),
+            PathKind::Self_ => Either::Left(PerNs::types(
                 Module { krate: self.krate, module_id: original_module }.into(),
             )),
             // plain import or absolute path in 2015: crate-relative with
@@ -361,7 +361,7 @@ impl CrateDefMap {
             }
             PathKind::Super => {
                 if let Some(p) = self.modules[original_module].parent {
-                    Either::A(PerNs::types(Module { krate: self.krate, module_id: p }.into()))
+                    Either::Left(PerNs::types(Module { krate: self.krate, module_id: p }.into()))
                 } else {
                     log::debug!("super path in root module");
                     return ResolvePathResult::empty(ReachedFixedPoint::Yes);
@@ -375,7 +375,7 @@ impl CrateDefMap {
                 };
                 if let Some(def) = self.extern_prelude.get(&segment.name) {
                     log::debug!("absolute path {:?} resolved to crate {:?}", path, def);
-                    Either::A(PerNs::types(*def))
+                    Either::Left(PerNs::types(*def))
                 } else {
                     return ResolvePathResult::empty(ReachedFixedPoint::No); // extern crate declarations can add to the extern prelude
                 }
@@ -383,7 +383,7 @@ impl CrateDefMap {
         };
 
         for (i, segment) in segments {
-            let curr = match curr_per_ns.as_ref().a().and_then(|m| m.as_ref().take_types()) {
+            let curr = match curr_per_ns.as_ref().left().and_then(|m| m.as_ref().take_types()) {
                 Some(r) => r,
                 None => {
                     // we still have path segments left, but the path so far
@@ -424,10 +424,10 @@ impl CrateDefMap {
                     // enum variant
                     tested_by!(can_import_enum_variant);
                     match e.variant(db, &segment.name) {
-                        Some(variant) => Either::A(PerNs::both(variant.into(), variant.into())),
+                        Some(variant) => Either::Left(PerNs::both(variant.into(), variant.into())),
                         None => {
                             return ResolvePathResult::with(
-                                Either::A(PerNs::types((*e).into())),
+                                Either::Left(PerNs::types((*e).into())),
                                 ReachedFixedPoint::Yes,
                                 Some(i),
                             );
@@ -444,7 +444,7 @@ impl CrateDefMap {
                     );
 
                     return ResolvePathResult::with(
-                        Either::A(PerNs::types(*s)),
+                        Either::Left(PerNs::types(*s)),
                         ReachedFixedPoint::Yes,
                         Some(i),
                     );
@@ -458,10 +458,10 @@ impl CrateDefMap {
         let from_crate_root = self[self.root]
             .scope
             .get_item_or_macro(name)
-            .unwrap_or_else(|| Either::A(PerNs::none()));
+            .unwrap_or_else(|| Either::Left(PerNs::none()));
         let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
 
-        or(from_crate_root, Either::A(from_extern_prelude))
+        or(from_crate_root, Either::Left(from_extern_prelude))
     }
 
     pub(crate) fn resolve_name_in_module(
@@ -470,7 +470,7 @@ impl CrateDefMap {
         module: CrateModuleId,
         name: &Name,
     ) -> PerNs<ModuleDef> {
-        self.resolve_name_in_module_with_macro(db, module, name).a().unwrap_or_else(PerNs::none)
+        self.resolve_name_in_module_with_macro(db, module, name).left().unwrap_or_else(PerNs::none)
     }
 
     fn resolve_name_in_module_with_macro(
@@ -483,13 +483,15 @@ impl CrateDefMap {
         //  - current module / scope
         //  - extern prelude
         //  - std prelude
-        let from_scope =
-            self[module].scope.get_item_or_macro(name).unwrap_or_else(|| Either::A(PerNs::none()));
+        let from_scope = self[module]
+            .scope
+            .get_item_or_macro(name)
+            .unwrap_or_else(|| Either::Left(PerNs::none()));
         let from_extern_prelude =
             self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
         let from_prelude = self.resolve_in_prelude(db, name);
 
-        or(from_scope, or(Either::A(from_extern_prelude), from_prelude))
+        or(from_scope, or(Either::Left(from_extern_prelude), from_prelude))
     }
 
     fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs<ModuleDef> {
@@ -503,9 +505,9 @@ impl CrateDefMap {
             } else {
                 db.crate_def_map(prelude.krate)[prelude.module_id].scope.get_item_or_macro(name)
             };
-            resolution.unwrap_or_else(|| Either::A(PerNs::none()))
+            resolution.unwrap_or_else(|| Either::Left(PerNs::none()))
         } else {
-            Either::A(PerNs::none())
+            Either::Left(PerNs::none())
         }
     }
 }
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index b74dc33b17..99110d58d2 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -1,5 +1,6 @@
 use arrayvec::ArrayVec;
 use rustc_hash::FxHashMap;
+use either::Either;
 use relative_path::RelativePathBuf;
 use test_utils::tested_by;
 use ra_db::FileId;
@@ -8,7 +9,7 @@ use ra_syntax::ast;
 use crate::{
     Function, Module, Struct, Union, Enum, Const, Static, Trait, TypeAlias, MacroDef,
     DefDatabase, HirFileId, Name, Path, AstDatabase,
-    KnownName, AstId,
+    KnownName,
     nameres::{
         Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode,
         CrateDefMap, CrateModuleId, ModuleData, ItemOrMacro,
@@ -16,7 +17,7 @@ use crate::{
         raw,
     },
     ids::{AstItemDef, LocationCtx, MacroCallLoc, MacroCallId, MacroDefId, MacroFileKind},
-    either::Either,
+    AstId,
 };
 
 pub(super) fn collect_defs(
@@ -128,7 +129,12 @@ where
         let unresolved_imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
         // show unresolved imports in completion, etc
         for (module_id, import, import_data) in unresolved_imports {
-            self.record_resolved_import(module_id, Either::A(PerNs::none()), import, &import_data)
+            self.record_resolved_import(
+                module_id,
+                Either::Left(PerNs::none()),
+                import,
+                &import_data,
+            )
         }
     }
 
@@ -153,7 +159,7 @@ where
         // What we should do is that, in CrateDefMap, we should maintain a
         // separate tower of macro scopes, with ids. Then, for each item in the
         // module, we need to store it's macro scope.
-        let def = Either::B(MacroDef { id: macro_id });
+        let def = Either::Right(MacroDef { id: macro_id });
 
         // In Rust, `#[macro_export]` macros are unconditionally visible at the
         // crate root, even if the parent modules is **not** visible.
@@ -197,7 +203,7 @@ where
                     .as_ident()
                     .expect("extern crate should have been desugared to one-element path"),
             );
-            (Either::A(res), ReachedFixedPoint::Yes)
+            (Either::Left(res), ReachedFixedPoint::Yes)
         } else {
             let res = self.def_map.resolve_path_fp_with_macro(
                 self.db,
@@ -219,7 +225,7 @@ where
     ) {
         if import.is_glob {
             log::debug!("glob import: {:?}", import);
-            match def.a().and_then(|item| item.take_types()) {
+            match def.left().and_then(|item| item.take_types()) {
                 Some(ModuleDef::Module(m)) => {
                     if import.is_prelude {
                         tested_by!(std_prelude);
@@ -232,11 +238,11 @@ where
                         let items = scope
                             .items
                             .iter()
-                            .map(|(name, res)| (name.clone(), Either::A(res.clone())));
+                            .map(|(name, res)| (name.clone(), Either::Left(res.clone())));
                         let macros = scope
                             .macros
                             .iter()
-                            .map(|(name, res)| (name.clone(), Either::B(res.clone())));
+                            .map(|(name, res)| (name.clone(), Either::Right(res.clone())));
 
                         let all = items.chain(macros).collect::<Vec<_>>();
                         self.update(module_id, Some(import_id), &all);
@@ -248,11 +254,11 @@ where
                         let items = scope
                             .items
                             .iter()
-                            .map(|(name, res)| (name.clone(), Either::A(res.clone())));
+                            .map(|(name, res)| (name.clone(), Either::Left(res.clone())));
                         let macros = scope
                             .macros
                             .iter()
-                            .map(|(name, res)| (name.clone(), Either::B(res.clone())));
+                            .map(|(name, res)| (name.clone(), Either::Right(res.clone())));
 
                         let all = items.chain(macros).collect::<Vec<_>>();
 
@@ -276,7 +282,7 @@ where
                                 import: Some(import_id),
                             };
                             let name = variant.name(self.db)?;
-                            Some((name, Either::A(res)))
+                            Some((name, Either::Left(res)))
                         })
                         .collect::<Vec<_>>();
                     self.update(module_id, Some(import_id), &resolutions);
@@ -296,16 +302,16 @@ where
 
                     // extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
                     if import.is_extern_crate && module_id == self.def_map.root {
-                        if let Some(def) = def.a().and_then(|item| item.take_types()) {
+                        if let Some(def) = def.left().and_then(|item| item.take_types()) {
                             self.def_map.extern_prelude.insert(name.clone(), def);
                         }
                     }
 
                     let resolution = match def {
-                        Either::A(item) => {
-                            Either::A(Resolution { def: item, import: Some(import_id) })
+                        Either::Left(item) => {
+                            Either::Left(Resolution { def: item, import: Some(import_id) })
                         }
-                        Either::B(macro_) => Either::B(macro_),
+                        Either::Right(macro_) => Either::Right(macro_),
                     };
 
                     self.update(module_id, Some(import_id), &[(name, resolution)]);
@@ -340,7 +346,7 @@ where
         for (name, res) in resolutions {
             match res {
                 // item
-                Either::A(res) => {
+                Either::Left(res) => {
                     let existing = module_items.items.entry(name.clone()).or_default();
 
                     if existing.def.types.is_none() && res.def.types.is_some() {
@@ -363,7 +369,7 @@ where
                     }
                 }
                 // macro
-                Either::B(res) => {
+                Either::Right(res) => {
                     // Always shadowing
                     module_items.macros.insert(name.clone(), *res);
                 }
@@ -398,7 +404,7 @@ where
                 path,
             );
 
-            if let Some(def) = resolved_res.resolved_def.b() {
+            if let Some(def) = resolved_res.resolved_def.right() {
                 let call_id = MacroCallLoc { def: def.id, ast_id: *ast_id }.id(self.db);
                 resolved.push((*module_id, call_id, def.id));
                 res = ReachedFixedPoint::No;
@@ -564,7 +570,7 @@ where
             ),
             import: None,
         };
-        self.def_collector.update(self.module_id, None, &[(name, Either::A(resolution))]);
+        self.def_collector.update(self.module_id, None, &[(name, Either::Left(resolution))]);
         res
     }
 
@@ -595,7 +601,7 @@ where
             raw::DefKind::TypeAlias(ast_id) => PerNs::types(def!(TypeAlias, ast_id)),
         };
         let resolution = Resolution { def, import: None };
-        self.def_collector.update(self.module_id, None, &[(name, Either::A(resolution))])
+        self.def_collector.update(self.module_id, None, &[(name, Either::Left(resolution))])
     }
 
     fn collect_macro(&mut self, mac: &raw::MacroData) {
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 7f8b3812c3..1b987c1b66 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -2,6 +2,7 @@
 use std::sync::Arc;
 
 use rustc_hash::{FxHashMap, FxHashSet};
+use either::Either;
 
 use crate::{
     ModuleDef, Trait, MacroDef,
@@ -13,7 +14,6 @@ use crate::{
     expr::{scope::{ExprScopes, ScopeId}, PatId},
     impl_block::ImplBlock,
     path::Path,
-    either::Either,
 };
 
 #[derive(Debug, Clone, Default)]
@@ -137,7 +137,7 @@ impl Resolver {
     ) -> Option<MacroDef> {
         let (item_map, module) = self.module()?;
         match item_map.resolve_path_with_macro(db, module, path) {
-            (Either::B(macro_def), None) => Some(macro_def),
+            (Either::Right(macro_def), None) => Some(macro_def),
             _ => None,
         }
     }
diff --git a/crates/tools/Cargo.toml b/crates/ra_tools/Cargo.toml
similarity index 91%
rename from crates/tools/Cargo.toml
rename to crates/ra_tools/Cargo.toml
index f03256a749..35ea3231b2 100644
--- a/crates/tools/Cargo.toml
+++ b/crates/ra_tools/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 edition = "2018"
-name = "tools"
+name = "ra_tools"
 version = "0.1.0"
 authors = ["rust-analyzer developers"]
 publish = false
diff --git a/crates/tools/src/bin/pre-commit.rs b/crates/ra_tools/src/bin/pre-commit.rs
similarity index 84%
rename from crates/tools/src/bin/pre-commit.rs
rename to crates/ra_tools/src/bin/pre-commit.rs
index ea18c0863f..c514e992b3 100644
--- a/crates/tools/src/bin/pre-commit.rs
+++ b/crates/ra_tools/src/bin/pre-commit.rs
@@ -2,10 +2,10 @@ use std::process::Command;
 
 use failure::bail;
 
-use tools::{Result, run_rustfmt, run, project_root};
+use ra_tools::{Result, run_rustfmt, run, project_root, Overwrite};
 
-fn main() -> tools::Result<()> {
-    run_rustfmt(tools::Overwrite)?;
+fn main() -> Result<()> {
+    run_rustfmt(Overwrite)?;
     update_staged()
 }
 
diff --git a/crates/tools/src/lib.rs b/crates/ra_tools/src/lib.rs
similarity index 99%
rename from crates/tools/src/lib.rs
rename to crates/ra_tools/src/lib.rs
index 2446fdf287..61f6b08cd3 100644
--- a/crates/tools/src/lib.rs
+++ b/crates/ra_tools/src/lib.rs
@@ -121,7 +121,7 @@ pub fn install_format_hook() -> Result<()> {
         "./.git/hooks/pre-commit"
     });
     if !result_path.exists() {
-        run("cargo build --package tools --bin pre-commit", ".")?;
+        run("cargo build --package ra_tools --bin pre-commit", ".")?;
         if cfg!(windows) {
             fs::copy("./target/debug/pre-commit.exe", result_path)?;
         } else {
diff --git a/crates/tools/src/main.rs b/crates/ra_tools/src/main.rs
similarity index 99%
rename from crates/tools/src/main.rs
rename to crates/ra_tools/src/main.rs
index 8027ff833e..285071ea53 100644
--- a/crates/tools/src/main.rs
+++ b/crates/ra_tools/src/main.rs
@@ -1,7 +1,7 @@
 use clap::{App, SubCommand};
 use core::str;
 use failure::bail;
-use tools::{
+use ra_tools::{
     generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt,
     Overwrite, Result, run_fuzzer, run_clippy,
 };


Test patch:
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index adac814d91..a15e62bbe6 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -8,9 +8,10 @@ use std::sync::Arc;
 use ra_db::SourceDatabase;
 use test_utils::covers;
 use insta::assert_snapshot_matches;
+use either::Either;
 
 use crate::{
-    Crate, Either,
+    Crate,
     mock::{MockDatabase, CrateGraphFixture},
     nameres::Resolution,
 };
@@ -36,17 +37,19 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
         *buf += path;
         *buf += "\n";
 
-        let items = map.modules[module].scope.items.iter().map(|(name, it)| (name, Either::A(it)));
-        let macros = map.modules[module].scope.macros.iter().map(|(name, m)| (name, Either::B(m)));
+        let items =
+            map.modules[module].scope.items.iter().map(|(name, it)| (name, Either::Left(it)));
+        let macros =
+            map.modules[module].scope.macros.iter().map(|(name, m)| (name, Either::Right(m)));
         let mut entries = items.chain(macros).collect::<Vec<_>>();
 
         entries.sort_by_key(|(name, _)| *name);
         for (name, res) in entries {
             match res {
-                Either::A(it) => {
+                Either::Left(it) => {
                     *buf += &format!("{}: {}\n", name, dump_resolution(it));
                 }
-                Either::B(_) => {
+                Either::Right(_) => {
                     *buf += &format!("{}: m\n", name);
                 }
             }
diff --git a/crates/tools/tests/cli.rs b/crates/ra_tools/tests/cli.rs
similarity index 94%
rename from crates/tools/tests/cli.rs
rename to crates/ra_tools/tests/cli.rs
index 6f82ae61d9..83640218f7 100644
--- a/crates/tools/tests/cli.rs
+++ b/crates/ra_tools/tests/cli.rs
@@ -1,6 +1,6 @@
 use walkdir::WalkDir;
 
-use tools::{generate, gen_tests, run_rustfmt, Verify, project_root};
+use ra_tools::{generate, gen_tests, run_rustfmt, Verify, project_root};
 
 #[test]
 fn generated_grammar_is_fresh() {