Repository: rust-analyzer/rust-analyzer
Pull request #2625 (2019-12-20 20:15:16)

Clippy lints


Patch:
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs
index 2644125266..023917aca7 100644
--- a/crates/ra_assists/src/assists/early_return.rs
+++ b/crates/ra_assists/src/assists/early_return.rs
@@ -83,8 +83,8 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt
     let parent_container = parent_block.syntax().parent()?.parent()?;
 
     let early_expression: ast::Expr = match parent_container.kind() {
-        WHILE_EXPR | LOOP_EXPR => make::expr_continue().into(),
-        FN_DEF => make::expr_return().into(),
+        WHILE_EXPR | LOOP_EXPR => make::expr_continue(),
+        FN_DEF => make::expr_return(),
         _ => return None,
     };
 
@@ -116,13 +116,13 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt
                             )
                             .into(),
                         ),
-                        make::expr_path(make::path_from_name_ref(make::name_ref("it"))).into(),
+                        make::expr_path(make::path_from_name_ref(make::name_ref("it"))),
                     );
 
                     let sad_arm = make::match_arm(
                         // FIXME: would be cool to use `None` or `Err(_)` if appropriate
                         once(make::placeholder_pat().into()),
-                        early_expression.into(),
+                        early_expression,
                     );
 
                     make::expr_match(cond_expr, make::match_arm_list(vec![happy_arm, sad_arm]))
