Repository: rust-lang/rust-analyzer
Pull request #12678 (2022-07-02 14:15:27)

fix: Trigger flyimport completions in item lists again
Fixes https://github.com/rust-lang/rust-analyzer/issues/12656

Veykril: @bors r+
bors: :pushpin: Commit 915a006e2b32834d780306ebd4a2d19f1eaa3d69 has been approved by `Veykril`

<!-- @bors r=Veykril 915a006e2b32834d780306ebd4a2d19f1eaa3d69 -->
<!-- homu: {"type":"Approved","sha":"915a006e2b32834d780306ebd4a2d19f1eaa3d69","approver":"Veykril"} -->
bors: :hourglass: Testing commit 915a006e2b32834d780306ebd4a2d19f1eaa3d69 with merge cc704ea5a333272db5c16ef22bb72fc4ffc1bb87...
<!-- homu: {"type":"BuildStarted","head_sha":"915a006e2b32834d780306ebd4a2d19f1eaa3d69","merge_sha":"cc704ea5a333272db5c16ef22bb72fc4ffc1bb87"} -->

Patch:
diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs
index 8e8b5c322f..12bfbbe308 100644
--- a/crates/hir-def/src/data.rs
+++ b/crates/hir-def/src/data.rs
@@ -2,7 +2,7 @@
 
 use std::{mem, sync::Arc};
 
