Repository: rust-analyzer/rust-analyzer
Pull request #11974 (2022-04-13 10:28:31)

minor: prepare CI for rust-lang move
bors r+


Patch:
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index baefd8bc1f..d1048bd354 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -17,7 +17,7 @@ env:
 
 jobs:
   rust:
-    if: github.repository == 'rust-analyzer/rust-analyzer'
+    if: github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer'
     name: Rust
     runs-on: ${{ matrix.os }}
     env:
@@ -62,7 +62,7 @@ jobs:
 
   # Weird targets to catch non-portable code
   rust-cross:
-    if: github.repository == 'rust-analyzer/rust-analyzer'
+    if: github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer'
     name: Rust Cross
     runs-on: ubuntu-latest
 
@@ -99,7 +99,7 @@ jobs:
         done
 
   typescript:
-    if: github.repository == 'rust-analyzer/rust-analyzer'
+    if: github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer'
     name: TypeScript
     strategy:
       fail-fast: false
diff --git a/.github/workflows/metrics.yaml b/.github/workflows/metrics.yaml
index f4412ef657..c09642868d 100644
--- a/.github/workflows/metrics.yaml
+++ b/.github/workflows/metrics.yaml
@@ -12,7 +12,7 @@ env:
 
 jobs:
   metrics:
-    if: github.repository == 'rust-analyzer/rust-analyzer'
+    if: github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer'
     runs-on: ubuntu-latest
 
     steps:
diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml
index 4ee7add1de..b1da921610 100644
--- a/.github/workflows/release.yaml
+++ b/.github/workflows/release.yaml
@@ -247,12 +247,12 @@ jobs:
         working-directory: ./editors/code
 
       - name: Publish Extension (release)