@@ -130,7 +130,7 @@ pub(crate) fn convert_to_guarded_return(ctx: AssistCtx<impl HirDatabase>) -> Opt
 
                 let let_stmt = make::let_stmt(
                     make::bind_pat(make::name(&bound_ident.syntax().to_string())).into(),
-                    Some(match_expr.into()),
+                    Some(match_expr),
                 );
                 let let_stmt = if_indent_level.increase_indent(let_stmt);
                 replace(let_stmt.syntax(), &then_block, &parent_block, &if_expr)
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index fca3a29509..ecf883272d 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -221,7 +221,7 @@ impl Module {
 
     pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
         let def_map = db.crate_def_map(self.id.krate);
-        def_map[self.id.local_id].scope.impls().map(ImplBlock::from).collect()
+        def_map[self.id.local_id].impls.iter().copied().map(ImplBlock::from).collect()
     }
 
     pub(crate) fn with_module_id(self, module_id: LocalModuleId) -> Module {
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 445d215b7b..401fe0b9b5 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -17,14 +17,13 @@ use rustc_hash::FxHashMap;
 use crate::{
     db::DefDatabase,
     expr::{Expr, ExprId, Pat, PatId},
-    item_scope::BuiltinShadowMode,
-    nameres::CrateDefMap,
+    nameres::{BuiltinShadowMode, CrateDefMap},
     path::{ModPath, Path},
     src::HasSource,
     DefWithBodyId, HasModule, Lookup, ModuleDefId, ModuleId,
 };
 
-pub(crate) struct Expander {
+struct Expander {
     crate_def_map: Arc<CrateDefMap>,
     current_file_id: HirFileId,
     hygiene: Hygiene,
@@ -33,22 +32,18 @@ pub(crate) struct Expander {
 }
 
 impl Expander {
-    pub(crate) fn new(
-        db: &impl DefDatabase,
-        current_file_id: HirFileId,
-        module: ModuleId,
-    ) -> Expander {
+    fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander {
         let crate_def_map = db.crate_def_map(module.krate);
         let hygiene = Hygiene::new(db, current_file_id);
         let ast_id_map = db.ast_id_map(current_file_id);
         Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module }
     }
 
-    pub(crate) fn enter_expand<T: ast::AstNode, DB: DefDatabase>(
+    fn enter_expand(
         &mut self,
-        db: &DB,
+        db: &impl DefDatabase,
         macro_call: ast::MacroCall,
-    ) -> Option<(Mark, T)> {
+    ) -> Option<(Mark, ast::Expr)> {
         let ast_id = AstId::new(
             self.current_file_id,
             db.ast_id_map(self.current_file_id).ast_id(&macro_call),
@@ -59,7 +54,7 @@ impl Expander {
                 let call_id = def.as_call_id(db, MacroCallKind::FnLike(ast_id));
                 let file_id = call_id.as_file();
                 if let Some(node) = db.parse_or_expand(file_id) {
-                    if let Some(expr) = T::cast(node) {
+                    if let Some(expr) = ast::Expr::cast(node) {
                         log::debug!("macro expansion {:#?}", expr.syntax());
 
                         let mark = Mark {
@@ -82,14 +77,14 @@ impl Expander {
         None
     }
 
-    pub(crate) fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) {
+    fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) {
         self.hygiene = Hygiene::new(db, mark.file_id);
         self.current_file_id = mark.file_id;
         self.ast_id_map = mem::take(&mut mark.ast_id_map);
         mark.bomb.defuse();
     }
 
-    pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
+    fn to_source<T>(&self, value: T) -> InFile<T> {
         InFile { file_id: self.current_file_id, value }
     }
 
@@ -114,7 +109,7 @@ impl Expander {
     }
 }
 
-pub(crate) struct Mark {
+struct Mark {
     file_id: HirFileId,
     ast_id_map: Arc<AstIdMap>,
     bomb: DropBomb,
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index 4488e85020..f5a65ad409 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -80,9 +80,9 @@ impl ChildBySource for ModuleId {
 
         module_data.scope.declarations().for_each(|item| add_module_def(db, &mut res, item));
 
-        for imp in module_data.scope.impls() {
-            let src = imp.lookup(db).source(db);
-            res[keys::IMPL].insert(src, imp)
+        for &impl_ in module_data.impls.iter() {
+            let src = impl_.lookup(db).source(db);
+            res[keys::IMPL].insert(src, impl_)
         }
 
         res
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index b0a3f17845..14e86936bc 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -4,16 +4,16 @@ use std::sync::Arc;
 
 use hir_expand::{
     name::{name, AsName, Name},
-    AstId, InFile,
+    AstId,
 };
-use ra_syntax::ast::{self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner};
+use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
 
 use crate::{
     db::DefDatabase,
     src::HasSource,
     type_ref::{Mutability, TypeRef},
-    AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule,
-    ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
+    AssocContainerId, AssocItemId, ConstId, ConstLoc, FunctionId, FunctionLoc, ImplId, Intern,
+    Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc,
 };
 
 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -167,24 +167,46 @@ pub struct ImplData {
 
 impl ImplData {
     pub(crate) fn impl_data_query(db: &impl DefDatabase, id: ImplId) -> Arc<ImplData> {
-        let impl_loc = id.lookup(db);
-        let src = impl_loc.source(db);
+        let src = id.lookup(db).source(db);
+        let items = db.ast_id_map(src.file_id);
 
         let target_trait = src.value.target_trait().map(TypeRef::from_ast);
         let target_type = TypeRef::from_ast_opt(src.value.target_type());
         let is_negative = src.value.is_negative();
-        let module_id = impl_loc.container.module(db);
 
-        let mut items = Vec::new();
-        if let Some(item_list) = src.value.item_list() {
-            items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id));
-            items.extend(collect_impl_items_in_macros(
-                db,
-                module_id,
-                &src.with_value(item_list),
-                id,
-            ));
-        }
+        let items = if let Some(item_list) = src.value.item_list() {
+            item_list
+                .impl_items()
+                .map(|item_node| match item_node {
+                    ast::ImplItem::FnDef(it) => {
+                        let def = FunctionLoc {
+                            container: AssocContainerId::ImplId(id),
+                            ast_id: AstId::new(src.file_id, items.ast_id(&it)),
+                        }
+                        .intern(db);
+                        def.into()
+                    }
+                    ast::ImplItem::ConstDef(it) => {
+                        let def = ConstLoc {
+                            container: AssocContainerId::ImplId(id),
+                            ast_id: AstId::new(src.file_id, items.ast_id(&it)),
+                        }
+                        .intern(db);
+                        def.into()
+                    }
+                    ast::ImplItem::TypeAliasDef(it) => {
+                        let def = TypeAliasLoc {
+                            container: AssocContainerId::ImplId(id),
+                            ast_id: AstId::new(src.file_id, items.ast_id(&it)),
+                        }
+                        .intern(db);
+                        def.into()
+                    }
+                })
+                .collect()
+        } else {
+            Vec::new()
+        };
 
         let res = ImplData { target_trait, target_type, items, is_negative };
         Arc::new(res)
@@ -215,66 +237,3 @@ impl ConstData {
         ConstData { name, type_ref }
     }
 }
-
-fn collect_impl_items_in_macros(
-    db: &impl DefDatabase,
-    module_id: ModuleId,
-    impl_block: &InFile<ast::ItemList>,
-    id: ImplId,
-) -> Vec<AssocItemId> {
-    let mut expander = Expander::new(db, impl_block.file_id, module_id);
-    let mut res = Vec::new();
-
-    for m in impl_block.value.syntax().children().filter_map(ast::MacroCall::cast) {
-        if let Some((mark, items)) = expander.enter_expand(db, m) {
-            let items: InFile<ast::MacroItems> = expander.to_source(items);
-            expander.exit(db, mark);
-            res.extend(collect_impl_items(
-                db,
-                items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())),
-                items.file_id,
-                id,
-            ));
-        }
-    }
-
-    res
-}
-
-fn collect_impl_items(
-    db: &impl DefDatabase,
-    impl_items: impl Iterator<Item = ImplItem>,
-    file_id: crate::HirFileId,
-    id: ImplId,
-) -> Vec<AssocItemId> {
-    let items = db.ast_id_map(file_id);
-
-    impl_items
-        .map(|item_node| match item_node {
-            ast::ImplItem::FnDef(it) => {
-                let def = FunctionLoc {
-                    container: AssocContainerId::ImplId(id),
-                    ast_id: AstId::new(file_id, items.ast_id(&it)),
-                }
-                .intern(db);
-                def.into()
-            }
-            ast::ImplItem::ConstDef(it) => {
-                let def = ConstLoc {
-                    container: AssocContainerId::ImplId(id),
-                    ast_id: AstId::new(file_id, items.ast_id(&it)),
-                }
-                .intern(db);
-                def.into()
-            }
-            ast::ImplItem::TypeAliasDef(it) => {
-                let def = TypeAliasLoc {
-                    container: AssocContainerId::ImplId(id),
-                    ast_id: AstId::new(file_id, items.ast_id(&it)),
-                }
-                .intern(db);
-                def.into()
-            }
-        })
-        .collect()
-}
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
deleted file mode 100644
index 6b9be8325d..0000000000
--- a/crates/ra_hir_def/src/item_scope.rs
+++ /dev/null
@@ -1,165 +0,0 @@
-//! Describes items defined or visible (ie, imported) in a certain scope.
-//! This is shared between modules and blocks.
-
-use hir_expand::name::Name;
-use once_cell::sync::Lazy;
-use rustc_hash::FxHashMap;
-
-use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId};
-
-#[derive(Debug, Default, PartialEq, Eq)]
-pub struct ItemScope {
-    items: FxHashMap<Name, Resolution>,
-    impls: Vec<ImplId>,
-    /// Macros visible in current module in legacy textual scope
-    ///
-    /// For macros invoked by an unqualified identifier like `bar!()`, `legacy_macros` will be searched in first.
-    /// If it yields no result, then it turns to module scoped `macros`.
-    /// It macros with name qualified with a path like `crate::foo::bar!()`, `legacy_macros` will be skipped,
-    /// and only normal scoped `macros` will be searched in.
-    ///
-    /// Note that this automatically inherit macros defined textually before the definition of module itself.
-    ///
-    /// Module scoped macros will be inserted into `items` instead of here.
-    // FIXME: Macro shadowing in one module is not properly handled. Non-item place macros will
-    // be all resolved to the last one defined if shadowing happens.
-    legacy_macros: FxHashMap<Name, MacroDefId>,
-}
-
-static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
-    BuiltinType::ALL
-        .iter()
-        .map(|(name, ty)| {
-            (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None })
-        })
-        .collect()
-});
-
-/// Shadow mode for builtin type which can be shadowed by module.
-#[derive(Debug, Copy, Clone, PartialEq, Eq)]
-pub(crate) enum BuiltinShadowMode {
-    // Prefer Module
-    Module,
-    // Prefer Other Types
-    Other,
-}
-
-/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
-/// Other methods will only resolve values, types and module scoped macros only.
-impl ItemScope {
-    pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a {
-        //FIXME: shadowing
-        self.items.iter().chain(BUILTIN_SCOPE.iter())
-    }
-
-    pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ {
-        self.entries()
-            .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None })
-            .flat_map(|per_ns| {
-                per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter())
-            })
-    }
-
-    pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
-        self.impls.iter().copied()
-    }
-
-    /// Iterate over all module scoped macros
-    pub(crate) fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
-        self.items
-            .iter()
-            .filter_map(|(name, res)| res.def.take_macros().map(|macro_| (name, macro_)))
-    }
-
-    /// Iterate over all legacy textual scoped macros visible at the end of the module
-    pub(crate) fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
-        self.legacy_macros.iter().map(|(name, def)| (name, *def))
-    }
-
-    /// Get a name from current module scope, legacy macros are not included
-    pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&Resolution> {
-        match shadow {
-            BuiltinShadowMode::Module => self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)),
-            BuiltinShadowMode::Other => {
-                let item = self.items.get(name);
-                if let Some(res) = item {
-                    if let Some(ModuleDefId::ModuleId(_)) = res.def.take_types() {
-                        return BUILTIN_SCOPE.get(name).or(item);
-                    }
-                }
-
-                item.or_else(|| BUILTIN_SCOPE.get(name))
-            }
-        }
-    }
-
-    pub(crate) fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {
-        self.items.values().filter_map(|r| match r.def.take_types() {
-            Some(ModuleDefId::TraitId(t)) => Some(t),
-            _ => None,
-        })
-    }
-
-    pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroDefId> {
-        self.legacy_macros.get(name).copied()
-    }
-
-    pub(crate) fn define_impl(&mut self, imp: ImplId) {
-        self.impls.push(imp)
-    }
-
-    pub(crate) fn define_legacy_macro(&mut self, name: Name, mac: MacroDefId) {
-        self.legacy_macros.insert(name, mac);
-    }
-
-    pub(crate) fn push_res(
-        &mut self,
-        name: Name,
-        res: &Resolution,
-        import: Option<LocalImportId>,
-    ) -> bool {
-        let mut changed = false;
-        let existing = self.items.entry(name.clone()).or_default();
-
-        if existing.def.types.is_none() && res.def.types.is_some() {
-            existing.def.types = res.def.types;
-            existing.import = import.or(res.import);
-            changed = true;
-        }
-        if existing.def.values.is_none() && res.def.values.is_some() {
-            existing.def.values = res.def.values;
-            existing.import = import.or(res.import);
-            changed = true;
-        }
-        if existing.def.macros.is_none() && res.def.macros.is_some() {
-            existing.def.macros = res.def.macros;
-            existing.import = import.or(res.import);
-            changed = true;
-        }
-
-        if existing.def.is_none()
-            && res.def.is_none()
-            && existing.import.is_none()
-            && res.import.is_some()
-        {
-            existing.import = res.import;
-        }
-        changed
-    }
-
-    pub(crate) fn collect_resolutions(&self) -> Vec<(Name, Resolution)> {
-        self.items.iter().map(|(name, res)| (name.clone(), res.clone())).collect()
-    }
-
-    pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> {
-        self.legacy_macros.clone()
-    }
-}
-
-#[derive(Debug, Clone, PartialEq, Eq, Default)]
-pub struct Resolution {
-    /// None for unresolved
-    pub def: PerNs,
-    /// ident by which this is imported into local scope.
-    pub import: Option<LocalImportId>,
-}
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index cef061837b..f4fdbdcfc7 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -81,7 +81,7 @@ impl LangItems {
         // Look for impl targets
         let def_map = db.crate_def_map(module.krate);
         let module_data = &def_map[module.local_id];
-        for impl_block in module_data.scope.impls() {
+        for &impl_block in module_data.impls.iter() {
             self.collect_lang_item(db, impl_block, LangItemTarget::ImplBlockId)
         }
 
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index acd4f4af17..8ed1599ffb 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -15,7 +15,6 @@ pub mod type_ref;
 pub mod builtin_type;
 pub mod diagnostics;
 pub mod per_ns;
-pub mod item_scope;
 
 pub mod dyn_map;
 pub mod keys;
@@ -48,7 +47,6 @@ use ra_arena::{impl_arena_id, RawId};
 use ra_db::{impl_intern_key, salsa, CrateId};
 use ra_syntax::{ast, AstNode};
 
-use crate::body::Expander;
 use crate::builtin_type::BuiltinType;
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 5d4ca73a39..af52fa36ee 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -57,7 +57,8 @@ mod tests;
 
 use std::sync::Arc;
 
-use hir_expand::{diagnostics::DiagnosticSink, name::Name, InFile};
+use hir_expand::{diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId};
+use once_cell::sync::Lazy;
 use ra_arena::Arena;
 use ra_db::{CrateId, Edition, FileId, FilePosition};
 use ra_prof::profile;
@@ -68,12 +69,12 @@ use ra_syntax::{
 use rustc_hash::FxHashMap;
 
 use crate::{
+    builtin_type::BuiltinType,
     db::DefDatabase,
-    item_scope::{BuiltinShadowMode, ItemScope},
     nameres::{diagnostics::DefDiagnostic, path_resolution::ResolveMode},
     path::ModPath,
     per_ns::PerNs,
-    AstId, LocalModuleId, ModuleDefId, ModuleId,
+    AstId, ImplId, LocalImportId, LocalModuleId, ModuleDefId, ModuleId, TraitId,
 };
 
 /// Contains all top-level defs from a macro-expanded crate
@@ -165,10 +166,113 @@ impl ModuleOrigin {
 pub struct ModuleData {
     pub parent: Option<LocalModuleId>,
     pub children: FxHashMap<Name, LocalModuleId>,
-    pub scope: ItemScope,
+    pub scope: ModuleScope,
 
     /// Where does this module come from?
     pub origin: ModuleOrigin,
+
+    pub impls: Vec<ImplId>,
+}
+
+#[derive(Debug, Default, PartialEq, Eq)]
+pub struct ModuleScope {
+    items: FxHashMap<Name, Resolution>,
+    /// Macros visable in current module in legacy textual scope
+    ///
+    /// For macros invoked by an unquatified identifier like `bar!()`, `legacy_macros` will be searched in first.
+    /// If it yields no result, then it turns to module scoped `macros`.
+    /// It macros with name quatified with a path like `crate::foo::bar!()`, `legacy_macros` will be skipped,
+    /// and only normal scoped `macros` will be searched in.
+    ///
+    /// Note that this automatically inherit macros defined textually before the definition of module itself.
+    ///
+    /// Module scoped macros will be inserted into `items` instead of here.
+    // FIXME: Macro shadowing in one module is not properly handled. Non-item place macros will
+    // be all resolved to the last one defined if shadowing happens.
+    legacy_macros: FxHashMap<Name, MacroDefId>,
+}
+
+static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
+    BuiltinType::ALL
+        .iter()
+        .map(|(name, ty)| {
+            (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None })
+        })
+        .collect()
+});
+
+/// Shadow mode for builtin type which can be shadowed by module.
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum BuiltinShadowMode {
+    // Prefer Module
+    Module,
+    // Prefer Other Types
+    Other,
+}
+
+/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
+/// Other methods will only resolve values, types and module scoped macros only.
+impl ModuleScope {
+    pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a {
+        //FIXME: shadowing
+        self.items.iter().chain(BUILTIN_SCOPE.iter())
+    }
+
+    pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ {
+        self.entries()
+            .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None })
+            .flat_map(|per_ns| {
+                per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter())
+            })
+    }
+
+    /// Iterate over all module scoped macros
+    pub fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
+        self.items
+            .iter()
+            .filter_map(|(name, res)| res.def.take_macros().map(|macro_| (name, macro_)))
+    }
+
+    /// Iterate over all legacy textual scoped macros visable at the end of the module
+    pub fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
+        self.legacy_macros.iter().map(|(name, def)| (name, *def))
+    }
+
+    /// Get a name from current module scope, legacy macros are not included
+    pub fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&Resolution> {
+        match shadow {
+            BuiltinShadowMode::Module => self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)),
+            BuiltinShadowMode::Other => {
+                let item = self.items.get(name);
+                if let Some(res) = item {
+                    if let Some(ModuleDefId::ModuleId(_)) = res.def.take_types() {
+                        return BUILTIN_SCOPE.get(name).or(item);
+                    }
+                }
+
+                item.or_else(|| BUILTIN_SCOPE.get(name))
+            }
+        }
+    }
+
+    pub fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {
+        self.items.values().filter_map(|r| match r.def.take_types() {
+            Some(ModuleDefId::TraitId(t)) => Some(t),
+            _ => None,
+        })
+    }
+
+    fn get_legacy_macro(&self, name: &Name) -> Option<MacroDefId> {
+        self.legacy_macros.get(name).copied()
+    }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
+pub struct Resolution {
+    /// None for unresolved
+    pub def: PerNs,
+    /// ident by which this is imported into local scope.
+    pub import: Option<LocalImportId>,
 }
 
 impl CrateDefMap {
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 8b641d8b56..3d8ca5dce3 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -18,10 +18,9 @@ use test_utils::tested_by;
 use crate::{
     attr::Attrs,
     db::DefDatabase,
-    item_scope::Resolution,
     nameres::{
         diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
-        raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, ResolveMode,
+        raw, BuiltinShadowMode, CrateDefMap, ModuleData, ModuleOrigin, Resolution, ResolveMode,
     },
     path::{ModPath, PathKind},
     per_ns::PerNs,
@@ -226,14 +225,14 @@ where
 
     /// Define a legacy textual scoped macro in module
     ///
-    /// We use a map `legacy_macros` to store all legacy textual scoped macros visible per module.
+    /// We use a map `legacy_macros` to store all legacy textual scoped macros visable per module.
     /// It will clone all macros from parent legacy scope, whose definition is prior to
     /// the definition of current module.
-    /// And also, `macro_use` on a module will import all legacy macros visible inside to
+    /// And also, `macro_use` on a module will import all legacy macros visable inside to
     /// current legacy scope, with possible shadowing.
-    fn define_legacy_macro(&mut self, module_id: LocalModuleId, name: Name, mac: MacroDefId) {
+    fn define_legacy_macro(&mut self, module_id: LocalModuleId, name: Name, macro_: MacroDefId) {
         // Always shadowing
-        self.def_map.modules[module_id].scope.define_legacy_macro(name, mac);
+        self.def_map.modules[module_id].scope.legacy_macros.insert(name, macro_);
     }
 
     /// Import macros from `#[macro_use] extern crate`.
@@ -372,7 +371,11 @@ where
                         let scope = &item_map[m.local_id].scope;
 
                         // Module scoped macros is included
-                        let items = scope.collect_resolutions();
+                        let items = scope
+                            .items
+                            .iter()
+                            .map(|(name, res)| (name.clone(), res.clone()))
+                            .collect::<Vec<_>>();
 
                         self.update(module_id, Some(import_id), &items);
                     } else {
@@ -382,7 +385,11 @@ where
                         let scope = &self.def_map[m.local_id].scope;
 
                         // Module scoped macros is included
-                        let items = scope.collect_resolutions();
+                        let items = scope
+                            .items
+                            .iter()
+                            .map(|(name, res)| (name.clone(), res.clone()))
+                            .collect::<Vec<_>>();
 
                         self.update(module_id, Some(import_id), &items);
                         // record the glob import in case we add further items
@@ -399,14 +406,14 @@ where
                     let resolutions = enum_data
                         .variants
                         .iter()
-                        .filter_map(|(local_id, variant_data)| {
+                        .map(|(local_id, variant_data)| {
                             let name = variant_data.name.clone();
                             let variant = EnumVariantId { parent: e, local_id };
                             let res = Resolution {
                                 def: PerNs::both(variant.into(), variant.into()),
                                 import: Some(import_id),
                             };
-                            Some((name, res))
+                            (name, res)
                         })
                         .collect::<Vec<_>>();
                     self.update(module_id, Some(import_id), &resolutions);
@@ -459,10 +466,34 @@ where
             // prevent stack overflows (but this shouldn't be possible)
             panic!("infinite recursion in glob imports!");
         }
-        let scope = &mut self.def_map.modules[module_id].scope;
+        let module_items = &mut self.def_map.modules[module_id].scope;
         let mut changed = false;
         for (name, res) in resolutions {
-            changed |= scope.push_res(name.clone(), res, import);
+            let existing = module_items.items.entry(name.clone()).or_default();
+
+            if existing.def.types.is_none() && res.def.types.is_some() {
+                existing.def.types = res.def.types;
+                existing.import = import.or(res.import);
+                changed = true;
+            }
+            if existing.def.values.is_none() && res.def.values.is_some() {
+                existing.def.values = res.def.values;
+                existing.import = import.or(res.import);
+                changed = true;
+            }
+            if existing.def.macros.is_none() && res.def.macros.is_some() {
+                existing.def.macros = res.def.macros;
+                existing.import = import.or(res.import);
+                changed = true;
+            }
+
+            if existing.def.is_none()
+                && res.def.is_none()
+                && existing.import.is_none()
+                && res.import.is_some()
+            {
+                existing.import = res.import;
+            }
         }
 
         if !changed {
@@ -635,9 +666,7 @@ where
                         let impl_id =
                             ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) }
                                 .intern(self.def_collector.db);
-                        self.def_collector.def_map.modules[self.module_id]
-                            .scope
-                            .define_impl(impl_id)
+                        self.def_collector.def_map.modules[self.module_id].impls.push(impl_id)
                     }
                 }
             }
