Repository: rust-analyzer/rust-analyzer
Pull request #10686 (2021-11-03 18:04:20)

internal: Add `Semantics::original_ast_node` for upmapping nodes out of macro files
Fixes trying to insert imports into macro expanded files which then do text edits on very wrong text ranges.


Patch:
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index f0ff7d71fc..c996d3dd44 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -85,7 +85,7 @@ jobs:
 
   dist-x86_64-unknown-linux-gnu:
     name: dist (x86_64-unknown-linux-gnu)
-    runs-on: ubuntu-20.04
+    runs-on: ubuntu-18.04
     env:
       RA_TARGET: x86_64-unknown-linux-gnu
 
@@ -123,70 +123,67 @@ jobs:
         name: dist-x86_64-unknown-linux-gnu
         path: ./dist
 
-  dist-aarch64-unknown-linux-gnu:
-    name: dist (aarch64-unknown-linux-gnu)
+  dist-x86_64-unknown-linux-musl:
+    name: dist (x86_64-unknown-linux-musl)
     runs-on: ubuntu-20.04
     env:
-      RA_TARGET: aarch64-unknown-linux-gnu
-      CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
+      RA_TARGET: x86_64-unknown-linux-musl
+      # For some reason `-crt-static` is not working for clang without lld
+      RUSTFLAGS: "-C link-arg=-fuse-ld=lld -C target-feature=-crt-static"
+    container:
+      image: rust:alpine
+      volumes:
+      - /usr/local/cargo/registry
 
     steps:
+    - name: Install dependencies
+      run: apk add --no-cache git clang lld musl-dev
+
     - name: Checkout repository
       uses: actions/checkout@v2
       with:
         fetch-depth: ${{ env.FETCH_DEPTH }}
 
-    - name: Install Rust toolchain
-      uses: actions-rs/toolchain@v1
-      with:
-        toolchain: stable
-        target: aarch64-unknown-linux-gnu
-        profile: minimal
-        override: true
-
-    - name: Update apt repositories
-      run: sudo apt-get update
-
-    - name: Install target toolchain
-      run: sudo apt-get install gcc-aarch64-linux-gnu
-
     - name: Dist
       run: cargo xtask dist
 
     - name: Upload artifacts
       uses: actions/upload-artifact@v1
       with:
-        name: dist-aarch64-unknown-linux-gnu
+        name: dist-x86_64-unknown-linux-musl
         path: ./dist
 
-  dist-x86_64-unknown-linux-musl:
-    name: dist (x86_64-unknown-linux-musl)
-    runs-on: ubuntu-latest
+  dist-aarch64-unknown-linux-gnu:
+    name: dist (aarch64-unknown-linux-gnu)
+    runs-on: ubuntu-18.04
     env:
-      RA_TARGET: x86_64-unknown-linux-musl
-      # For some reason `-crt-static` is not working for clang without lld
-      RUSTFLAGS: "-C link-arg=-fuse-ld=lld -C target-feature=-crt-static"
-    container:
-      image: rust:alpine
-      volumes:
-      - /usr/local/cargo/registry
+      RA_TARGET: aarch64-unknown-linux-gnu
+      CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
 
     steps:
-    - name: Install dependencies
-      run: apk add --no-cache git clang lld musl-dev
-
     - name: Checkout repository
       uses: actions/checkout@v2
       with:
         fetch-depth: ${{ env.FETCH_DEPTH }}
 
+    - name: Install Rust toolchain
+      uses: actions-rs/toolchain@v1
+      with:
+        toolchain: stable
+        target: aarch64-unknown-linux-gnu
+        profile: minimal
+        override: true
+
+    - name: Install target toolchain
+      run: sudo apt-get install gcc-aarch64-linux-gnu
+
     - name: Dist
       run: cargo xtask dist
 
     - name: Upload artifacts
       uses: actions/upload-artifact@v1
       with:
-        name: dist-x86_64-unknown-linux-musl
+        name: dist-aarch64-unknown-linux-gnu
         path: ./dist
 
   dist-x86_64-apple-darwin:
@@ -256,7 +253,7 @@ jobs:
 
   publish:
     name: publish
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-18.04
     needs: ['dist-x86_64-pc-windows-msvc', 'dist-aarch64-pc-windows-msvc', 'dist-x86_64-unknown-linux-gnu', 'dist-x86_64-unknown-linux-musl', 'dist-aarch64-unknown-linux-gnu', 'dist-x86_64-apple-darwin', 'dist-aarch64-apple-darwin']
     steps:
     - name: Install Nodejs
diff --git a/Cargo.lock b/Cargo.lock
index afd1bbe6bc..eff2545268 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -55,9 +55,9 @@ checksum = "577b08a4acd7b99869f863c50011b01eb73424ccc798ecd996f2e24817adfca7"
 
 [[package]]
 name = "arrayvec"
-version = "0.7.2"
+version = "0.7.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
+checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd"
 
 [[package]]
 name = "atty"
@@ -78,9 +78,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
 
 [[package]]
 name = "backtrace"