-        if: github.ref == 'refs/heads/release' && github.repository == 'rust-analyzer/rust-analyzer'
+        if: github.ref == 'refs/heads/release' && (github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer')
         working-directory: ./editors/code
         # token from https://dev.azure.com/rust-analyzer/
         run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer-*.vsix
 
       - name: Publish Extension (nightly)
-        if: github.ref != 'refs/heads/release' && github.repository == 'rust-analyzer/rust-analyzer'
+        if: github.ref != 'refs/heads/release' && (github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer')
         working-directory: ./editors/code
         run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer-*.vsix --pre-release
diff --git a/.github/workflows/rustdoc.yaml b/.github/workflows/rustdoc.yaml
index ac69adb947..eccc7d6858 100644
--- a/.github/workflows/rustdoc.yaml
+++ b/.github/workflows/rustdoc.yaml
@@ -12,7 +12,7 @@ env:
 
 jobs:
   rustdoc:
-    if: github.repository == 'rust-analyzer/rust-analyzer'
+    if: github.repository == 'rust-analyzer/rust-analyzer' || github.repository == 'rust-lang/rust-analyzer'
     runs-on: ubuntu-latest
 
     steps:
diff --git a/Cargo.lock b/Cargo.lock
index cea8540936..aeea1d9efa 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -171,9 +171,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
 name = "chalk-derive"
-version = "0.82.0"
+version = "0.81.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee9cd790d543c29ce953abcb28d54b9fbaf9c4033bfd3024de99b1aa0f3c3ada"
+checksum = "0bb2ca8aa9da8210effebb51e49b4bd8bc25c06df38220d58a60df35a08a84af"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -183,9 +183,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-ir"
-version = "0.82.0"
+version = "0.81.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dddf2c11f9de666c08c7591eb113efcdc740bd8ac602915475b045bcbe7f27a5"
+checksum = "e128fa3652ef2cdd5a7e64e0cc5a89f40170f80dd9f6357ba4a82cf027abd0d5"
 dependencies = [
  "bitflags",
  "chalk-derive",
@@ -194,9 +194,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-recursive"
-version = "0.82.0"
+version = "0.81.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a60d5b35598702963ffd145b8bfa0d8d8ae9da3a731e4e0814aa21541b85c2d5"
+checksum = "ea6fcba1e8b66a291430b6aa18368a95da0577d7f126653baae71c0cb0f3d093"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
@@ -207,9 +207,9 @@ dependencies = [
 
 [[package]]
 name = "chalk-solve"
-version = "0.82.0"
+version = "0.81.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d99da4fa3b224c07f6c2506e6905bca9d6aad665f11d25364e6818a7ea149215"
+checksum = "43151ddc627d8dfbde6af44405cb8e98a15828f66a3d4a3da6a1fad6c5dc4687"
 dependencies = [
  "chalk-derive",
  "chalk-ir",
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml
index 1fe5788253..efcd5ffc5e 100644
--- a/crates/hir_ty/Cargo.toml
+++ b/crates/hir_ty/Cargo.toml
@@ -18,9 +18,9 @@ ena = "0.14.0"
 tracing = "0.1.32"
 rustc-hash = "1.1.0"
 scoped-tls = "1.0.0"
-chalk-solve = { version = "0.82.0", default-features = false }
-chalk-ir = "0.82.0"
-chalk-recursive = { version = "0.82.0", default-features = false }
+chalk-solve = { version = "0.81.0", default-features = false }
+chalk-ir = "0.81.0"
+chalk-recursive = { version = "0.81.0", default-features = false }
 la-arena = { version = "0.3.0", path = "../../lib/arena" }
 once_cell = "1.10.0"
 typed-arena = "2.0.1"
diff --git a/crates/ide/src/rename.rs b/crates/ide/src/rename.rs
index f5bff5fd91..1bb3cdb907 100644
--- a/crates/ide/src/rename.rs
+++ b/crates/ide/src/rename.rs
@@ -968,21 +968,15 @@ mod fo$0o;
                         },
                     },
                     file_system_edits: [
-                        MoveDir {
-                            src: AnchoredPathBuf {
-                                anchor: FileId(
-                                    1,
-                                ),
-                                path: "foo",
-                            },
-                            src_id: FileId(
+                        MoveFile {
+                            src: FileId(
                                 1,
                             ),
                             dst: AnchoredPathBuf {
                                 anchor: FileId(
                                     1,
                                 ),
-                                path: "foo2",
+                                path: "../foo2/mod.rs",
                             },
                         },
                     ],
@@ -1119,68 +1113,6 @@ pub mod foo$0;
         );
     }
 
-    #[test]
-    fn test_rename_mod_recursive() {
-        check_expect(
-            "foo2",
-            r#"
-//- /lib.rs
-mod foo$0;
-
-//- /foo.rs
-mod bar;
-mod corge;
-
-//- /foo/bar.rs
-mod qux;
-
-//- /foo/bar/qux.rs
-mod quux;
-
-//- /foo/bar/qux/quux/mod.rs
-// empty
-
-//- /foo/corge.rs
-// empty
-"#,
-            expect![[r#"
-                SourceChange {
-                    source_file_edits: {
-                        FileId(
-                            0,
-                        ): TextEdit {
-                            indels: [
-                                Indel {
-                                    insert: "foo2",
-                                    delete: 4..7,
-                                },
-                            ],
-                        },
-                    },
-                    file_system_edits: [
-                        MoveDir {
-                            src: AnchoredPathBuf {
-                                anchor: FileId(
-                                    1,
-                                ),
-                                path: "foo",
-                            },
-                            src_id: FileId(
-                                1,
-                            ),
-                            dst: AnchoredPathBuf {
-                                anchor: FileId(
-                                    1,
-                                ),
-                                path: "foo2",
-                            },
-                        },
-                    ],
-                    is_snippet: false,
-                }
-            "#]],
-        )
-    }
     #[test]
     fn test_rename_mod_ref_by_super() {
         check(
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs
index b8a904a3a0..7dbc511395 100644
--- a/crates/ide_completion/src/completions.rs
+++ b/crates/ide_completion/src/completions.rs
@@ -126,7 +126,7 @@ impl Completions {
             cov_mark::hit!(qualified_path_doc_hidden);
             return;
         }
-        self.add(render_resolution(RenderContext::new(ctx), local_name, resolution).build());
+        self.add(render_resolution(RenderContext::new(ctx), local_name, resolution));
     }
 
     pub(crate) fn add_resolution_simple(
@@ -138,7 +138,7 @@ impl Completions {
         if ctx.is_scope_def_hidden(resolution) {
             return;
         }
-        self.add(render_resolution_simple(RenderContext::new(ctx), local_name, resolution).build());
+        self.add(render_resolution_simple(RenderContext::new(ctx), local_name, resolution));
     }
 
     pub(crate) fn add_macro(
@@ -152,14 +152,11 @@ impl Completions {
             Visible::Editable => true,
             Visible::No => return,
         };
-        self.add(
-            render_macro(
-                RenderContext::new(ctx).private_editable(is_private_editable),
-                local_name,
-                mac,
-            )
-            .build(),
-        );
+        self.add(render_macro(
+            RenderContext::new(ctx).private_editable(is_private_editable),
+            local_name,
+            mac,
+        ));
     }
 
     pub(crate) fn add_function(
@@ -173,14 +170,11 @@ impl Completions {
             Visible::Editable => true,
             Visible::No => return,
         };
-        self.add(
-            render_fn(
-                RenderContext::new(ctx).private_editable(is_private_editable),
-                local_name,
-                func,
-            )
-            .build(),
-        );
+        self.add(render_fn(
+            RenderContext::new(ctx).private_editable(is_private_editable),
+            local_name,
+            func,
+        ));
     }
 
     pub(crate) fn add_method(
@@ -195,15 +189,12 @@ impl Completions {
             Visible::Editable => true,
             Visible::No => return,
         };
-        self.add(
-            render_method(
-                RenderContext::new(ctx).private_editable(is_private_editable),
-                receiver,
-                local_name,
-                func,
-            )
-            .build(),
-        );
+        self.add(render_method(
+            RenderContext::new(ctx).private_editable(is_private_editable),
+            receiver,
+            local_name,
+            func,
+        ));
     }
 
     pub(crate) fn add_const(&mut self, ctx: &CompletionContext, konst: hir::Const) {
@@ -244,11 +235,7 @@ impl Completions {
         variant: hir::Variant,
         path: hir::ModPath,
     ) {
-        if let Some(builder) =
-            render_variant_lit(RenderContext::new(ctx), None, variant, Some(path))
-        {
-            self.add(builder.build());
-        }
+        self.add_opt(render_variant_lit(RenderContext::new(ctx), None, variant, Some(path)));
     }
 
     pub(crate) fn add_enum_variant(
@@ -257,11 +244,7 @@ impl Completions {
         variant: hir::Variant,
         local_name: Option<hir::Name>,
     ) {
-        if let Some(builder) =
-            render_variant_lit(RenderContext::new(ctx), local_name, variant, None)
-        {
-            self.add(builder.build());
-        }
+        self.add_opt(render_variant_lit(RenderContext::new(ctx), local_name, variant, None));
     }
 
     pub(crate) fn add_field(
@@ -292,11 +275,8 @@ impl Completions {
         path: Option<hir::ModPath>,
         local_name: Option<hir::Name>,
     ) {
-        if let Some(builder) =
-            render_struct_literal(RenderContext::new(ctx), strukt, path, local_name)
-        {
-            self.add(builder.build());
-        }
+        let item = render_struct_literal(RenderContext::new(ctx), strukt, path, local_name);
+        self.add_opt(item);
     }
 
     pub(crate) fn add_union_literal(
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 76d708ae51..fb857aeccd 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -205,8 +205,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
                     &user_input_lowercased,
                 )
             })
-            .filter_map(|import| render_resolution_with_import(RenderContext::new(ctx), import))
-            .map(|builder| builder.build()),
+            .filter_map(|import| render_resolution_with_import(RenderContext::new(ctx), import)),
     );
     Some(())
 }
diff --git a/crates/ide_completion/src/completions/trait_impl.rs b/crates/ide_completion/src/completions/trait_impl.rs
index 43428f777f..13e05049e2 100644
--- a/crates/ide_completion/src/completions/trait_impl.rs
+++ b/crates/ide_completion/src/completions/trait_impl.rs
@@ -167,7 +167,7 @@ fn add_function_impl(
     };
 
     let mut item = CompletionItem::new(completion_kind, replacement_range, label);
-    item.lookup_by(format!("fn {}", fn_name))
+    item.lookup_by(fn_name)
         .set_documentation(func.docs(ctx.db))
         .set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
 
@@ -228,17 +228,13 @@ fn add_type_alias_impl(
     let alias_name = type_alias.name(ctx.db).to_smol_str();
 
     let label = format!("type {} =", alias_name);
-    let replacement = format!("type {} = ", alias_name);
+    let snippet = format!("type {} = ", alias_name);
 
     let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
-    item.lookup_by(format!("type {}", alias_name))
+    item.text_edit(TextEdit::replace(replacement_range, snippet))
+        .lookup_by(alias_name)
         .set_documentation(type_alias.docs(ctx.db))
         .set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
-    match ctx.config.snippet_cap {
-        Some(cap) => item
-            .snippet_edit(cap, TextEdit::replace(replacement_range, format!("{}$0;", replacement))),
-        None => item.text_edit(TextEdit::replace(replacement_range, replacement)),
-    };
     item.add_to(acc);
 }
 
@@ -261,22 +257,16 @@ fn add_const_impl(
                 };
 
                 let label = make_const_compl_syntax(&transformed_const);
-                let replacement = format!("{} ", label);
+                let snippet = format!("{} ", label);
 
                 let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
-                item.lookup_by(format!("const {}", const_name))
+                item.text_edit(TextEdit::replace(replacement_range, snippet))
+                    .lookup_by(const_name)
                     .set_documentation(const_.docs(ctx.db))
                     .set_relevance(CompletionRelevance {
                         is_item_from_trait: true,
                         ..Default::default()
                     });
-                match ctx.config.snippet_cap {
-                    Some(cap) => item.snippet_edit(
-                        cap,
-                        TextEdit::replace(replacement_range, format!("{}$0;", replacement)),
-                    ),
-                    None => item.text_edit(TextEdit::replace(replacement_range, replacement)),
-                };
                 item.add_to(acc);
             }
         }
@@ -559,7 +549,7 @@ impl Test for T {
     #[test]
     fn name_ref_single_function() {
         check_edit(
-            "fn test",
+            "test",
             r#"
 trait Test {
     fn test();
@@ -588,7 +578,7 @@ impl Test for T {
     #[test]
     fn single_function() {
         check_edit(
-            "fn test",
+            "test",
             r#"
 trait Test {
     fn test();
@@ -617,7 +607,7 @@ impl Test for T {
     #[test]
     fn generic_fn() {
         check_edit(
-            "fn foo",
+            "foo",
             r#"
 trait Test {
     fn foo<T>();
@@ -642,7 +632,7 @@ impl Test for T {
 "#,
         );
         check_edit(
-            "fn foo",
+            "foo",
             r#"
 trait Test {
     fn foo<T>() where T: Into<String>;
@@ -672,7 +662,7 @@ where T: Into<String> {
     #[test]
     fn associated_type() {
         check_edit(
-            "type SomeType",
+            "SomeType",
             r#"
 trait Test {
     type SomeType;
@@ -688,7 +678,7 @@ trait Test {
 }
 
 impl Test for () {
-    type SomeType = $0;\n\
+    type SomeType = \n\
 }
 ",
         );
@@ -697,7 +687,7 @@ impl Test for () {
     #[test]
     fn associated_const() {
         check_edit(
-            "const SOME_CONST",
+            "SOME_CONST",
             r#"
 trait Test {
     const SOME_CONST: u16;
@@ -713,13 +703,13 @@ trait Test {
 }
 
 impl Test for () {
-    const SOME_CONST: u16 = $0;\n\
+    const SOME_CONST: u16 = \n\
 }
 ",
         );
 
         check_edit(
-            "const SOME_CONST",
+            "SOME_CONST",
             r#"
 trait Test {
     const SOME_CONST: u16 = 92;
@@ -735,7 +725,7 @@ trait Test {
 }
 
 impl Test for () {
-    const SOME_CONST: u16 = $0;\n\
+    const SOME_CONST: u16 = \n\
 }
 ",
         );
@@ -793,9 +783,9 @@ impl Test for T {{
             "default type OtherType = i32;",
             "default const OTHER_CONST: i32 = 0;",
         ] {
-            test("fn bar", "fn $0", "fn bar() {\n    $0\n}", next_sibling);
-            test("type Foo", "type $0", "type Foo = $0;", next_sibling);
-            test("const CONST", "const $0", "const CONST: u16 = $0;", next_sibling);
+            test("bar", "fn $0", "fn bar() {\n    $0\n}", next_sibling);
+            test("Foo", "type $0", "type Foo = ", next_sibling);
+            test("CONST", "const $0", "const CONST: u16 = ", next_sibling);
         }
     }
 
@@ -840,15 +830,15 @@ impl Foo for T {{
                 ),
             )
         };
-        test("fn function", "fn f$0", "fn function() {\n    $0\n}");
-        test("type Type", "type T$0", "type Type = $0;");
-        test("const CONST", "const C$0", "const CONST: i32 = $0;");
+        test("function", "fn f$0", "fn function() {\n    $0\n}");
+        test("Type", "type T$0", "type Type = ");
+        test("CONST", "const C$0", "const CONST: i32 = ");
     }
 
     #[test]
     fn generics_are_inlined_in_return_type() {
         check_edit(
-            "fn function",
+            "function",
             r#"
 trait Foo<T> {
     fn function() -> T;
@@ -877,7 +867,7 @@ impl Foo<u32> for Bar {
     #[test]
     fn generics_are_inlined_in_parameter() {
         check_edit(
-            "fn function",
+            "function",
             r#"
 trait Foo<T> {
     fn function(bar: T);
@@ -906,7 +896,7 @@ impl Foo<u32> for Bar {
     #[test]
     fn generics_are_inlined_when_part_of_other_types() {
         check_edit(
-            "fn function",
+            "function",
             r#"
 trait Foo<T> {
     fn function(bar: Vec<T>);
@@ -935,7 +925,7 @@ impl Foo<u32> for Bar {
     #[test]
     fn generics_are_inlined_complex() {
         check_edit(
-            "fn function",
+            "function",
             r#"
 trait Foo<T, U, V> {
     fn function(bar: Vec<T>, baz: U) -> Arc<Vec<V>>;
@@ -964,7 +954,7 @@ impl Foo<u32, Vec<usize>, u8> for Bar {
     #[test]
     fn generics_are_inlined_in_associated_const() {
         check_edit(
-            "const BAR",
+            "BAR",
             r#"
 trait Foo<T> {
     const BAR: T;
@@ -972,7 +962,7 @@ trait Foo<T> {
 struct Bar;
 
 impl Foo<u32> for Bar {
-    const B$0
+    const B$0;
 }
 "#,
             r#"
@@ -982,7 +972,7 @@ trait Foo<T> {
 struct Bar;
 
 impl Foo<u32> for Bar {
-    const BAR: u32 = $0;
+    const BAR: u32 = ;
 }
 "#,
         )
@@ -991,7 +981,7 @@ impl Foo<u32> for Bar {
     #[test]
     fn generics_are_inlined_in_where_clause() {
         check_edit(
-            "fn function",
+            "function",
             r#"
 trait SomeTrait<T> {}
 
diff --git a/crates/ide_completion/src/completions/use_.rs b/crates/ide_completion/src/completions/use_.rs
index 3f757f9816..d7c279f9d9 100644
--- a/crates/ide_completion/src/completions/use_.rs
+++ b/crates/ide_completion/src/completions/use_.rs
@@ -1,13 +1,11 @@
 //! Completion for use trees
 
 use hir::ScopeDef;
-use rustc_hash::FxHashSet;
 use syntax::{ast, AstNode};
 
 use crate::{
     context::{CompletionContext, PathCompletionCtx, PathKind, PathQualifierCtx},
-    item::Builder,
-    CompletionRelevance, Completions,
+    Completions,
 };
 
 pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext) {
@@ -41,22 +39,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
                 None => return,
             };
 
-            let mut already_imported_names = FxHashSet::default();
-            if let Some(list) = ctx.token.ancestors().find_map(ast::UseTreeList::cast) {
-                let use_tree = list.parent_use_tree();
-                if use_tree.path().as_ref() == Some(path) {
-                    for tree in list.use_trees() {
-                        if tree.is_simple_path() {
-                            if let Some(name) =
-                                tree.path().and_then(|path| path.as_single_name_ref())
-                            {
-                                already_imported_names.insert(name.to_string());
-                            }
-                        }
-                    }
-                }
-            }
-
             match resolution {
                 hir::PathResolution::Def(hir::ModuleDef::Module(module)) => {
                     let module_scope = module.scope(ctx.db, Some(ctx.module));
@@ -68,9 +50,6 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
                         )
                     };
                     for (name, def) in module_scope {
-                        let is_name_already_imported =
-                            already_imported_names.contains(name.as_text().unwrap().as_str());
-
                         let add_resolution = match def {
                             ScopeDef::Unknown if unknown_is_current(&name) => {
                                 // for `use self::foo$0`, don't suggest `foo` as a completion
@@ -82,12 +61,7 @@ pub(crate) fn complete_use_tree(acc: &mut Completions, ctx: &CompletionContext)
                         };
 
                         if add_resolution {
-                            let mut builder = Builder::from_resolution(ctx, name, def);
-                            builder.set_relevance(CompletionRelevance {
-                                is_name_already_imported,
-                                ..Default::default()
-                            });
-                            acc.add(builder.build());
+                            acc.add_resolution(ctx, name, def);
                         }
                     }
                 }
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs
index 41fae38da1..2fa8f77264 100644
--- a/crates/ide_completion/src/item.rs
+++ b/crates/ide_completion/src/item.rs
@@ -9,11 +9,6 @@ use stdx::{impl_from, never};
 use syntax::{SmolStr, TextRange};
 use text_edit::TextEdit;
 
-use crate::{
-    context::CompletionContext,
-    render::{render_resolution, RenderContext},
-};
-
 /// `CompletionItem` describes a single completion variant in the editor pop-up.
 /// It is basically a POD with various properties. To construct a
 /// `CompletionItem`, use `new` method and the `Builder` struct.
@@ -139,8 +134,6 @@ pub struct CompletionRelevance {
     pub is_local: bool,
     /// This is set when trait items are completed in an impl of that trait.
     pub is_item_from_trait: bool,
-    /// This is set when an import is suggested whose name is already imported.
-    pub is_name_already_imported: bool,
     /// Set for method completions of the `core::ops` and `core::cmp` family.
     pub is_op_method: bool,
     /// Set for item completions that are private but in the workspace.
@@ -207,7 +200,6 @@ impl CompletionRelevance {
             type_match,
             is_local,
             is_item_from_trait,
-            is_name_already_imported,
             is_op_method,
             is_private_editable,
             postfix_match,
@@ -222,10 +214,6 @@ impl CompletionRelevance {
         if !is_op_method {
             score += 10;
         }
-        // lower rank for conflicting import names
-        if !is_name_already_imported {
-            score += 1;
-        }
         if exact_name_match {
             score += 10;
         }
@@ -336,7 +324,7 @@ impl CompletionItem {
             kind: kind.into(),
             text_edit: None,
             deprecated: false,
-            trigger_call_info: false,
+            trigger_call_info: None,
             relevance: CompletionRelevance::default(),
             ref_match: None,
             imports_to_add: Default::default(),
@@ -419,20 +407,12 @@ pub(crate) struct Builder {
     kind: CompletionItemKind,
     text_edit: Option<TextEdit>,
     deprecated: bool,
-    trigger_call_info: bool,
+    trigger_call_info: Option<bool>,
     relevance: CompletionRelevance,
     ref_match: Option<Mutability>,
 }
 
 impl Builder {
-    pub(crate) fn from_resolution(
-        ctx: &CompletionContext,
-        local_name: hir::Name,
-        resolution: hir::ScopeDef,
-    ) -> Self {
-        render_resolution(RenderContext::new(ctx), local_name, resolution)
-    }
-
     pub(crate) fn build(self) -> CompletionItem {
         let _p = profile::span("item::Builder::build");
 
@@ -465,7 +445,7 @@ impl Builder {
             lookup,
             kind: self.kind,
             deprecated: self.deprecated,
-            trigger_call_info: self.trigger_call_info,
+            trigger_call_info: self.trigger_call_info.unwrap_or(false),
             relevance: self.relevance,
             ref_match: self.ref_match,
             import_to_add: self.imports_to_add,
@@ -533,7 +513,7 @@ impl Builder {
         self
     }
     pub(crate) fn trigger_call_info(&mut self) -> &mut Builder {
-        self.trigger_call_info = true;
+        self.trigger_call_info = Some(true);
         self
     }
     pub(crate) fn add_import(&mut self, import_to_add: LocatedImport) -> &mut Builder {
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs
index 810ef63ec3..5b0257f6b4 100644
--- a/crates/ide_completion/src/render.rs
+++ b/crates/ide_completion/src/render.rs
@@ -18,7 +18,7 @@ use syntax::{SmolStr, SyntaxKind, TextRange};
 
 use crate::{
     context::{PathCompletionCtx, PathKind},
-    item::{Builder, CompletionRelevanceTypeMatch},
+    item::CompletionRelevanceTypeMatch,
     render::{function::render_fn, literal::render_variant_lit, macro_::render_macro},
     CompletionContext, CompletionItem, CompletionItemKind, CompletionRelevance,
 };
@@ -144,7 +144,7 @@ pub(crate) fn render_resolution(
     ctx: RenderContext<'_>,
     local_name: hir::Name,
     resolution: ScopeDef,
-) -> Builder {
+) -> CompletionItem {
     render_resolution_(ctx, local_name, None, resolution)
 }
 
@@ -152,14 +152,14 @@ pub(crate) fn render_resolution_simple(
     ctx: RenderContext<'_>,
     local_name: hir::Name,
     resolution: ScopeDef,
-) -> Builder {
+) -> CompletionItem {
     render_resolution_simple_(ctx, local_name, None, resolution)
 }
 
 pub(crate) fn render_resolution_with_import(
     ctx: RenderContext<'_>,
     import_edit: LocatedImport,
-) -> Option<Builder> {
+) -> Option<CompletionItem> {
     let resolution = ScopeDef::from(import_edit.original_item);
     let local_name = match resolution {
         ScopeDef::ModuleDef(hir::ModuleDef::Function(f)) => f.name(ctx.completion.db),
@@ -182,7 +182,7 @@ fn render_resolution_(
     local_name: hir::Name,
     import_to_add: Option<LocatedImport>,
     resolution: ScopeDef,
-) -> Builder {
+) -> CompletionItem {
     let _p = profile::span("render_resolution");
     use hir::ModuleDef::*;
 
@@ -211,7 +211,7 @@ fn render_resolution_simple_(
     local_name: hir::Name,
     import_to_add: Option<LocatedImport>,
     resolution: ScopeDef,
-) -> Builder {
+) -> CompletionItem {
     let _p = profile::span("render_resolution");
     use hir::ModuleDef::*;
 
@@ -292,7 +292,7 @@ fn render_resolution_simple_(
     if let Some(import_to_add) = ctx.import_to_add {
         item.add_import(import_to_add);
     }
-    item
+    item.build()
 }
 
 fn scope_def_docs(db: &RootDatabase, resolution: ScopeDef) -> Option<hir::Documentation> {
@@ -625,7 +625,6 @@ fn main() { let _: m::Spam = S$0 }
                             ),
                             is_local: false,
                             is_item_from_trait: false,
-                            is_name_already_imported: false,
                             is_op_method: false,
                             is_private_editable: false,
                             postfix_match: None,
@@ -649,7 +648,6 @@ fn main() { let _: m::Spam = S$0 }
                             ),
                             is_local: false,
                             is_item_from_trait: false,
-                            is_name_already_imported: false,
                             is_op_method: false,
                             is_private_editable: false,
                             postfix_match: None,
@@ -739,7 +737,6 @@ fn foo() { A { the$0 } }
                             ),
                             is_local: false,
                             is_item_from_trait: false,
-                            is_name_already_imported: false,
                             is_op_method: false,
                             is_private_editable: false,
                             postfix_match: None,
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs
index 38520e1832..211aa432c7 100644
--- a/crates/ide_completion/src/render/function.rs
+++ b/crates/ide_completion/src/render/function.rs
@@ -22,7 +22,7 @@ pub(crate) fn render_fn(
     ctx: RenderContext<'_>,
     local_name: Option<hir::Name>,
     func: hir::Function,
-) -> Builder {
+) -> CompletionItem {
     let _p = profile::span("render_fn");
     render(ctx, local_name, func, FuncKind::Function)
 }
@@ -32,7 +32,7 @@ pub(crate) fn render_method(
     receiver: Option<hir::Name>,
     local_name: Option<hir::Name>,
     func: hir::Function,
-) -> Builder {
+) -> CompletionItem {
     let _p = profile::span("render_method");
     render(ctx, local_name, func, FuncKind::Method(receiver))
 }
@@ -42,7 +42,7 @@ fn render(
     local_name: Option<hir::Name>,
     func: hir::Function,
     func_kind: FuncKind,
-) -> Builder {
+) -> CompletionItem {
     let db = completion.db;
 
     let name = local_name.unwrap_or_else(|| func.name(db));
@@ -107,7 +107,7 @@ fn render(
             }
         }
     }
-    item
+    item.build()
 }
 
 pub(super) fn add_call_parens<'b>(
diff --git a/crates/ide_completion/src/render/literal.rs b/crates/ide_completion/src/render/literal.rs
index f1773137fe..e65631712e 100644
--- a/crates/ide_completion/src/render/literal.rs
+++ b/crates/ide_completion/src/render/literal.rs
@@ -5,7 +5,7 @@ use ide_db::SymbolKind;
 
 use crate::{
     context::{CompletionContext, PathCompletionCtx},
-    item::{Builder, CompletionItem},
+    item::CompletionItem,
     render::{
         compute_ref_match, compute_type_match,
         variant::{
@@ -22,7 +22,7 @@ pub(crate) fn render_variant_lit(
     local_name: Option<hir::Name>,
     variant: hir::Variant,
     path: Option<hir::ModPath>,
-) -> Option<Builder> {
+) -> Option<CompletionItem> {
     let _p = profile::span("render_enum_variant");
     let db = ctx.db();
 
@@ -35,7 +35,7 @@ pub(crate) fn render_struct_literal(
     strukt: hir::Struct,
     path: Option<hir::ModPath>,
     local_name: Option<hir::Name>,
-) -> Option<Builder> {
+) -> Option<CompletionItem> {
     let _p = profile::span("render_struct_literal");
     let db = ctx.db();
 
@@ -48,7 +48,7 @@ fn render(
     thing: Variant,
     name: hir::Name,
     path: Option<hir::ModPath>,
-) -> Option<Builder> {
+) -> Option<CompletionItem> {
     let db = completion.db;
     let kind = thing.kind(db);
     let has_call_parens =
@@ -112,7 +112,7 @@ fn render(
     if let Some(import_to_add) = ctx.import_to_add {
         item.add_import(import_to_add);
     }
-    Some(item)
+    Some(item.build())
 }
 
 #[derive(Clone, Copy)]
diff --git a/crates/ide_completion/src/render/macro_.rs b/crates/ide_completion/src/render/macro_.rs
index ba18e5d216..9f848febeb 100644
--- a/crates/ide_completion/src/render/macro_.rs
+++ b/crates/ide_completion/src/render/macro_.rs
@@ -4,13 +4,13 @@ use hir::{Documentation, HirDisplay};
 use ide_db::SymbolKind;
 use syntax::SmolStr;
 
-use crate::{
-    context::PathKind,
-    item::{Builder, CompletionItem},
-    render::RenderContext,
-};
+use crate::{context::PathKind, item::CompletionItem, render::RenderContext};
 
-pub(crate) fn render_macro(ctx: RenderContext<'_>, name: hir::Name, macro_: hir::Macro) -> Builder {
+pub(crate) fn render_macro(
+    ctx: RenderContext<'_>,
+    name: hir::Name,
+    macro_: hir::Macro,
+) -> CompletionItem {
     let _p = profile::span("render_macro");
     render(ctx, name, macro_)
 }
@@ -19,7 +19,7 @@ fn render(
     ctx @ RenderContext { completion, .. }: RenderContext<'_>,
     name: hir::Name,
     macro_: hir::Macro,
-) -> Builder {
+) -> CompletionItem {
     let source_range = if completion.is_immediately_after_macro_bang() {
         cov_mark::hit!(completes_macro_call_if_cursor_at_bang_token);
         completion.token.parent().map_or_else(|| ctx.source_range(), |it| it.text_range())
@@ -66,7 +66,7 @@ fn render(
         item.add_import(import_to_add);
     }
 
-    item
+    item.build()
 }
 
 fn label(
diff --git a/crates/ide_db/src/rename.rs b/crates/ide_db/src/rename.rs
index 589975406a..13234a817b 100644
--- a/crates/ide_db/src/rename.rs
+++ b/crates/ide_db/src/rename.rs
@@ -178,23 +178,17 @@ fn rename_mod(
     let mut source_change = SourceChange::default();
 
     let InFile { file_id, value: def_source } = module.definition_source(sema.db);
+    let file_id = file_id.original_file(sema.db);
     if let ModuleSource::SourceFile(..) = def_source {
-        let anchor = file_id.original_file(sema.db);
-        // not mod.rs and doesn't has children, rename file only
-        if !module.is_mod_rs(sema.db) && module.children(sema.db).next().is_none() {
-            let path = format!("{}.rs", new_name);
-            let dst = AnchoredPathBuf { anchor, path };
-            source_change.push_file_system_edit(FileSystemEdit::MoveFile { src: anchor, dst })
-        } else if let Some(mod_name) = module.name(sema.db) {
-            // is mod.rs or has children, rename dir
-            let src = AnchoredPathBuf { anchor, path: mod_name.to_string() };
-            let dst = AnchoredPathBuf { anchor, path: new_name.to_string() };
-            source_change.push_file_system_edit(FileSystemEdit::MoveDir {
-                src,
-                src_id: anchor,
-                dst,
-            })
-        }
+        // mod is defined in path/to/dir/mod.rs
+        let path = if module.is_mod_rs(sema.db) {
+            format!("../{}/mod.rs", new_name)
+        } else {
+            format!("{}.rs", new_name)
+        };
+        let dst = AnchoredPathBuf { anchor: file_id, path };
+        let move_file = FileSystemEdit::MoveFile { src: file_id, dst };
+        source_change.push_file_system_edit(move_file);
     }
 
     if let Some(src) = module.declaration_source(sema.db) {
diff --git a/crates/ide_db/src/source_change.rs b/crates/ide_db/src/source_change.rs
index 8132c73ef2..aa910eb325 100644
--- a/crates/ide_db/src/source_change.rs
+++ b/crates/ide_db/src/source_change.rs
@@ -85,7 +85,6 @@ impl From<FxHashMap<FileId, TextEdit>> for SourceChange {
 pub enum FileSystemEdit {
     CreateFile { dst: AnchoredPathBuf, initial_contents: String },
     MoveFile { src: FileId, dst: AnchoredPathBuf },
-    MoveDir { src: AnchoredPathBuf, src_id: FileId, dst: AnchoredPathBuf },
 }
 
 impl From<FileSystemEdit> for SourceChange {
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 3d83f090e2..0588f00678 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -866,20 +866,6 @@ pub(crate) fn snippet_text_document_ops(
                 rename_file,
             )))
         }
-        FileSystemEdit::MoveDir { src, src_id, dst } => {
-            let old_uri = snap.anchored_path(&src);
-            let new_uri = snap.anchored_path(&dst);
-            let mut rename_file =
-                lsp_types::RenameFile { old_uri, new_uri, options: None, annotation_id: None };
-            if snap.analysis.is_library_file(src_id).ok() == Some(true)
-                && snap.config.change_annotation_support()
-            {
-                rename_file.annotation_id = Some(outside_workspace_annotation_id())
-            }
-            ops.push(lsp_ext::SnippetDocumentChangeOperation::Op(lsp_types::ResourceOp::Rename(
-                rename_file,
-            )))
-        }
     }
     Ok(ops)
 }


Test patch:
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs
index b3a0bd2773..09260c12ed 100644
--- a/crates/ide_assists/src/tests.rs
+++ b/crates/ide_assists/src/tests.rs
@@ -162,10 +162,6 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
                     FileSystemEdit::MoveFile { src, dst } => {
                         (dst, db.file_text(src).as_ref().to_owned())
                     }
-                    FileSystemEdit::MoveDir { src, src_id, dst } => {
-                        // temporary placeholder for MoveDir since we are not using MoveDir in ide assists yet.
-                        (dst, format!("{:?}\n{:?}", src_id, src))
-                    }
                 };
                 let sr = db.file_source_root(dst.anchor);
                 let sr = db.source_root(sr);