@@ -711,9 +740,7 @@ where
         let res = modules.alloc(ModuleData::default());
         modules[res].parent = Some(self.module_id);
         modules[res].origin = ModuleOrigin::not_sure_file(definition, declaration);
-        for (name, mac) in modules[self.module_id].scope.collect_legacy_macros() {
-            modules[res].scope.define_legacy_macro(name, mac)
-        }
+        modules[res].scope.legacy_macros = modules[self.module_id].scope.legacy_macros.clone();
         modules[self.module_id].children.insert(name.clone(), res);
         let resolution = Resolution {
             def: PerNs::types(
@@ -877,7 +904,7 @@ where
     }
 
     fn import_all_legacy_macros(&mut self, module_id: LocalModuleId) {
-        let macros = self.def_collector.def_map[module_id].scope.collect_legacy_macros();
+        let macros = self.def_collector.def_map[module_id].scope.legacy_macros.clone();
         for (name, macro_) in macros {
             self.def_collector.define_legacy_macro(self.module_id, name.clone(), macro_);
         }
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 8e12942011..00325cd99a 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -135,7 +135,7 @@ impl Path {
     }
 
     pub fn type_anchor(&self) -> Option<&TypeRef> {
-        self.type_anchor.as_deref()
+        self.type_anchor.as_ref().map(|it| &**it)
     }
 
     pub fn segments(&self) -> PathSegments<'_> {
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 83013fed3d..af9d194f8a 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -14,8 +14,7 @@ use crate::{
     db::DefDatabase,
     expr::{ExprId, PatId},
     generics::GenericParams,
-    item_scope::BuiltinShadowMode,
-    nameres::CrateDefMap,
+    nameres::{BuiltinShadowMode, CrateDefMap},
     path::{ModPath, PathKind},
     per_ns::PerNs,
     AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId,
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 1749b491b9..857f8a4441 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -138,7 +138,7 @@ fn to_col_number(db: &dyn AstDatabase, file: HirFileId, pos: TextUnit) -> usize
         if c == '\n' {
             break;
         }
-        col_num = col_num + 1;
+        col_num += 1;
     }
     col_num
 }
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index d86445abff..42e599fec7 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -93,12 +93,11 @@ pub(crate) fn macro_def(
             Some(Arc::new((TokenExpander::MacroRules(rules), tmap)))
         }
         MacroDefKind::BuiltIn(expander) => {
-            Some(Arc::new((TokenExpander::Builtin(expander.clone()), mbe::TokenMap::default())))
+            Some(Arc::new((TokenExpander::Builtin(expander), mbe::TokenMap::default())))
+        }
+        MacroDefKind::BuiltInDerive(expander) => {
+            Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default())))
         }