-version = "0.3.62"
+version = "0.3.61"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "091bcdf2da9950f96aa522681ce805e6857f6ca8df73833d35736ab2dc78e152"
+checksum = "e7a905d892734eea339e896738c14b9afce22b5318f64b951e70bf3844419b01"
 dependencies = [
  "addr2line",
  "cc",
@@ -132,9 +132,9 @@ dependencies = [
 
 [[package]]
 name = "cargo_metadata"
-version = "0.14.1"
+version = "0.14.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba2ae6de944143141f6155a473a6b02f66c7c3f9f47316f802f80204ebfe6e12"
+checksum = "c297bd3135f558552f99a0daa180876984ea2c4ffa7470314540dff8c654109a"
 dependencies = [
  "camino",
  "cargo-platform",
@@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "chalk-derive"
-version = "0.72.0"
+version = "0.71.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "50947a8c71b9a6ee75d6c3b74eb320f58668f872a5ca1347a2b664989fbc8ac8"
+checksum = "059cce4ba41e57dd82f55b348d3e83cb30fd142479d00287f08c4ae66f9e7197"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -183,9 +183,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-ir"
-version = "0.72.0"
+version = "0.71.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "39fba0a2f05527fb93c5039803c1f1ffaff5d6cebdff936386e1a5cbe7646283"
+checksum = "c0f9b041f3fcc136dbf8a92cef5f6ac743f9800467763502f5924349b781cbe0"
 dependencies = [
  "bitflags",
  "chalk-derive",
@@ -194,9 +194,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-recursive"
-version = "0.72.0"
+version = "0.71.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d01108bc48af1d40e69b3b7f6923323e904c32476d4974750c474c1f94343e5c"
+checksum = "b1dd77179b3310dea3838b73e0f5990fcf4d1c00bfd2bc43d984faa8d2783ff1"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
@@ -207,9 +207,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-solve"
-version = "0.72.0"
+version = "0.71.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ff759b94bbb114254ba01b7a7459f8fa78ae98801a814946ce7ed6d5973c8a06"
+checksum = "0c8ff6810c6bcac76950d1d292f71862e5757f483b8745a9186e649076b913be"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
@@ -747,9 +747,9 @@ dependencies = [
 
 [[package]]
 name = "instant"
-version = "0.1.12"
+version = "0.1.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
+checksum = "716d3d89f35ac6a34fd0eed635395f4c3b76fa889338a4632e5231a8684216bd"
 dependencies = [
  "cfg-if",
 ]
@@ -807,9 +807,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
 
 [[package]]
 name = "libc"
-version = "0.2.105"
+version = "0.2.103"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013"
+checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
 
 [[package]]
 name = "libloading"
@@ -953,9 +953,9 @@ dependencies = [
 
 [[package]]
 name = "mio"
-version = "0.7.14"
+version = "0.7.13"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
+checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16"
 dependencies = [
  "libc",
  "log",
@@ -1012,9 +1012,9 @@ dependencies = [
 
 [[package]]
 name = "object"
-version = "0.27.1"
+version = "0.26.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9"
+checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2"
 dependencies = [
  "memchr",
 ]
@@ -1116,9 +1116,9 @@ checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443"
 
 [[package]]
 name = "proc-macro2"
-version = "1.0.32"
+version = "1.0.30"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
+checksum = "edc3358ebc67bc8b7fa0c007f945b0b18226f78437d61bec735a9eb96b61ee70"
 dependencies = [
  "unicode-xid",
 ]
@@ -1530,9 +1530,9 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "1.0.81"
+version = "1.0.80"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
+checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
 dependencies = [
  "proc-macro2",
  "quote",
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs
index 2b091f37a0..84e295e014 100644
--- a/crates/base_db/src/fixture.rs
+++ b/crates/base_db/src/fixture.rs
@@ -136,7 +136,6 @@ impl ChangeFixture {
                     file_id,
                     meta.edition,
                     Some(crate_name.clone().into()),
-                    None,
                     meta.cfg.clone(),
                     meta.cfg,
                     meta.env,
@@ -169,7 +168,6 @@ impl ChangeFixture {
                 crate_root,
                 Edition::CURRENT,
                 Some(CrateName::new("test").unwrap().into()),
-                None,
                 default_cfg.clone(),
                 default_cfg,
                 Env::default(),
@@ -204,7 +202,6 @@ impl ChangeFixture {
                 core_file,
                 Edition::Edition2021,
                 Some(CrateDisplayName::from_canonical_name("core".to_string())),
-                None,
                 CfgOptions::default(),
                 CfgOptions::default(),
                 Env::default(),
@@ -238,7 +235,6 @@ impl ChangeFixture {
                 proc_lib_file,
                 Edition::Edition2021,
                 Some(CrateDisplayName::from_canonical_name("proc_macros".to_string())),
-                None,
                 CfgOptions::default(),
                 CfgOptions::default(),
                 Env::default(),
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index 98533ca0a7..63b2691154 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -192,7 +192,6 @@ pub struct ProcMacro {
 pub struct CrateData {
     pub root_file_id: FileId,
     pub edition: Edition,
-    pub version: Option<String>,
     /// A name used in the package's project declaration: for Cargo projects,
     /// its `[package].name` can be different for other project types or even
     /// absent (a dummy crate for the code snippet, for example).
@@ -251,7 +250,6 @@ impl CrateGraph {
         file_id: FileId,
         edition: Edition,
         display_name: Option<CrateDisplayName>,
-        version: Option<String>,
         cfg_options: CfgOptions,
         potential_cfg_options: CfgOptions,
         env: Env,
@@ -260,7 +258,6 @@ impl CrateGraph {
         let data = CrateData {
             root_file_id: file_id,
             edition,
-            version,
             display_name,
             cfg_options,
             potential_cfg_options,
@@ -566,7 +563,6 @@ mod tests {
             FileId(1u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -576,7 +572,6 @@ mod tests {
             FileId(2u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -586,7 +581,6 @@ mod tests {
             FileId(3u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -610,7 +604,6 @@ mod tests {
             FileId(1u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -620,7 +613,6 @@ mod tests {
             FileId(2u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -641,7 +633,6 @@ mod tests {
             FileId(1u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -651,7 +642,6 @@ mod tests {
             FileId(2u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -661,7 +651,6 @@ mod tests {
             FileId(3u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -682,7 +671,6 @@ mod tests {
             FileId(1u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
@@ -692,7 +680,6 @@ mod tests {
             FileId(2u32),
             Edition2018,
             None,
-            None,
             CfgOptions::default(),
             CfgOptions::default(),
             Env::default(),
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index a221c4d57e..9c6531da20 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -183,10 +183,6 @@ impl Crate {
         db.crate_graph()[self.id].edition
     }
 
-    pub fn version(self, db: &dyn HirDatabase) -> Option<String> {
-        db.crate_graph()[self.id].version.clone()
-    }
-
     pub fn display_name(self, db: &dyn HirDatabase) -> Option<CrateDisplayName> {
         db.crate_graph()[self.id].display_name.clone()
     }
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index ca23d85cb2..4f481613dd 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -208,6 +208,10 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
         self.imp.original_range_opt(node)
     }
 
+    pub fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
+        self.imp.original_ast_node(node)
+    }
+
     pub fn diagnostics_display_range(&self, diagnostics: InFile<SyntaxNodePtr>) -> FileRange {
         self.imp.diagnostics_display_range(diagnostics)
     }
@@ -660,6 +664,11 @@ impl<'db> SemanticsImpl<'db> {
         node.as_ref().original_file_range_opt(self.db.upcast())
     }
 
+    fn original_ast_node<N: AstNode>(&self, node: N) -> Option<N> {
+        let file = self.find_file(node.syntax().clone());
+        file.with_value(node).original_ast_node(self.db.upcast()).map(|it| it.value)
+    }
+
     fn diagnostics_display_range(&self, src: InFile<SyntaxNodePtr>) -> FileRange {
         let root = self.db.parse_or_expand(src.file_id).unwrap();
         let node = src.value.to_node(&root);
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index f411ef9b3c..4742cb089e 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -24,9 +24,9 @@ use std::{hash::Hash, iter, sync::Arc};
 
 use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange};
 use syntax::{
-    algo::skip_trivia_token,
+    algo::{self, skip_trivia_token},
     ast::{self, AstNode, HasAttrs},
-    Direction, SyntaxNode, SyntaxToken, TextRange,
+    Direction, SyntaxNode, SyntaxToken,
 };
 
 use crate::{
@@ -600,13 +600,15 @@ impl<'a> InFile<&'a SyntaxNode> {
 
     /// Attempts to map the syntax node back up its macro calls.
     pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
-        match original_range_opt(db, self) {
-            Some(range) => {
-                let original_file = range.file_id.original_file(db);
-                if range.file_id != original_file.into() {
+        match ascend_node_border_tokens(db, self) {
+            Some(InFile { file_id, value: (first, last) }) => {
+                let original_file = file_id.original_file(db);
+                let range = first.text_range().cover(last.text_range());
+                if file_id != original_file.into() {
                     tracing::error!("Failed mapping up more for {:?}", range);
+                    return None;
                 }
-                Some(FileRange { file_id: original_file, range: range.value })
+                Some(FileRange { file_id: original_file, range })
             }
             _ if !self.file_id.is_macro() => Some(FileRange {
                 file_id: self.file_id.original_file(db),
@@ -617,28 +619,29 @@ impl<'a> InFile<&'a SyntaxNode> {
     }
 }
 
-fn original_range_opt(
+fn ascend_node_border_tokens(
     db: &dyn db::AstDatabase,
-    node: InFile<&SyntaxNode>,
-) -> Option<InFile<TextRange>> {
-    let expansion = node.file_id.expansion_info(db)?;
+    InFile { file_id, value: node }: InFile<&SyntaxNode>,
+) -> Option<InFile<(SyntaxToken, SyntaxToken)>> {
+    let expansion = file_id.expansion_info(db)?;
 
     // the input node has only one token ?
-    let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
-        == skip_trivia_token(node.value.last_token()?, Direction::Prev)?;
+    let first = skip_trivia_token(node.first_token()?, Direction::Next)?;
+    let last = skip_trivia_token(node.last_token()?, Direction::Prev)?;
+    let is_single_token = first == last;
 
-    node.value.descendants().find_map(|it| {
+    node.descendants().find_map(|it| {
         let first = skip_trivia_token(it.first_token()?, Direction::Next)?;
-        let first = ascend_call_token(db, &expansion, node.with_value(first))?;
+        let first = ascend_call_token(db, &expansion, InFile::new(file_id, first))?;
 
         let last = skip_trivia_token(it.last_token()?, Direction::Prev)?;
-        let last = ascend_call_token(db, &expansion, node.with_value(last))?;
+        let last = ascend_call_token(db, &expansion, InFile::new(file_id, last))?;
 
-        if (!single && first == last) || (first.file_id != last.file_id) {
+        if (!is_single_token && first == last) || (first.file_id != last.file_id) {
             return None;
         }
 
-        Some(first.with_value(first.value.text_range().cover(last.value.text_range())))
+        Some(InFile::new(first.file_id, (first.value, last.value)))
     })
 }
 
@@ -674,6 +677,23 @@ impl<N: AstNode> InFile<N> {
         self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n))
     }
 
+    pub fn original_ast_node(self, db: &dyn db::AstDatabase) -> Option<InFile<N>> {
+        match ascend_node_border_tokens(db, self.syntax()) {
+            Some(InFile { file_id, value: (first, last) }) => {
+                let original_file = file_id.original_file(db);
+                if file_id != original_file.into() {
+                    let range = first.text_range().cover(last.text_range());
+                    tracing::error!("Failed mapping up more for {:?}", range);
+                    return None;
+                }
+                let anc = algo::least_common_ancestor(&first.parent()?, &last.parent()?)?;
+                Some(InFile::new(file_id, anc.ancestors().find_map(N::cast)?))
+            }
+            _ if !self.file_id.is_macro() => Some(self),
+            _ => None,
+        }
+    }
+
     pub fn syntax(&self) -> InFile<&SyntaxNode> {
         self.with_value(self.value.syntax())
     }
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml
index d0f22cdae3..14ef3e52ce 100644
--- a/crates/hir_ty/Cargo.toml
+++ b/crates/hir_ty/Cargo.toml
@@ -18,9 +18,9 @@ ena = "0.14.0"
 tracing = "0.1"
 rustc-hash = "1.1.0"
 scoped-tls = "1"
-chalk-solve = { version = "0.72", default-features = false }
-chalk-ir = "0.72"
-chalk-recursive = { version = "0.72", default-features = false }
+chalk-solve = { version = "0.71", default-features = false }
+chalk-ir = "0.71"
+chalk-recursive = { version = "0.71", default-features = false }
 la-arena = { version = "0.3.0", path = "../../lib/arena" }
 once_cell = { version = "1.5.0" }
 
diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs
index dbdbfcd8eb..8c47b809b9 100644
--- a/crates/ide/src/doc_links.rs
+++ b/crates/ide/src/doc_links.rs
@@ -473,17 +473,12 @@ fn get_doc_base_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
         }
         _ => {
             krate.get_html_root_url(db).or_else(|| {
-                let version = krate.version(db);
                 // Fallback to docs.rs. This uses `display_name` and can never be
                 // correct, but that's what fallbacks are about.
                 //
                 // FIXME: clicking on the link should just open the file in the editor,
                 // instead of falling back to external urls.
-                Some(format!(
-                    "https://docs.rs/{krate}/{version}/",
-                    krate = display_name,
-                    version = version.as_deref().unwrap_or("*")
-                ))
+                Some(format!("https://docs.rs/{krate}/*/", krate = display_name))
             })?
         }
     };
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index bc447177af..c2412254ef 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -219,7 +219,6 @@ impl Analysis {
             file_id,
             Edition::CURRENT,
             None,
-            None,
             cfg_options.clone(),
             cfg_options,
             Env::default(),
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs
index a5858869c5..cac736ff85 100644
--- a/crates/ide_assists/src/handlers/auto_import.rs
+++ b/crates/ide_assists/src/handlers/auto_import.rs
@@ -95,7 +95,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
         NodeOrToken::Token(token) => token.text_range(),
     };
     let group_label = group_label(import_assets.import_candidate());
-    let scope = ImportScope::find_insert_use_container_with_macros(
+    let scope = ImportScope::find_insert_use_container(
         &match syntax_under_caret {
             NodeOrToken::Node(it) => it,
             NodeOrToken::Token(it) => it.parent()?,
@@ -164,6 +164,60 @@ mod tests {
 
     use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
 
+    #[test]
+    fn not_applicable_if_scope_inside_macro() {
+        check_assist_not_applicable(
+            auto_import,
+            r"
+mod bar {
+    pub struct Baz;
+}
+macro_rules! foo {
+    ($it:ident) => {
+        mod __ {
+            fn __(x: $it) {}
+        }
+    };
+}
+foo! {
+    Baz$0
+}
+",
+        );
+    }
+
+    #[test]
+    fn applicable_in_attributes() {
+        check_assist(
+            auto_import,
+            r"
+//- proc_macros: identity
+#[proc_macros::identity]
+mod foo {
+    mod bar {
+        const _: Baz$0 = ();
+    }
+}
+mod baz {
+    pub struct Baz;
+}
+",
+            r"
+#[proc_macros::identity]
+mod foo {
+    mod bar {
+        use crate::baz::Baz;
+
+        const _: Baz = ();
+    }
+}
+mod baz {
+    pub struct Baz;
+}
+",
+        );
+    }
+
     #[test]
     fn applicable_when_found_an_import_partial() {
         check_assist(
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs
index 7ffb5728cc..3a334efe0a 100644
--- a/crates/ide_assists/src/handlers/extract_function.rs
+++ b/crates/ide_assists/src/handlers/extract_function.rs
@@ -91,7 +91,7 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext) -> Option
 
     let target_range = body.text_range();
 
-    let scope = ImportScope::find_insert_use_container_with_macros(&node, &ctx.sema)?;
+    let scope = ImportScope::find_insert_use_container(&node, &ctx.sema)?;
 
     acc.add(
         AssistId("extract_function", crate::AssistKind::RefactorExtract),
diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
index 3b812cdf17..8e28f0443d 100644
--- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -314,7 +314,7 @@ fn process_references(
                 if let Some(mut mod_path) = mod_path {
                     mod_path.pop_segment();
                     mod_path.push_segment(variant_hir_name.clone());
-                    let scope = ImportScope::find_insert_use_container(&scope_node)?;
+                    let scope = ImportScope::find_insert_use_container(&scope_node, &ctx.sema)?;
                     visited_modules.insert(module);
                     return Some((segment, scope_node, Some((scope, mod_path))));
                 }
diff --git a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
index 47600be763..8df8c4b726 100644
--- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
@@ -70,7 +70,7 @@ pub(crate) fn replace_qualified_name_with_use(
         })
         .flatten();
 
-    let scope = ImportScope::find_insert_use_container_with_macros(path.syntax(), &ctx.sema)?;
+    let scope = ImportScope::find_insert_use_container(path.syntax(), &ctx.sema)?;
     let target = path.syntax().text_range();
     acc.add(
         AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite),
diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs
index 5c08d12ef2..33b8481932 100644
--- a/crates/ide_completion/src/completions/attribute/derive.rs
+++ b/crates/ide_completion/src/completions/attribute/derive.rs
@@ -98,7 +98,7 @@ fn flyimport_attribute(ctx: &CompletionContext, acc: &mut Completions) -> Option
         &ctx.sema,
         parent.clone(),
     )?;
-    let import_scope = ImportScope::find_insert_use_container_with_macros(&parent, &ctx.sema)?;
+    let import_scope = ImportScope::find_insert_use_container(&parent, &ctx.sema)?;
     acc.add_all(
         import_assets
             .search_for_imports(&ctx.sema, ctx.config.insert_use.prefix_kind)
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index a5c134714b..956411f1a3 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -129,7 +129,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
 
     let user_input_lowercased = potential_import_name.to_lowercase();
     let import_assets = import_assets(ctx, potential_import_name)?;
-    let import_scope = ImportScope::find_insert_use_container_with_macros(
+    let import_scope = ImportScope::find_insert_use_container(
         &position_for_import(ctx, Some(import_assets.import_candidate()))?,
         &ctx.sema,
     )?;
diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs
index 4ee257ab43..c239401e48 100644
--- a/crates/ide_completion/src/completions/postfix.rs
+++ b/crates/ide_completion/src/completions/postfix.rs
@@ -244,8 +244,7 @@ fn add_custom_postfix_completions(
     postfix_snippet: impl Fn(&str, &str, &str) -> Builder,
     receiver_text: &str,
 ) -> Option<()> {
-    let import_scope =
-        ImportScope::find_insert_use_container_with_macros(&ctx.token.parent()?, &ctx.sema)?;
+    let import_scope = ImportScope::find_insert_use_container(&ctx.token.parent()?, &ctx.sema)?;
     ctx.config.postfix_snippets().filter(|(_, snip)| snip.scope == SnippetScope::Expr).for_each(
         |(trigger, snippet)| {
             let imports = match snippet.imports(ctx, &import_scope) {
diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs
index 1840e780ed..12bccfae11 100644
--- a/crates/ide_completion/src/completions/snippet.rs
+++ b/crates/ide_completion/src/completions/snippet.rs
@@ -102,8 +102,7 @@ fn add_custom_completions(
     cap: SnippetCap,
     scope: SnippetScope,
 ) -> Option<()> {
-    let import_scope =
-        ImportScope::find_insert_use_container_with_macros(&ctx.token.parent()?, &ctx.sema)?;
+    let import_scope = ImportScope::find_insert_use_container(&ctx.token.parent()?, &ctx.sema)?;
     ctx.config.prefix_snippets().filter(|(_, snip)| snip.scope == scope).for_each(
         |(trigger, snip)| {
             let imports = match snip.imports(ctx, &import_scope) {
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs
index 463744f22a..d9618642c4 100644
--- a/crates/ide_completion/src/lib.rs
+++ b/crates/ide_completion/src/lib.rs
@@ -183,7 +183,7 @@ pub fn resolve_completion_edits(
     let _p = profile::span("resolve_completion_edits");
     let ctx = CompletionContext::new(db, position, config)?;
     let position_for_import = &position_for_import(&ctx, None)?;
-    let scope = ImportScope::find_insert_use_container_with_macros(position_for_import, &ctx.sema)?;
+    let scope = ImportScope::find_insert_use_container(position_for_import, &ctx.sema)?;
 
     let current_module = ctx.sema.scope(position_for_import).module()?;
     let current_crate = current_module.krate();
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs
index 9889dd772e..1f3e3c55bf 100644
--- a/crates/ide_db/src/helpers/insert_use.rs
+++ b/crates/ide_db/src/helpers/insert_use.rs
@@ -8,7 +8,7 @@ use hir::Semantics;
 use syntax::{
     algo,
     ast::{self, make, AstNode, HasAttrs, HasModuleItem, HasVisibility, PathSegmentKind},
-    match_ast, ted, AstToken, Direction, NodeOrToken, SyntaxNode, SyntaxToken,
+    ted, AstToken, Direction, NodeOrToken, SyntaxNode, SyntaxToken,
 };
 
 use crate::{
@@ -50,7 +50,10 @@ pub enum ImportScope {
 }
 
 impl ImportScope {
+    // FIXME: Remove this?
+    #[cfg(test)]
     fn from(syntax: SyntaxNode) -> Option<Self> {
+        use syntax::match_ast;
         fn contains_cfg_attr(attrs: &dyn HasAttrs) -> bool {
             attrs
                 .attrs()
@@ -76,16 +79,60 @@ impl ImportScope {
     }
 
     /// Determines the containing syntax node in which to insert a `use` statement affecting `position`.
-    pub fn find_insert_use_container_with_macros(
+    /// Returns the original source node inside attributes.
+    pub fn find_insert_use_container(
         position: &SyntaxNode,
         sema: &Semantics<'_, RootDatabase>,
     ) -> Option<Self> {
-        sema.ancestors_with_macros(position.clone()).find_map(Self::from)
-    }
+        fn contains_cfg_attr(attrs: &dyn HasAttrs) -> bool {
+            attrs
+                .attrs()
+                .any(|attr| attr.as_simple_call().map_or(false, |(ident, _)| ident == "cfg"))
+        }
 
-    /// Determines the containing syntax node in which to insert a `use` statement affecting `position`.
-    pub fn find_insert_use_container(position: &SyntaxNode) -> Option<Self> {
-        std::iter::successors(Some(position.clone()), SyntaxNode::parent).find_map(Self::from)
+        // Walk up the ancestor tree searching for a suitable node to do insertions on
+        // with special handling on cfg-gated items, in which case we want to insert imports locally
+        // or FIXME: annotate inserted imports with the same cfg
+        for syntax in sema.ancestors_with_macros(position.clone()) {
+            if let Some(file) = ast::SourceFile::cast(syntax.clone()) {
+                return Some(ImportScope::File(file));
+            } else if let Some(item) = ast::Item::cast(syntax) {
+                return match item {
+                    ast::Item::Const(konst) if contains_cfg_attr(&konst) => {
+                        // FIXME: Instead of bailing out with None, we should note down that
+                        // this import needs an attribute added
+                        match sema.original_ast_node(konst)?.body()? {
+                            ast::Expr::BlockExpr(block) => block,
+                            _ => return None,
+                        }
+                        .stmt_list()
+                        .map(ImportScope::Block)
+                    }
+                    ast::Item::Fn(func) if contains_cfg_attr(&func) => {
+                        // FIXME: Instead of bailing out with None, we should note down that
+                        // this import needs an attribute added
+                        sema.original_ast_node(func)?.body()?.stmt_list().map(ImportScope::Block)
+                    }
+                    ast::Item::Static(statik) if contains_cfg_attr(&statik) => {
+                        // FIXME: Instead of bailing out with None, we should note down that
+                        // this import needs an attribute added
+                        match sema.original_ast_node(statik)?.body()? {
+                            ast::Expr::BlockExpr(block) => block,
+                            _ => return None,
+                        }
+                        .stmt_list()
+                        .map(ImportScope::Block)
+                    }
+                    ast::Item::Module(module) => {
+                        // early return is important here, if we can't find the original module
+                        // in the input there is no way for us to insert an import anywhere.
+                        sema.original_ast_node(module)?.item_list().map(ImportScope::Module)
+                    }
+                    _ => continue,
+                };
+            }
+        }
+        None
     }
 
     pub fn as_syntax_node(&self) -> &SyntaxNode {
diff --git a/crates/proc_macro_api/Cargo.toml b/crates/proc_macro_api/Cargo.toml
index f1f627dd4c..42687355c3 100644
--- a/crates/proc_macro_api/Cargo.toml
+++ b/crates/proc_macro_api/Cargo.toml
@@ -24,6 +24,6 @@ profile = { path = "../profile", version = "0.0.0" }
 # base_db = { path = "../base_db", version = "0.0.0" }
 
 [dependencies.object]
-version = "0.27"
+version = "0.26"
 default-features = false
 features = ["std", "read_core", "elf", "macho", "pe"]
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml
index be68a3a8e7..458bea1aa6 100644
--- a/crates/proc_macro_srv/Cargo.toml
+++ b/crates/proc_macro_srv/Cargo.toml
@@ -10,7 +10,7 @@ rust-version = "1.56"
 doctest = false
 
 [dependencies]
-object = { version = "0.27", default-features = false, features = [
+object = { version = "0.26", default-features = false, features = [
     "std",
     "read_core",
     "elf",
diff --git a/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs b/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs
index 6105238d0b..f8626c5f62 100644
--- a/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs
+++ b/crates/proc_macro_srv/src/abis/abi_1_55/rustc_server.rs
@@ -488,8 +488,8 @@ impl server::Literal for Rustc {
         // They must still be present to be ABI-compatible and work with upstream proc_macro.
         "".to_owned()
     }
-    fn from_str(&mut self, s: &str) -> Result<Self::Literal, ()> {
-        Ok(Literal { text: s.into(), id: tt::TokenId::unspecified() })
+    fn from_str(&mut self, _s: &str) -> Result<Self::Literal, ()> {
+        unimplemented!()
     }
     fn symbol(&mut self, literal: &Self::Literal) -> String {
         literal.text.to_string()
diff --git a/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs b/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs
index 1cebc289f8..fb8a4c8cbe 100644
--- a/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs
+++ b/crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs
@@ -489,8 +489,8 @@ impl server::Literal for Rustc {
         // They must still be present to be ABI-compatible and work with upstream proc_macro.
         "".to_owned()
     }
-    fn from_str(&mut self, s: &str) -> Result<Self::Literal, ()> {
-        Ok(Literal { text: s.into(), id: tt::TokenId::unspecified() })
+    fn from_str(&mut self, _s: &str) -> Result<Self::Literal, ()> {
+        unimplemented!()
     }
     fn symbol(&mut self, literal: &Self::Literal) -> String {
         literal.text.to_string()
diff --git a/crates/project_model/src/project_json.rs b/crates/project_model/src/project_json.rs
index d8d0d07aff..75ad66a5cc 100644
--- a/crates/project_model/src/project_json.rs
+++ b/crates/project_model/src/project_json.rs
@@ -29,7 +29,6 @@ pub struct Crate {
     pub(crate) display_name: Option<CrateDisplayName>,
     pub(crate) root_module: AbsPathBuf,
     pub(crate) edition: Edition,
-    pub(crate) version: Option<String>,
     pub(crate) deps: Vec<Dependency>,
     pub(crate) cfg: Vec<CfgFlag>,
     pub(crate) target: Option<String>,
@@ -81,7 +80,6 @@ impl ProjectJson {
                             .map(CrateDisplayName::from_canonical_name),
                         root_module,
                         edition: crate_data.edition.into(),
-                        version: crate_data.version.as_ref().map(ToString::to_string),
                         deps: crate_data
                             .deps
                             .into_iter()
@@ -129,8 +127,6 @@ struct CrateData {
     display_name: Option<String>,
     root_module: PathBuf,
     edition: EditionData,
-    #[serde(default)]
-    version: Option<semver::Version>,
     deps: Vec<DepData>,
     #[serde(default)]
     cfg: Vec<CfgFlag>,
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs
index 2fc88bf505..54e3bae17b 100644
--- a/crates/project_model/src/workspace.rs
+++ b/crates/project_model/src/workspace.rs
@@ -468,7 +468,6 @@ fn project_json_to_crate_graph(
                     file_id,
                     krate.edition,
                     krate.display_name.clone(),
-                    krate.version.clone(),
                     cfg_options.clone(),
                     cfg_options,
                     env,
@@ -676,7 +675,6 @@ fn detached_files_to_crate_graph(
             file_id,
             Edition::CURRENT,
             display_name,
-            None,
             cfg_options.clone(),
             cfg_options.clone(),
             Env::default(),
@@ -826,7 +824,6 @@ fn add_target_crate_root(
         file_id,
         edition,
         Some(display_name),
-        Some(pkg.version.to_string()),
         cfg_options,
         potential_cfg_options,
         env,
@@ -869,7 +866,6 @@ fn sysroot_to_crate_graph(
                 file_id,
                 Edition::CURRENT,
                 Some(display_name),
-                None,
                 cfg_options.clone(),
                 cfg_options.clone(),
                 env,
diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs
index f108b694c0..f3b843dc08 100644
--- a/crates/rust-analyzer/src/cli/lsif.rs
+++ b/crates/rust-analyzer/src/cli/lsif.rs
@@ -136,7 +136,6 @@ impl LsifManager<'_> {
                 result: lsp_types::Hover {
                     contents: lsp_types::HoverContents::Markup(to_proto::markup_content(
                         hover.markup,
-                        ide::HoverDocFormat::Markdown,
                     )),
                     range: None,
                 },
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index bef943464a..8e947b5540 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -8,7 +8,7 @@ use std::{sync::Arc, time::Instant};
 use crossbeam_channel::{unbounded, Receiver, Sender};
 use flycheck::FlycheckHandle;
 use ide::{Analysis, AnalysisHost, Cancellable, Change, FileId};
-use ide_db::base_db::{CrateId, FileLoader, SourceDatabase};
+use ide_db::base_db::CrateId;
 use lsp_types::{SemanticTokens, Url};
 use parking_lot::{Mutex, RwLock};
 use proc_macro_api::ProcMacroServer;
@@ -58,7 +58,6 @@ pub(crate) struct GlobalState {
     pub(crate) mem_docs: MemDocs,
     pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
     pub(crate) shutdown_requested: bool,
-    pub(crate) proc_macro_changed: bool,
     pub(crate) last_reported_status: Option<lsp_ext::ServerStatusParams>,
     pub(crate) source_root_config: SourceRootConfig,
     pub(crate) proc_macro_client: Option<ProcMacroServer>,
@@ -148,7 +147,6 @@ impl GlobalState {
             mem_docs: MemDocs::default(),
             semantic_tokens_cache: Arc::new(Default::default()),
             shutdown_requested: false,
-            proc_macro_changed: false,
             last_reported_status: None,
             source_root_config: SourceRootConfig::default(),
             proc_macro_client: None,
@@ -189,15 +187,6 @@ impl GlobalState {
             }
 
             for file in changed_files {
-                if !file.is_created_or_deleted() {
-                    let crates = self.analysis_host.raw_database().relevant_crates(file.file_id);
-                    let crate_graph = self.analysis_host.raw_database().crate_graph();
-
-                    if crates.iter().any(|&krate| !crate_graph[krate].proc_macro.is_empty()) {
-                        self.proc_macro_changed = true;
-                    }
-                }
-
                 if let Some(path) = vfs.file_path(file.file_id).as_path() {
                     let path = path.to_path_buf();
                     if reload::should_refresh_for_change(&path, file.change_kind) {
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 0ddddeca67..ba4b153cfc 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -920,14 +920,9 @@ pub(crate) fn handle_hover(
 
     let line_index = snap.file_line_index(file_range.file_id)?;
     let range = to_proto::range(&line_index, info.range);
-    let markup_kind =
-        snap.config.hover().documentation.map_or(ide::HoverDocFormat::Markdown, |kind| kind);
     let hover = lsp_ext::Hover {
         hover: lsp_types::Hover {
-            contents: HoverContents::Markup(to_proto::markup_content(
-                info.info.markup,
-                markup_kind,
-            )),
+            contents: HoverContents::Markup(to_proto::markup_content(info.info.markup)),
             range: Some(range),
         },
         actions: if snap.config.hover_actions().none() {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 4a1060596b..9f08ad5ebf 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -561,7 +561,7 @@ impl GlobalState {
                 s.shutdown_requested = true;
                 Ok(())
             })?
-            .on_sync_mut::<lsp_ext::MemoryUsage>(handlers::handle_memory_usage)?
+            .on_sync_mut::<lsp_ext::MemoryUsage>(|s, p| handlers::handle_memory_usage(s, p))?
             .on_sync::<lsp_ext::JoinLines>(handlers::handle_join_lines)?
             .on_sync::<lsp_ext::OnEnter>(handlers::handle_on_enter)?
             .on_sync::<lsp_types::request::SelectionRangeRequest>(handlers::handle_selection_range)?
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 7ba5697176..6a6df9c1dd 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -66,11 +66,6 @@ impl GlobalState {
             message: None,
         };
 
-        if self.proc_macro_changed {
-            status.health = lsp_ext::Health::Warning;
-            status.message =
-                Some("Reload required due to source changes of a procedural macro.".into())
-        }
         if let Some(error) = self.fetch_build_data_error() {
             status.health = lsp_ext::Health::Warning;
             status.message = Some(error)
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 8e77df9598..ea39f799b7 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -1202,16 +1202,9 @@ pub(crate) fn reference_title(count: usize) -> String {
     }
 }
 
-pub(crate) fn markup_content(
-    markup: Markup,
-    kind: ide::HoverDocFormat,
-) -> lsp_types::MarkupContent {
-    let kind = match kind {
-        ide::HoverDocFormat::Markdown => lsp_types::MarkupKind::Markdown,
-        ide::HoverDocFormat::PlainText => lsp_types::MarkupKind::PlainText,
-    };
+pub(crate) fn markup_content(markup: Markup) -> lsp_types::MarkupContent {
     let value = crate::markdown::format_docs(markup.as_str());
-    lsp_types::MarkupContent { kind, value }
+    lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value }
 }
 
 pub(crate) fn rename_error(err: RenameError) -> crate::LspError {
diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs
index 18a6e1410d..005e78c48a 100644
--- a/crates/syntax/src/ast/generated/nodes.rs
+++ b/crates/syntax/src/ast/generated/nodes.rs
@@ -850,6 +850,7 @@ pub struct ForExpr {
     pub(crate) syntax: SyntaxNode,
 }
 impl ast::HasAttrs for ForExpr {}
+impl ast::HasLoopBody for ForExpr {}
 impl ForExpr {
     pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
     pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 98d142da3f..2e6544f090 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -754,15 +754,6 @@ impl ast::GenericParamList {
     }
 }
 
-impl ast::HasLoopBody for ast::ForExpr {
-    fn loop_body(&self) -> Option<ast::BlockExpr> {
-        let mut exprs = support::children(self.syntax());
-        let first = exprs.next();
-        let second = exprs.next();
-        second.or(first)
-    }
-}
-
 impl ast::HasDocComments for ast::SourceFile {}
 impl ast::HasDocComments for ast::Fn {}
 impl ast::HasDocComments for ast::Struct {}
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index 58f386be85..6bae5123a6 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -50,8 +50,8 @@ fn fix_path_for_mac() -> Result<()> {
         };
 
         [ROOT_DIR, &home_dir]
-            .into_iter()
-            .map(|dir| dir.to_string() + COMMON_APP_PATH)
+            .iter()
+            .map(|dir| String::from(*dir) + COMMON_APP_PATH)
             .map(PathBuf::from)
             .filter(|path| path.exists())
             .collect()


Test patch:
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs
index 4a0a5d6fa1..67952edca3 100644
--- a/crates/hir_ty/src/tests/regression.rs
+++ b/crates/hir_ty/src/tests/regression.rs
@@ -1221,27 +1221,3 @@ fn mamba(a: U32!(), p: u32) -> u32 {
     "#,
     )
 }
-
-#[test]
-fn for_loop_block_expr_iterable() {
-    check_infer(
-        r#"
-fn test() {
-    for _ in { let x = 0; } {
-        let y = 0;
-    }
-}
-        "#,
-        expect![[r#"
-            10..68 '{     ...   } }': ()
-            16..66 'for _ ...     }': ()
-            20..21 '_': {unknown}
-            25..39 '{ let x = 0; }': ()
-            31..32 'x': i32
-            35..36 '0': i32
-            40..66 '{     ...     }': ()
-            54..55 'y': i32
-            58..59 '0': i32
-        "#]],
-    );
-}
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs
index 7f3c93d740..5a79979533 100644
--- a/crates/ide_assists/src/tests.rs
+++ b/crates/ide_assists/src/tests.rs
@@ -2,7 +2,7 @@ mod sourcegen;
 mod generated;
 
 use expect_test::expect;
-use hir::Semantics;
+use hir::{db::DefDatabase, Semantics};
 use ide_db::{
     base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt},
     helpers::{
@@ -117,7 +117,8 @@ enum ExpectedResult<'a> {
 
 #[track_caller]
 fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: Option<&str>) {
-    let (db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before);
+    let (mut db, file_with_caret_id, range_or_offset) = RootDatabase::with_range_or_offset(before);
+    db.set_enable_proc_attr_macros(true);
     let text_without_caret = db.file_text(file_with_caret_id).to_string();
 
     let frange = FileRange { file_id: file_with_caret_id, range: range_or_offset.into() };
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs
index f3b9c7130f..34a6900e26 100644
--- a/crates/ide_db/src/helpers/insert_use/tests.rs
+++ b/crates/ide_db/src/helpers/insert_use/tests.rs
@@ -1,5 +1,7 @@
+use base_db::fixture::WithFixture;
 use hir::PrefixKind;
-use test_utils::{assert_eq_text, extract_range_or_offset, CURSOR_MARKER};
+use stdx::trim_indent;
+use test_utils::{assert_eq_text, CURSOR_MARKER};
 
 use super::*;
 
@@ -865,17 +867,20 @@ fn check_with_config(
     ra_fixture_after: &str,
     config: &InsertUseConfig,
 ) {
-    let (text, pos) = if ra_fixture_before.contains(CURSOR_MARKER) {
-        let (range_or_offset, text) = extract_range_or_offset(ra_fixture_before);
-        (text, Some(range_or_offset))
+    let (db, file_id, pos) = if ra_fixture_before.contains(CURSOR_MARKER) {
+        let (db, file_id, range_or_offset) = RootDatabase::with_range_or_offset(ra_fixture_before);
+        (db, file_id, Some(range_or_offset))
     } else {
-        (ra_fixture_before.to_owned(), None)
+        let (db, file_id) = RootDatabase::with_single_file(ra_fixture_before);
+        (db, file_id, None)
     };
-    let syntax = ast::SourceFile::parse(&text).tree().syntax().clone_for_update();
+    let sema = &Semantics::new(&db);
+    let source_file = sema.parse(file_id);
+    let syntax = source_file.syntax().clone_for_update();
     let file = pos
         .and_then(|pos| syntax.token_at_offset(pos.expect_offset()).next()?.parent())
-        .and_then(|it| super::ImportScope::find_insert_use_container(&it))
-        .or_else(|| super::ImportScope::from(syntax))
+        .and_then(|it| ImportScope::find_insert_use_container(&it, sema))
+        .or_else(|| ImportScope::from(syntax))
         .unwrap();
     let path = ast::SourceFile::parse(&format!("use {};", path))
         .tree()
@@ -886,7 +891,7 @@ fn check_with_config(
 
     insert_use(&file, path, config);
     let result = file.as_syntax_node().ancestors().last().unwrap().to_string();
-    assert_eq_text!(ra_fixture_after, &result);
+    assert_eq_text!(&trim_indent(ra_fixture_after), &result);
 }
 
 fn check(
@@ -942,6 +947,6 @@ fn check_merge_only_fail(ra_fixture0: &str, ra_fixture1: &str, mb: MergeBehavior
 
 fn check_guess(ra_fixture: &str, expected: ImportGranularityGuess) {
     let syntax = ast::SourceFile::parse(ra_fixture).tree().syntax().clone();
-    let file = super::ImportScope::from(syntax).unwrap();
+    let file = ImportScope::from(syntax).unwrap();
     assert_eq!(super::guess_granularity_from_scope(&file), expected);
 }
diff --git a/crates/project_model/src/tests.rs b/crates/project_model/src/tests.rs
index 252acde14d..647d30605d 100644
--- a/crates/project_model/src/tests.rs
+++ b/crates/project_model/src/tests.rs
@@ -121,9 +121,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             1,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -181,9 +178,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             6,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -250,9 +244,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             3,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -319,9 +310,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             5,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -378,9 +366,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             2,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -447,9 +432,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             7,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -506,9 +488,6 @@ fn cargo_hello_world_project_model_with_wildcard_overrides() {
                             4,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -597,9 +576,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             1,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -659,9 +635,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             6,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -728,9 +701,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             3,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -799,9 +769,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             5,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -858,9 +825,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             2,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -929,9 +893,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             7,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -988,9 +949,6 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
                             4,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1072,9 +1030,6 @@ fn cargo_hello_world_project_model() {
                             1,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1134,9 +1089,6 @@ fn cargo_hello_world_project_model() {
                             6,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1205,9 +1157,6 @@ fn cargo_hello_world_project_model() {
                             3,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1276,9 +1225,6 @@ fn cargo_hello_world_project_model() {
                             5,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1337,9 +1283,6 @@ fn cargo_hello_world_project_model() {
                             2,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1408,9 +1351,6 @@ fn cargo_hello_world_project_model() {
                             7,
                         ),
                         edition: Edition2015,
-                        version: Some(
-                            "0.2.98",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1469,9 +1409,6 @@ fn cargo_hello_world_project_model() {
                             4,
                         ),
                         edition: Edition2018,
-                        version: Some(
-                            "0.1.0",
-                        ),
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1553,7 +1490,6 @@ fn rust_project_hello_world_project_model() {
                             1,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1591,7 +1527,6 @@ fn rust_project_hello_world_project_model() {
                             11,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1619,7 +1554,6 @@ fn rust_project_hello_world_project_model() {
                             8,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1647,7 +1581,6 @@ fn rust_project_hello_world_project_model() {
                             5,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1685,7 +1618,6 @@ fn rust_project_hello_world_project_model() {
                             2,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1713,7 +1645,6 @@ fn rust_project_hello_world_project_model() {
                             12,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1778,7 +1709,6 @@ fn rust_project_hello_world_project_model() {
                             9,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1806,7 +1736,6 @@ fn rust_project_hello_world_project_model() {
                             6,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1834,7 +1763,6 @@ fn rust_project_hello_world_project_model() {
                             3,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1862,7 +1790,6 @@ fn rust_project_hello_world_project_model() {
                             10,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -1890,7 +1817,6 @@ fn rust_project_hello_world_project_model() {
                             7,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
@@ -2000,7 +1926,6 @@ fn rust_project_hello_world_project_model() {
                             4,
                         ),
                         edition: Edition2018,
-                        version: None,
                         display_name: Some(
                             CrateDisplayName {
                                 crate_name: CrateName(
diff --git a/crates/syntax/src/tests/sourcegen_ast.rs b/crates/syntax/src/tests/sourcegen_ast.rs
index dcd813bbe0..36fedd2f0b 100644
--- a/crates/syntax/src/tests/sourcegen_ast.rs
+++ b/crates/syntax/src/tests/sourcegen_ast.rs
@@ -81,17 +81,10 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
         .map(|node| {
             let name = format_ident!("{}", node.name);
             let kind = format_ident!("{}", to_upper_snake_case(&node.name));
-            let traits = node
-                .traits
-                .iter()
-                .filter(|trait_name| {
-                    // For loops have two expressions so this might collide, therefor manual impl it
-                    node.name != "ForExpr" || trait_name.as_str() != "HasLoopBody"
-                })
-                .map(|trait_name| {
-                    let trait_name = format_ident!("{}", trait_name);
-                    quote!(impl ast::#trait_name for #name {})
-                });
+            let traits = node.traits.iter().map(|trait_name| {
+                let trait_name = format_ident!("{}", trait_name);
+                quote!(impl ast::#trait_name for #name {})
+            });
 
             let methods = node.fields.iter().map(|field| {
                 let method_name = field.method_name();