-use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroDefKind};
+use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId};
 use syntax::ast;
 
 use crate::{
@@ -498,17 +498,6 @@ impl<'a> AssocItemCollector<'a> {
                     if !self.db.enable_proc_attr_macros() {
                         continue 'attrs;
                     }
-                    let loc = self.db.lookup_intern_macro_call(call_id);
-                    if let MacroDefKind::ProcMacro(exp, ..) = loc.def.kind {
-                        // If there's no expander for the proc macro (e.g. the
-                        // proc macro is ignored, or building the proc macro
-                        // crate failed), skip expansion like we would if it was
-                        // disabled. This is analogous to the handling in
-                        // `DefCollector::collect_macros`.
-                        if exp.is_dummy() {
-                            continue 'attrs;
-                        }
-                    }
                     match self.expander.enter_expand_id(self.db, call_id) {
                         ExpandResult { value: Some((mark, mac)), .. } => {
                             self.collect_macro_items(mark, mac);
diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs
index af59733b9f..d38e4a52a8 100644
--- a/crates/hir-expand/src/mod_path.rs
+++ b/crates/hir-expand/src/mod_path.rs
@@ -20,9 +20,6 @@ pub struct ModPath {
     segments: Vec<Name>,
 }
 
-#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub struct EscapedModPath<'a>(&'a ModPath);
-
 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
 pub enum PathKind {
     Plain,
@@ -100,12 +97,10 @@ impl ModPath {
             _ => None,
         }
     }
+}
 
-    pub fn escaped(&self) -> EscapedModPath {
-        EscapedModPath(self)
-    }
-
-    fn _fmt(&self, f: &mut fmt::Formatter<'_>, escaped: bool) -> fmt::Result {
+impl Display for ModPath {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         let mut first_segment = true;
         let mut add_segment = |s| -> fmt::Result {
             if !first_segment {
@@ -132,28 +127,12 @@ impl ModPath {
                 f.write_str("::")?;
             }
             first_segment = false;
-            if escaped {
-                segment.escaped().fmt(f)?
-            } else {
-                segment.fmt(f)?
-            };
+            segment.fmt(f)?;
         }
         Ok(())
     }
 }
 
-impl Display for ModPath {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        self._fmt(f, false)
-    }
-}
-
-impl<'a> Display for EscapedModPath<'a> {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        self.0._fmt(f, true)
-    }
-}
-
 impl From<Name> for ModPath {
     fn from(name: Name) -> ModPath {
         ModPath::from_segments(PathKind::Plain, iter::once(name))
diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs
index 6b48258f37..f1bf665707 100644
--- a/crates/hir-expand/src/name.rs
+++ b/crates/hir-expand/src/name.rs
@@ -2,7 +2,7 @@
 
 use std::fmt;
 
-use syntax::{ast, SmolStr, SyntaxKind};
+use syntax::{ast, SmolStr};
 
 /// `Name` is a wrapper around string, which is used in hir for both references
 /// and declarations. In theory, names should also carry hygiene info, but we are
@@ -10,10 +10,6 @@ use syntax::{ast, SmolStr, SyntaxKind};
 #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub struct Name(Repr);
 
-/// `EscapedName` will add a prefix "r#" to the wrapped `Name` when it is a raw identifier
-#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
-pub struct EscapedName<'a>(&'a Name);
-
 #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
 enum Repr {
     Text(SmolStr),
@@ -29,51 +25,6 @@ impl fmt::Display for Name {
     }
 }
 
-fn is_raw_identifier(name: &str) -> bool {
-    let is_keyword = SyntaxKind::from_keyword(name).is_some();
-    is_keyword && !matches!(name, "self" | "crate" | "super" | "Self")
-}
-
-impl<'a> fmt::Display for EscapedName<'a> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match &self.0 .0 {
-            Repr::Text(text) => {
-                if is_raw_identifier(text) {
-                    write!(f, "r#{}", &text)
-                } else {
-                    fmt::Display::fmt(&text, f)
-                }
-            }
-            Repr::TupleField(idx) => fmt::Display::fmt(&idx, f),
-        }
-    }
-}
-
-impl<'a> EscapedName<'a> {
-    pub fn is_escaped(&self) -> bool {
-        match &self.0 .0 {
-            Repr::Text(it) => is_raw_identifier(&it),
-            Repr::TupleField(_) => false,
-        }
-    }
-
-    /// Returns the textual representation of this name as a [`SmolStr`].
-    /// Prefer using this over [`ToString::to_string`] if possible as this conversion is cheaper in
-    /// the general case.
-    pub fn to_smol_str(&self) -> SmolStr {
-        match &self.0 .0 {
-            Repr::Text(it) => {
-                if is_raw_identifier(&it) {
-                    SmolStr::from_iter(["r#", &it])
-                } else {
-                    it.clone()
-                }
-            }
-            Repr::TupleField(it) => SmolStr::new(&it.to_string()),
-        }
-    }
-}
-
 impl Name {
     /// Note: this is private to make creating name from random string hard.
     /// Hopefully, this should allow us to integrate hygiene cleaner in the
@@ -141,10 +92,6 @@ impl Name {
             Repr::TupleField(it) => SmolStr::new(&it.to_string()),
         }
     }
-
-    pub fn escaped(&self) -> EscapedName {
-        EscapedName(self)
-    }
 }
 
 pub trait AsName {
diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs
index fa8c0eb77a..1c62347fb5 100644
--- a/crates/ide-completion/src/completions/flyimport.rs
+++ b/crates/ide-completion/src/completions/flyimport.rs
@@ -5,7 +5,10 @@ use ide_db::imports::{
     insert_use::ImportScope,
 };
 use itertools::Itertools;
-use syntax::{ast, AstNode, SyntaxNode, T};
+use syntax::{
+    ast::{self},
+    AstNode, SyntaxNode, T,
+};
 
 use crate::{
     context::{
@@ -123,6 +126,7 @@ pub(crate) fn import_on_the_fly_path(
                 | PathKind::Type { .. }
                 | PathKind::Attr { .. }
                 | PathKind::Derive { .. }
+                | PathKind::Item { .. }
                 | PathKind::Pat { .. },
             qualified,
             ..
@@ -161,7 +165,7 @@ pub(crate) fn import_on_the_fly_pat(
     let potential_import_name = import_name(ctx);
     let import_assets = import_assets_for_path(ctx, &potential_import_name, None)?;
 
-    import_on_the_fly_pat2(
+    import_on_the_fly_pat_(
         acc,
         ctx,
         pattern_ctx,
@@ -227,7 +231,7 @@ fn import_on_the_fly(
                 | PathKind::Pat { .. },
                 ItemInNs::Macros(mac),
             ) => mac.is_fn_like(ctx.db),
-            (PathKind::Item { .. }, _) => true,
+            (PathKind::Item { .. }, ..) => false,
 
             (PathKind::Expr { .. }, ItemInNs::Types(_) | ItemInNs::Values(_)) => true,
 
@@ -279,7 +283,7 @@ fn import_on_the_fly(
     Some(())
 }
 
-fn import_on_the_fly_pat2(
+fn import_on_the_fly_pat_(
     acc: &mut Completions,
     ctx: &CompletionContext,
     pattern_ctx: &PatternContext,
diff --git a/crates/ide-completion/src/completions/item_list/trait_impl.rs b/crates/ide-completion/src/completions/item_list/trait_impl.rs
index 3872053f2c..972a7d2f21 100644
--- a/crates/ide-completion/src/completions/item_list/trait_impl.rs
+++ b/crates/ide-completion/src/completions/item_list/trait_impl.rs
@@ -232,11 +232,10 @@ fn add_type_alias_impl(
     replacement_range: TextRange,
     type_alias: hir::TypeAlias,
 ) {
-    let alias_name = type_alias.name(ctx.db);
-    let (alias_name, escaped_name) = (alias_name.to_smol_str(), alias_name.escaped().to_smol_str());
+    let alias_name = type_alias.name(ctx.db).to_smol_str();
 
     let label = format!("type {} =", alias_name);
-    let replacement = format!("type {} = ", escaped_name);
+    let replacement = format!("type {} = ", alias_name);
 
     let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
     item.lookup_by(format!("type {}", alias_name))
diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs
index 005ab3a895..6571e67352 100644
--- a/crates/ide-completion/src/render.rs
+++ b/crates/ide-completion/src/render.rs
@@ -116,8 +116,7 @@ pub(crate) fn render_field(
     ty: &hir::Type,
 ) -> CompletionItem {
     let is_deprecated = ctx.is_deprecated(field);
-    let name = field.name(ctx.db());
-    let (name, escaped_name) = (name.to_smol_str(), name.escaped().to_smol_str());
+    let name = field.name(ctx.db()).to_smol_str();
     let mut item = CompletionItem::new(
         SymbolKind::Field,
         ctx.source_range(),
@@ -132,7 +131,10 @@ pub(crate) fn render_field(
         .set_documentation(field.docs(ctx.db()))
         .set_deprecated(is_deprecated)
         .lookup_by(name.clone());
-    item.insert_text(escaped_name);
+    let is_keyword = SyntaxKind::from_keyword(name.as_str()).is_some();
+    if is_keyword && !matches!(name.as_str(), "self" | "crate" | "super" | "Self") {
+        item.insert_text(format!("r#{}", name));
+    }
     if let Some(receiver) = &dot_access.receiver {
         if let Some(ref_match) = compute_ref_match(ctx.completion, ty) {
             item.ref_match(ref_match, receiver.syntax().text_range().start());
@@ -233,7 +235,7 @@ fn render_resolution_pat(
         _ => (),
     }
 
-    render_resolution_simple_(ctx, &local_name, import_to_add, resolution)
+    render_resolution_simple_(ctx, local_name, import_to_add, resolution)
 }
 
 fn render_resolution_path(
@@ -272,10 +274,7 @@ fn render_resolution_path(
     let config = completion.config;
 
     let name = local_name.to_smol_str();
-    let mut item = render_resolution_simple_(ctx, &local_name, import_to_add, resolution);
-    if local_name.escaped().is_escaped() {
-        item.insert_text(local_name.escaped().to_smol_str());
-    }
+    let mut item = render_resolution_simple_(ctx, local_name, import_to_add, resolution);
     // Add `<>` for generic types
     let type_path_no_ty_args = matches!(
         path_ctx,
@@ -296,7 +295,7 @@ fn render_resolution_path(
                 item.lookup_by(name.clone())
                     .label(SmolStr::from_iter([&name, "<…>"]))
                     .trigger_call_info()
-                    .insert_snippet(cap, format!("{}<$0>", local_name.escaped()));
+                    .insert_snippet(cap, format!("{}<$0>", name));
             }
         }
     }
@@ -322,7 +321,7 @@ fn render_resolution_path(
 
 fn render_resolution_simple_(
     ctx: RenderContext<'_>,
-    local_name: &hir::Name,
+    local_name: hir::Name,
     import_to_add: Option<LocatedImport>,
     resolution: ScopeDef,
 ) -> Builder {
@@ -1726,149 +1725,4 @@ fn f() {
             "#]],
         );
     }
-
-    #[test]
-    fn completes_struct_with_raw_identifier() {
-        check_edit(
-            "type",
-            r#"
-mod m { pub struct r#type {} }
-fn main() {
-    let r#type = m::t$0;
-}
-"#,
-            r#"
-mod m { pub struct r#type {} }
-fn main() {
-    let r#type = m::r#type;
-}
-"#,
-        )
-    }
-
-    #[test]
-    fn completes_fn_with_raw_identifier() {
-        check_edit(
-            "type",
-            r#"
-mod m { pub fn r#type {} }
-fn main() {
-    m::t$0
-}
-"#,
-            r#"
-mod m { pub fn r#type {} }
-fn main() {
-    m::r#type()$0
-}
-"#,
-        )
-    }
-
-    #[test]
-    fn completes_macro_with_raw_identifier() {
-        check_edit(
-            "let!",
-            r#"
-macro_rules! r#let { () => {} }
-fn main() {
-    $0
-}
-"#,
-            r#"
-macro_rules! r#let { () => {} }
-fn main() {
-    r#let!($0)
-}
-"#,
-        )
-    }
-
-    #[test]
-    fn completes_variant_with_raw_identifier() {
-        check_edit(
-            "type",
-            r#"
-enum A { r#type }
-fn main() {
-    let a = A::t$0
-}
-"#,
-            r#"
-enum A { r#type }
-fn main() {
-    let a = A::r#type$0
-}
-"#,
-        )
-    }
-
-    #[test]
-    fn completes_field_with_raw_identifier() {
-        check_edit(
-            "fn",
-            r#"
-mod r#type {
-    pub struct r#struct {
-        pub r#fn: u32
-    }
-}
-
-fn main() {
-    let a = r#type::r#struct {};
-    a.$0
-}
-"#,
-            r#"
-mod r#type {
-    pub struct r#struct {
-        pub r#fn: u32
-    }
-}
-
-fn main() {
-    let a = r#type::r#struct {};
-    a.r#fn
-}
-"#,
-        )
-    }
-
-    #[test]
-    fn completes_const_with_raw_identifier() {
-        check_edit(
-            "type",
-            r#"
-struct r#struct {}
-impl r#struct { pub const r#type: u8 = 1; }
-fn main() {
-    r#struct::t$0
-}
-"#,
-            r#"
-struct r#struct {}
-impl r#struct { pub const r#type: u8 = 1; }
-fn main() {
-    r#struct::r#type
-}
-"#,
-        )
-    }
-
-    #[test]
-    fn completes_type_alias_with_raw_identifier() {
-        check_edit(
-            "type type",
-            r#"
-struct r#struct {}
-trait r#trait { type r#type; }
-impl r#trait for r#struct { type t$0 }
-"#,
-            r#"
-struct r#struct {}
-trait r#trait { type r#type; }
-impl r#trait for r#struct { type r#type = $0; }
-"#,
-        )
-    }
 }
diff --git a/crates/ide-completion/src/render/const_.rs b/crates/ide-completion/src/render/const_.rs
index a810eef18d..89e6c82dde 100644
--- a/crates/ide-completion/src/render/const_.rs
+++ b/crates/ide-completion/src/render/const_.rs
@@ -12,8 +12,7 @@ pub(crate) fn render_const(ctx: RenderContext<'_>, const_: hir::Const) -> Option
 
 fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem> {
     let db = ctx.db();
-    let name = const_.name(db)?;
-    let (name, escaped_name) = (name.to_smol_str(), name.escaped().to_smol_str());
+    let name = const_.name(db)?.to_smol_str();
     let detail = const_.display(db).to_string();
 
     let mut item = CompletionItem::new(SymbolKind::Const, ctx.source_range(), name.clone());
@@ -25,9 +24,9 @@ fn render(ctx: RenderContext<'_>, const_: hir::Const) -> Option<CompletionItem>
     if let Some(actm) = const_.as_assoc_item(db) {
         if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
             item.trait_name(trt.name(db).to_smol_str());
+            item.insert_text(name);
         }
     }
-    item.insert_text(escaped_name);
 
     Some(item.build())
 }
diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs
index 4a8a5d5c77..37486e4d93 100644
--- a/crates/ide-completion/src/render/function.rs
+++ b/crates/ide-completion/src/render/function.rs
@@ -50,12 +50,9 @@ fn render(
 
     let name = local_name.unwrap_or_else(|| func.name(db));
 
-    let (call, escaped_call) = match &func_kind {
-        FuncKind::Method(_, Some(receiver)) => (
-            format!("{}.{}", receiver, &name).into(),
-            format!("{}.{}", receiver.escaped(), name.escaped()).into(),
-        ),
-        _ => (name.to_smol_str(), name.escaped().to_smol_str()),
+    let call = match &func_kind {
+        FuncKind::Method(_, Some(receiver)) => format!("{}.{}", receiver, &name).into(),
+        _ => name.to_smol_str(),
     };
     let mut item = CompletionItem::new(
         if func.self_param(db).is_some() {
@@ -118,15 +115,7 @@ fn render(
                 if let Some((self_param, params)) =
                     params(ctx.completion, func, &func_kind, has_dot_receiver)
                 {
-                    add_call_parens(
-                        &mut item,
-                        completion,
-                        cap,
-                        call,
-                        escaped_call,
-                        self_param,
-                        params,
-                    );
+                    add_call_parens(&mut item, completion, cap, call, self_param, params);
                 }
             }
         }
@@ -153,14 +142,13 @@ pub(super) fn add_call_parens<'b>(
     ctx: &CompletionContext,
     cap: SnippetCap,
     name: SmolStr,
-    escaped_name: SmolStr,
     self_param: Option<hir::SelfParam>,
     params: Vec<hir::Param>,
 ) -> &'b mut Builder {
     cov_mark::hit!(inserts_parens_for_function_calls);
 
     let (snippet, label_suffix) = if self_param.is_none() && params.is_empty() {
-        (format!("{}()$0", escaped_name), "()")
+        (format!("{}()$0", name), "()")
     } else {
         builder.trigger_call_info();
         let snippet = if let Some(CallableSnippets::FillArguments) = ctx.config.callable {
@@ -191,19 +179,19 @@ pub(super) fn add_call_parens<'b>(
                 Some(self_param) => {
                     format!(
                         "{}(${{1:{}}}{}{})$0",
-                        escaped_name,
+                        name,
                         self_param.display(ctx.db),
                         if params.is_empty() { "" } else { ", " },
                         function_params_snippet
                     )
                 }
                 None => {
-                    format!("{}({})$0", escaped_name, function_params_snippet)
+                    format!("{}({})$0", name, function_params_snippet)
                 }
             }
         } else {
             cov_mark::hit!(suppress_arg_snippets);
-            format!("{}($0)", escaped_name)
+            format!("{}($0)", name)
         };
 
         (snippet, "(…)")
diff --git a/crates/ide-completion/src/render/literal.rs b/crates/ide-completion/src/render/literal.rs
index df80fb2fa6..7b0555d5a4 100644
--- a/crates/ide-completion/src/render/literal.rs
+++ b/crates/ide-completion/src/render/literal.rs
@@ -72,21 +72,17 @@ fn render(
         }
         None => (name.clone().into(), name.into(), false),
     };
-    let (qualified_name, escaped_qualified_name) =
-        (qualified_name.to_string(), qualified_name.escaped().to_string());
+    let qualified_name = qualified_name.to_string();
     let snippet_cap = ctx.snippet_cap();
 
     let mut rendered = match kind {
         StructKind::Tuple if should_add_parens => {
-            render_tuple_lit(db, snippet_cap, &fields, &escaped_qualified_name)
+            render_tuple_lit(db, snippet_cap, &fields, &qualified_name)
         }
         StructKind::Record if should_add_parens => {
-            render_record_lit(db, snippet_cap, &fields, &escaped_qualified_name)
+            render_record_lit(db, snippet_cap, &fields, &qualified_name)
         }
-        _ => RenderedLiteral {
-            literal: escaped_qualified_name.clone(),
-            detail: escaped_qualified_name.clone(),
-        },
+        _ => RenderedLiteral { literal: qualified_name.clone(), detail: qualified_name.clone() },
     };
 
     if snippet_cap.is_some() {
diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs
index ebf8a98eb0..ac2091eca9 100644
--- a/crates/ide-completion/src/render/macro_.rs
+++ b/crates/ide-completion/src/render/macro_.rs
@@ -46,7 +46,7 @@ fn render(
         ctx.source_range()
     };
 
-    let (name, escaped_name) = (name.to_smol_str(), name.escaped().to_smol_str());
+    let name = name.to_smol_str();
     let docs = ctx.docs(macro_);
     let docs_str = docs.as_ref().map(Documentation::as_str).unwrap_or_default();
     let is_fn_like = macro_.is_fn_like(completion.db);
@@ -64,18 +64,20 @@ fn render(
         .set_documentation(docs)
         .set_relevance(ctx.completion_relevance());
 
+    let name = &*name;
     match ctx.snippet_cap() {
         Some(cap) if needs_bang && !has_call_parens => {
-            let snippet = format!("{}!{}$0{}", escaped_name, bra, ket);
-            let lookup = banged_name(&name);
+            let snippet = format!("{}!{}$0{}", name, bra, ket);
+            let lookup = banged_name(name);
             item.insert_snippet(cap, snippet).lookup_by(lookup);
         }
         _ if needs_bang => {
-            item.insert_text(banged_name(&escaped_name)).lookup_by(banged_name(&name));
+            let banged_name = banged_name(name);
+            item.insert_text(banged_name.clone()).lookup_by(banged_name);
         }
         _ => {
             cov_mark::hit!(dont_insert_macro_call_parens_unncessary);
-            item.insert_text(escaped_name);
+            item.insert_text(name);
         }
     };
     if let Some(import_to_add) = ctx.import_to_add {
diff --git a/crates/ide-completion/src/render/pattern.rs b/crates/ide-completion/src/render/pattern.rs
index f9c4037dee..463d292955 100644
--- a/crates/ide-completion/src/render/pattern.rs
+++ b/crates/ide-completion/src/render/pattern.rs
@@ -27,12 +27,11 @@ pub(crate) fn render_struct_pat(
         return None;
     }
 
-    let name = local_name.unwrap_or_else(|| strukt.name(ctx.db()));
-    let (name, escaped_name) = (name.to_smol_str(), name.escaped().to_smol_str());
+    let name = local_name.unwrap_or_else(|| strukt.name(ctx.db())).to_smol_str();
     let pat = render_pat(
         &ctx,
         pattern_ctx,
-        &escaped_name,
+        &name,
         strukt.kind(ctx.db()),
         &visible_fields,
         fields_omitted,
@@ -53,17 +52,14 @@ pub(crate) fn render_variant_pat(
     let fields = variant.fields(ctx.db());
     let (visible_fields, fields_omitted) = visible_fields(ctx.completion, &fields, variant)?;
 
-    let (name, escaped_name) = match path {
-        Some(path) => (path.to_string().into(), path.escaped().to_string().into()),
-        None => {
-            let name = local_name.unwrap_or_else(|| variant.name(ctx.db()));
-            (name.to_smol_str(), name.escaped().to_smol_str())
-        }
+    let name = match path {
+        Some(path) => path.to_string().into(),
+        None => local_name.unwrap_or_else(|| variant.name(ctx.db())).to_smol_str(),
     };
     let pat = render_pat(
         &ctx,
         pattern_ctx,
-        &escaped_name,
+        &name,
         variant.kind(ctx.db()),
         &visible_fields,
         fields_omitted,
diff --git a/crates/ide-completion/src/render/type_alias.rs b/crates/ide-completion/src/render/type_alias.rs
index f1b23c76e7..a518be87bf 100644
--- a/crates/ide-completion/src/render/type_alias.rs
+++ b/crates/ide-completion/src/render/type_alias.rs
@@ -29,14 +29,10 @@ fn render(
 ) -> Option<CompletionItem> {
     let db = ctx.db();
 
-    let name = type_alias.name(db);
-    let (name, escaped_name) = if with_eq {
-        (
-            SmolStr::from_iter([&name.to_smol_str(), " = "]),
-            SmolStr::from_iter([&name.escaped().to_smol_str(), " = "]),
-        )
+    let name = if with_eq {
+        SmolStr::from_iter([&*type_alias.name(db).to_smol_str(), " = "])
     } else {
-        (name.to_smol_str(), name.escaped().to_smol_str())
+        type_alias.name(db).to_smol_str()
     };
     let detail = type_alias.display(db).to_string();
 
@@ -49,9 +45,9 @@ fn render(
     if let Some(actm) = type_alias.as_assoc_item(db) {
         if let Some(trt) = actm.containing_trait_or_trait_impl(db) {
             item.trait_name(trt.name(db).to_smol_str());
+            item.insert_text(name);
         }
     }
-    item.insert_text(escaped_name);
 
     Some(item.build())
 }
diff --git a/crates/ide-completion/src/render/union_literal.rs b/crates/ide-completion/src/render/union_literal.rs
index fc35381256..aafedaf5aa 100644
--- a/crates/ide-completion/src/render/union_literal.rs
+++ b/crates/ide-completion/src/render/union_literal.rs
@@ -18,17 +18,17 @@ pub(crate) fn render_union_literal(
     path: Option<hir::ModPath>,
     local_name: Option<Name>,
 ) -> Option<CompletionItem> {
-    let name = local_name.unwrap_or_else(|| un.name(ctx.db()));
+    let name = local_name.unwrap_or_else(|| un.name(ctx.db())).to_smol_str();
 
-    let (qualified_name, escaped_qualified_name) = match path {
-        Some(p) => (p.to_string(), p.escaped().to_string()),
-        None => (name.to_string(), name.escaped().to_string()),
+    let qualified_name = match path {
+        Some(p) => p.to_string(),
+        None => name.to_string(),
     };
 
     let mut item = CompletionItem::new(
         CompletionItemKind::SymbolKind(SymbolKind::Union),
         ctx.source_range(),
-        format_literal_label(&name.to_smol_str(), StructKind::Record),
+        format_literal_label(&name, StructKind::Record),
     );
 
     let fields = un.fields(ctx.db());
@@ -41,16 +41,16 @@ pub(crate) fn render_union_literal(
     let literal = if ctx.snippet_cap().is_some() {
         format!(
             "{} {{ ${{1|{}|}}: ${{2:()}} }}$0",
-            escaped_qualified_name,
-            fields.iter().map(|field| field.name(ctx.db()).escaped().to_smol_str()).format(",")
+            qualified_name,
+            fields.iter().map(|field| field.name(ctx.db())).format(",")
         )
     } else {
         format!(
             "{} {{ {} }}",
-            escaped_qualified_name,
-            fields.iter().format_with(", ", |field, f| {
-                f(&format_args!("{}: ()", field.name(ctx.db()).escaped()))
-            })
+            qualified_name,
+            fields
+                .iter()
+                .format_with(", ", |field, f| { f(&format_args!("{}: ()", field.name(ctx.db()))) })
         )
     };
 
diff --git a/crates/ide-completion/src/render/variant.rs b/crates/ide-completion/src/render/variant.rs
index 440b9d14ca..2c9fb9b35a 100644
--- a/crates/ide-completion/src/render/variant.rs
+++ b/crates/ide-completion/src/render/variant.rs
@@ -24,9 +24,9 @@ pub(crate) fn render_record_lit(
 ) -> RenderedLiteral {
     let completions = fields.iter().enumerate().format_with(", ", |(idx, field), f| {
         if snippet_cap.is_some() {
-            f(&format_args!("{}: ${{{}:()}}", field.name(db).escaped(), idx + 1))
+            f(&format_args!("{}: ${{{}:()}}", field.name(db), idx + 1))
         } else {
-            f(&format_args!("{}: ()", field.name(db).escaped()))
+            f(&format_args!("{}: ()", field.name(db)))
         }
     });
 
diff --git a/crates/ide-diagnostics/src/handlers/inactive_code.rs b/crates/ide-diagnostics/src/handlers/inactive_code.rs
index 97ea5c456a..17243d612a 100644
--- a/crates/ide-diagnostics/src/handlers/inactive_code.rs
+++ b/crates/ide-diagnostics/src/handlers/inactive_code.rs
@@ -104,25 +104,6 @@ fn f() {
         );
     }
 
-    #[test]
-    fn inactive_assoc_item() {
-        // FIXME these currently don't work, hence the *
-        check(
-            r#"
-struct Foo;
-impl Foo {
-    #[cfg(any())] pub fn f() {}
-  //*************************** weak: code is inactive due to #[cfg] directives
-}
-
-trait Bar {
-    #[cfg(any())] pub fn f() {}
-  //*************************** weak: code is inactive due to #[cfg] directives
-}
-"#,
-        );
-    }
-
     /// Tests that `cfg` attributes behind `cfg_attr` is handled properly.
     #[test]
     fn inactive_via_cfg_attr() {


Test patch:
diff --git a/crates/hir-ty/src/tests/macros.rs b/crates/hir-ty/src/tests/macros.rs
index a1ab6060e7..a4299d9f05 100644
--- a/crates/hir-ty/src/tests/macros.rs
+++ b/crates/hir-ty/src/tests/macros.rs
@@ -1274,65 +1274,3 @@ impl S {
         "#]],
     );
 }
-
-#[test]
-fn infer_in_unexpandable_attr_proc_macro_1() {
-    check_types(
-        r#"
-//- /main.rs crate:main deps:mac
-#[mac::attr_macro]
-fn foo() {
-    let xxx = 1;
-      //^^^ i32
-}
-
-//- /mac.rs crate:mac
-#![crate_type="proc-macro"]
-#[proc_macro_attribute]
-pub fn attr_macro() {}
-"#,
-    );
-}
-
-#[test]
-fn infer_in_unexpandable_attr_proc_macro_in_impl() {
-    check_types(
-        r#"
-//- /main.rs crate:main deps:mac
-struct Foo;
-impl Foo {
-    #[mac::attr_macro]
-    fn foo() {
-        let xxx = 1;
-          //^^^ i32
-    }
-}
-
-//- /mac.rs crate:mac
-#![crate_type="proc-macro"]
-#[proc_macro_attribute]
-pub fn attr_macro() {}
-"#,
-    );
-}
-
-#[test]
-fn infer_in_unexpandable_attr_proc_macro_in_trait() {
-    check_types(
-        r#"
-//- /main.rs crate:main deps:mac
-trait Foo {
-    #[mac::attr_macro]
-    fn foo() {
-        let xxx = 1;
-          //^^^ i32
-    }
-}
-
-//- /mac.rs crate:mac
-#![crate_type="proc-macro"]
-#[proc_macro_attribute]
-pub fn attr_macro() {}
-"#,
-    );
-}
diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs
index c393e16e7a..0bba7f2459 100644
--- a/crates/ide-completion/src/tests/flyimport.rs
+++ b/crates/ide-completion/src/tests/flyimport.rs
@@ -1210,3 +1210,23 @@ fn f<T>() where T: Comp$0
         "#]],
     );
 }
+
+#[test]
+fn flyimport_source_file() {
+    check(
+        r#"
+//- /main.rs crate:main deps:dep
+def$0
+//- /lib.rs crate:dep
+#[macro_export]
+macro_rules! define_struct {
+    () => {
+        pub struct Foo;
+    };
+}
+"#,
+        expect![[r#"
+            ma define_struct!(…) (use dep::define_struct) macro_rules! define_struct
+        "#]],
+    );
+}