-        MacroDefKind::BuiltInDerive(expander) => Some(Arc::new((
-            TokenExpander::BuiltinDerive(expander.clone()),
-            mbe::TokenMap::default(),
-        ))),
     }
 }
 
@@ -188,7 +187,6 @@ fn to_fragment_kind(db: &dyn AstDatabase, macro_call_id: MacroCallId) -> Fragmen
         ARG_LIST => FragmentKind::Expr,
         TRY_EXPR => FragmentKind::Expr,
         TUPLE_EXPR => FragmentKind::Expr,
-        ITEM_LIST => FragmentKind::Items,
         _ => {
             // Unknown , Just guess it is `Items`
             FragmentKind::Items
diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs
index ee48fa5370..f32d5786af 100644
--- a/crates/ra_hir_ty/src/autoderef.rs
+++ b/crates/ra_hir_ty/src/autoderef.rs
@@ -48,7 +48,7 @@ fn deref_by_trait(
     krate: CrateId,
     ty: InEnvironment<&Canonical<Ty>>,
 ) -> Option<Canonical<Ty>> {
-    let deref_trait = match db.lang_item(krate.into(), "deref".into())? {
+    let deref_trait = match db.lang_item(krate, "deref".into())? {
         LangItemTarget::TraitId(it) => it,
         _ => return None,
     };
@@ -78,7 +78,7 @@ fn deref_by_trait(
 
     let canonical = super::Canonical { num_vars: 1 + ty.value.num_vars, value: in_env };
 
-    let solution = db.trait_solve(krate.into(), canonical)?;
+    let solution = db.trait_solve(krate, canonical)?;
 
     match &solution {
         Solution::Unique(vars) => {
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index 7310ef10d9..48abf97c92 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -919,7 +919,7 @@ impl HirDisplay for ApplicationTy {
                         {
                             Option::None => self.parameters.0.as_ref(),
                             Option::Some(default_parameters) => {
-                                for (i, parameter) in self.parameters.into_iter().enumerate() {
+                                for (i, parameter) in self.parameters.iter().enumerate() {
                                     match (parameter, default_parameters.get(i)) {
                                         (&Ty::Unknown, _) | (_, None) => {
                                             non_default_parameters.push(parameter.clone())
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs
index 888dc31166..92fb4c0817 100644
--- a/crates/ra_hir_ty/src/method_resolution.rs
+++ b/crates/ra_hir_ty/src/method_resolution.rs
@@ -58,7 +58,7 @@ impl CrateImplBlocks {
 
         let crate_def_map = db.crate_def_map(krate);
         for (_module_id, module_data) in crate_def_map.modules.iter() {
-            for impl_id in module_data.scope.impls() {
+            for &impl_id in module_data.impls.iter() {
                 match db.impl_trait(impl_id) {
                     Some(tr) => {
                         res.impls_by_trait.entry(tr.trait_).or_default().push(impl_id);
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs
index 646a30c76e..5470dc291f 100644
--- a/crates/ra_ide/src/completion/complete_postfix.rs
+++ b/crates/ra_ide/src/completion/complete_postfix.rs
@@ -12,7 +12,7 @@ use crate::{
 };
 
 pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
-    if ctx.db.feature_flags.get("completion.enable-postfix") == false {
+    if !ctx.db.feature_flags.get("completion.enable-postfix") {
         return;
     }
 
diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs
index 981da2b794..4894ea2f6b 100644
--- a/crates/ra_ide/src/completion/completion_context.rs
+++ b/crates/ra_ide/src/completion/completion_context.rs
@@ -239,16 +239,15 @@ impl<'a> CompletionContext<'a> {
                 .expr()
                 .map(|e| e.syntax().text_range())
                 .and_then(|r| find_node_with_range(original_file.syntax(), r));
-            self.dot_receiver_is_ambiguous_float_literal = if let Some(ast::Expr::Literal(l)) =
-                &self.dot_receiver
-            {
-                match l.kind() {
-                    ast::LiteralKind::FloatNumber { suffix: _ } => l.token().text().ends_with('.'),
-                    _ => false,
+            self.dot_receiver_is_ambiguous_float_literal =
+                if let Some(ast::Expr::Literal(l)) = &self.dot_receiver {
+                    match l.kind() {
+                        ast::LiteralKind::FloatNumber { .. } => l.token().text().ends_with('.'),
+                        _ => false,
+                    }
+                } else {
+                    false
                 }
-            } else {
-                false
-            }
         }
         if let Some(method_call_expr) = ast::MethodCallExpr::cast(parent) {
             // As above
diff --git a/crates/ra_ide/src/expand_macro.rs b/crates/ra_ide/src/expand_macro.rs
index 862c03304a..bdbc31704b 100644
--- a/crates/ra_ide/src/expand_macro.rs
+++ b/crates/ra_ide/src/expand_macro.rs
@@ -86,21 +86,18 @@ fn insert_whitespaces(syn: SyntaxNode) -> String {
         let mut is_next = |f: fn(SyntaxKind) -> bool, default| -> bool {
             token_iter.peek().map(|it| f(it.kind())).unwrap_or(default)
         };
-        let is_last = |f: fn(SyntaxKind) -> bool, default| -> bool {
-            last.map(|it| f(it)).unwrap_or(default)
-        };
+        let is_last =
+            |f: fn(SyntaxKind) -> bool, default| -> bool { last.map(f).unwrap_or(default) };
 
         res += &match token.kind() {
-            k @ _ if is_text(k) && is_next(|it| !it.is_punct(), true) => {
-                token.text().to_string() + " "
-            }
+            k if is_text(k) && is_next(|it| !it.is_punct(), true) => token.text().to_string() + " ",
             L_CURLY if is_next(|it| it != R_CURLY, true) => {
                 indent += 1;
-                let leading_space = if is_last(|it| is_text(it), false) { " " } else { "" };
+                let leading_space = if is_last(is_text, false) { " " } else { "" };
                 format!("{}{{\n{}", leading_space, "  ".repeat(indent))
             }
             R_CURLY if is_last(|it| it != L_CURLY, true) => {
-                indent = indent.checked_sub(1).unwrap_or(0);
+                indent = indent.saturating_sub(1);
                 format!("\n{}}}", "  ".repeat(indent))
             }
             R_CURLY => format!("}}\n{}", "  ".repeat(indent)),
diff --git a/crates/ra_ide/src/extend_selection.rs b/crates/ra_ide/src/extend_selection.rs
index c096ca6ae4..1ec41a117b 100644
--- a/crates/ra_ide/src/extend_selection.rs
+++ b/crates/ra_ide/src/extend_selection.rs
@@ -138,7 +138,7 @@ fn extend_ws(root: &SyntaxNode, ws: SyntaxToken, offset: TextUnit) -> TextRange
     ws.text_range()
 }
 
-fn pick_best<'a>(l: SyntaxToken, r: SyntaxToken) -> SyntaxToken {
+fn pick_best(l: SyntaxToken, r: SyntaxToken) -> SyntaxToken {
     return if priority(&r) > priority(&l) { r } else { l };
     fn priority(n: &SyntaxToken) -> usize {
         match n.kind() {
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 657c7b21a5..0228ee7e90 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -17,31 +17,31 @@ use crate::{
 };
 
 pub mod tags {
-    pub(crate) const FIELD: &'static str = "field";
-    pub(crate) const FUNCTION: &'static str = "function";
-    pub(crate) const MODULE: &'static str = "module";
-    pub(crate) const TYPE: &'static str = "type";
-    pub(crate) const CONSTANT: &'static str = "constant";
-    pub(crate) const MACRO: &'static str = "macro";
-    pub(crate) const VARIABLE: &'static str = "variable";
-    pub(crate) const VARIABLE_MUT: &'static str = "variable.mut";
-    pub(crate) const TEXT: &'static str = "text";
-
-    pub(crate) const TYPE_BUILTIN: &'static str = "type.builtin";
-    pub(crate) const TYPE_SELF: &'static str = "type.self";
-    pub(crate) const TYPE_PARAM: &'static str = "type.param";
-    pub(crate) const TYPE_LIFETIME: &'static str = "type.lifetime";
-
-    pub(crate) const LITERAL_BYTE: &'static str = "literal.byte";
-    pub(crate) const LITERAL_NUMERIC: &'static str = "literal.numeric";
-    pub(crate) const LITERAL_CHAR: &'static str = "literal.char";
-    pub(crate) const LITERAL_COMMENT: &'static str = "comment";
-    pub(crate) const LITERAL_STRING: &'static str = "string";
-    pub(crate) const LITERAL_ATTRIBUTE: &'static str = "attribute";
-
-    pub(crate) const KEYWORD_UNSAFE: &'static str = "keyword.unsafe";
-    pub(crate) const KEYWORD_CONTROL: &'static str = "keyword.control";
-    pub(crate) const KEYWORD: &'static str = "keyword";
+    pub(crate) const FIELD: &str = "field";
+    pub(crate) const FUNCTION: &str = "function";
+    pub(crate) const MODULE: &str = "module";
+    pub(crate) const TYPE: &str = "type";
+    pub(crate) const CONSTANT: &str = "constant";
+    pub(crate) const MACRO: &str = "macro";
+    pub(crate) const VARIABLE: &str = "variable";
+    pub(crate) const VARIABLE_MUT: &str = "variable.mut";
+    pub(crate) const TEXT: &str = "text";
+
+    pub(crate) const TYPE_BUILTIN: &str = "type.builtin";
+    pub(crate) const TYPE_SELF: &str = "type.self";
+    pub(crate) const TYPE_PARAM: &str = "type.param";
+    pub(crate) const TYPE_LIFETIME: &str = "type.lifetime";
+
+    pub(crate) const LITERAL_BYTE: &str = "literal.byte";
+    pub(crate) const LITERAL_NUMERIC: &str = "literal.numeric";
+    pub(crate) const LITERAL_CHAR: &str = "literal.char";
+    pub(crate) const LITERAL_COMMENT: &str = "comment";
+    pub(crate) const LITERAL_STRING: &str = "string";
+    pub(crate) const LITERAL_ATTRIBUTE: &str = "attribute";
+
+    pub(crate) const KEYWORD_UNSAFE: &str = "keyword.unsafe";
+    pub(crate) const KEYWORD_CONTROL: &str = "keyword.control";
+    pub(crate) const KEYWORD: &str = "keyword";
 }
 
 #[derive(Debug)]
@@ -258,9 +258,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str {
         SelfType(_) => tags::TYPE_SELF,
         TypeParam(_) => tags::TYPE_PARAM,
         Local(local) => {
-            if local.is_mut(db) {
-                tags::VARIABLE_MUT
-            } else if local.ty(db).is_mutable_reference() {
+            if local.is_mut(db) || local.ty(db).is_mutable_reference() {
                 tags::VARIABLE_MUT
             } else {
                 tags::VARIABLE
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 965e7c53c1..9e207415e6 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -131,7 +131,7 @@ pub fn main_loop(
         let feature_flags = {
             let mut ff = FeatureFlags::default();
             for (flag, value) in config.feature_flags {
-                if let Err(_) = ff.set(flag.as_str(), value) {
+                if ff.set(flag.as_str(), value).is_err() {
                     log::error!("unknown feature flag: {:?}", flag);
                     show_message(
                         req::MessageType::Error,
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 5b64b27cd2..5e3b1a73f0 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -164,7 +164,7 @@ pub fn handle_on_type_formatting(
 
     // in `ra_ide`, the `on_type` invariant is that
     // `text.char_at(position) == typed_char`.
-    position.offset = position.offset - TextUnit::of_char('.');
+    position.offset -= TextUnit::of_char('.');
     let char_typed = params.ch.chars().next().unwrap_or('\0');
 
     // We have an assist that inserts ` ` after typing `->` in `fn foo() ->{`,
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index 16cc11e8ce..f89b23089e 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -287,19 +287,15 @@ impl WorldSnapshot {
 ///
 /// When processing non-windows path, this is essentially the same as `Url::from_file_path`.
 fn url_from_path_with_drive_lowercasing(path: impl AsRef<Path>) -> Result<Url> {
-    let component_has_windows_drive = path
-        .as_ref()
-        .components()
-        .find(|comp| {
-            if let Component::Prefix(c) = comp {
-                match c.kind() {
-                    Prefix::Disk(_) | Prefix::VerbatimDisk(_) => return true,
-                    _ => return false,
-                }
+    let component_has_windows_drive = path.as_ref().components().any(|comp| {
+        if let Component::Prefix(c) = comp {
+            match c.kind() {
+                Prefix::Disk(_) | Prefix::VerbatimDisk(_) => return true,
+                _ => return false,
             }
-            false
-        })
-        .is_some();
+        }
+        false
+    });
 
     // VSCode expects drive letters to be lowercased, where rust will uppercase the drive letters.
     if component_has_windows_drive {
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs
index 45dad2d108..2c6ae56589 100644
--- a/crates/ra_mbe/src/lib.rs
+++ b/crates/ra_mbe/src/lib.rs
@@ -97,7 +97,9 @@ impl Shift {
                     tt::Leaf::Literal(lit) => lit.id = self.shift(lit.id),
                 },
                 tt::TokenTree::Subtree(tt) => {
-                    tt.delimiter.as_mut().map(|it: &mut Delimiter| it.id = self.shift(it.id));
+                    if let Some(it) = tt.delimiter.as_mut() {
+                        it.id = self.shift(it.id);
+                    };
                     self.shift_all(tt)
                 }
             }
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 40db570da0..04a5408fef 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -168,8 +168,7 @@ pub fn let_stmt(pattern: ast::Pat, initializer: Option<ast::Expr>) -> ast::LetSt
 
 fn ast_from_text<N: AstNode>(text: &str) -> N {
     let parse = SourceFile::parse(text);
-    let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap();
-    res
+    parse.tree().syntax().descendants().find_map(N::cast).unwrap()
 }
 
 pub mod tokens {


Test patch:
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs
index 4e968bcc84..61cdd768e8 100644
--- a/crates/ra_hir_def/src/nameres/tests.rs
+++ b/crates/ra_hir_def/src/nameres/tests.rs
@@ -32,22 +32,27 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
         *buf += path;
         *buf += "\n";
 
-        let mut entries = map.modules[module].scope.collect_resolutions();
-        entries.sort_by_key(|(name, _)| name.clone());
+        let mut entries = map.modules[module]
+            .scope
+            .items
+            .iter()
+            .map(|(name, res)| (name, res.def))
+            .collect::<Vec<_>>();
+        entries.sort_by_key(|(name, _)| *name);
 
         for (name, res) in entries {
             *buf += &format!("{}:", name);
 
-            if res.def.types.is_some() {
+            if res.types.is_some() {
                 *buf += " t";
             }
-            if res.def.values.is_some() {
+            if res.values.is_some() {
                 *buf += " v";
             }
-            if res.def.macros.is_some() {
+            if res.macros.is_some() {
                 *buf += " m";
             }
-            if res.def.is_none() {
+            if res.is_none() {
                 *buf += " _";
             }
 
@@ -582,6 +587,6 @@ mod b {
     ⋮T: v
     ⋮
     ⋮crate::a
-    ⋮T: t v
+    ⋮T: t v    
 "###);
 }
diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs
index ef2e9435cf..903a227719 100644
--- a/crates/ra_hir_def/src/nameres/tests/incremental.rs
+++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs
@@ -116,7 +116,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
         let events = db.log_executed(|| {
             let crate_def_map = db.crate_def_map(krate);
             let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
-            assert_eq!(module_data.scope.collect_resolutions().len(), 1);
+            assert_eq!(module_data.scope.items.len(), 1);
         });
         assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
     }
@@ -126,7 +126,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
         let events = db.log_executed(|| {
             let crate_def_map = db.crate_def_map(krate);
             let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
-            assert_eq!(module_data.scope.collect_resolutions().len(), 1);
+            assert_eq!(module_data.scope.items.len(), 1);
         });
         assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events)
     }
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs
index d104f5993f..cfa4ecb1af 100644
--- a/crates/ra_hir_def/src/nameres/tests/macros.rs
+++ b/crates/ra_hir_def/src/nameres/tests/macros.rs
@@ -610,7 +610,7 @@ fn expand_derive() {
         struct Foo;
         ",
     );
-    assert_eq!(map.modules[map.root].scope.impls().len(), 1);
+    assert_eq!(map.modules[map.root].impls.len(), 1);
 }
 
 #[test]
@@ -622,5 +622,5 @@ fn expand_multiple_derive() {
         struct Foo;
         ",
     );
-    assert_eq!(map.modules[map.root].scope.impls().len(), 2);
+    assert_eq!(map.modules[map.root].impls.len(), 2);
 }
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs
index 1a31b587bb..476f6df52a 100644
--- a/crates/ra_hir_ty/src/test_db.rs
+++ b/crates/ra_hir_ty/src/test_db.rs
@@ -98,7 +98,7 @@ impl TestDB {
                     }
                 }
 
-                for impl_id in crate_def_map[module_id].scope.impls() {
+                for &impl_id in crate_def_map[module_id].impls.iter() {
                     let impl_data = self.impl_data(impl_id);
                     for item in impl_data.items.iter() {
                         if let AssocItemId::FunctionId(f) = item {
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index d447b45718..d724ee1223 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -182,7 +182,7 @@ fn visit_module(
             _ => (),
         }
     }
-    for impl_id in crate_def_map[module_id].scope.impls() {
+    for &impl_id in crate_def_map[module_id].impls.iter() {
         let impl_data = db.impl_data(impl_id);
         for &item in impl_data.items.iter() {
             match item {
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index 7fdbf996f4..812f171db8 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -182,25 +182,6 @@ fn test() { S.foo()<|>; }
     assert_eq!(t, "u128");
 }
 
-#[test]
-fn infer_impl_items_generated_by_macros() {
-    let t = type_at(
-        r#"
-//- /main.rs
-macro_rules! m {
-    () => (fn foo(&self) -> u128 {0})
-}
-struct S;
-impl S {
-    m!();
-}
-
-fn test() { S.foo()<|>; }
-"#,
-    );
-    assert_eq!(t, "u128");
-}
-
 #[test]
 fn infer_macro_with_dollar_crate_is_correct_in_expr() {
     let (db, pos) = TestDB::with_position(