diff --git a/crates/hir-def/src/data/adt.rs b/crates/hir-def/src/data/adt.rs index 5790e600f63c8..a7461b78af1ce 100644 --- a/crates/hir-def/src/data/adt.rs +++ b/crates/hir-def/src/data/adt.rs @@ -191,9 +191,9 @@ impl StructData { let krate = loc.container.krate; let item_tree = loc.id.item_tree(db); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); - let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); + let cfg_options = db.crate_graph()[krate].cfg_options.clone(); - let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()); + let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()); let mut flags = StructFlags::NO_FLAGS; if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() { @@ -248,9 +248,9 @@ impl StructData { let krate = loc.container.krate; let item_tree = loc.id.item_tree(db); let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); - let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone(); + let cfg_options = db.crate_graph()[krate].cfg_options.clone(); - let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into()); + let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()); let mut flags = StructFlags::NO_FLAGS; if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() { flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL; diff --git a/crates/hir-def/src/db.rs b/crates/hir-def/src/db.rs index e0918d6850241..d3f436be0b44d 100644 --- a/crates/hir-def/src/db.rs +++ b/crates/hir-def/src/db.rs @@ -298,7 +298,6 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { } }; - // FIXME: The def site spans here are wrong, those should point to the name, not the whole ast node match id { MacroId::Macro2Id(it) => { let loc: Macro2Loc = it.lookup(db); @@ -310,9 +309,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()), local_inner: false, allow_internal_unsafe: loc.allow_internal_unsafe, - span: db - .span_map(loc.id.file_id()) - .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), + span: makro.def_site, edition: loc.edition, } } @@ -328,9 +325,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { allow_internal_unsafe: loc .flags .contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE), - span: db - .span_map(loc.id.file_id()) - .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), + span: makro.def_site, edition: loc.edition, } } @@ -348,6 +343,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId { ), local_inner: false, allow_internal_unsafe: false, + // FIXME: This is wrong, this should point to the name span: db .span_map(loc.id.file_id()) .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), diff --git a/crates/hir-def/src/item_tree.rs b/crates/hir-def/src/item_tree.rs index bd3d377ec083a..6450e3a2558c9 100644 --- a/crates/hir-def/src/item_tree.rs +++ b/crates/hir-def/src/item_tree.rs @@ -790,7 +790,6 @@ pub struct MacroCall { pub path: Interned, pub ast_id: FileAstId, pub expand_to: ExpandTo, - // FIXME: We need to move this out. It invalidates the item tree when typing inside the macro call. pub call_site: Span, } @@ -799,6 +798,7 @@ pub struct MacroRules { /// The name of the declared macro. pub name: Name, pub ast_id: FileAstId, + pub def_site: Span, } /// "Macros 2.0" macro definition. @@ -807,6 +807,7 @@ pub struct Macro2 { pub name: Name, pub visibility: RawVisibilityId, pub ast_id: FileAstId, + pub def_site: Span, } impl Use { diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index 686cab58ae960..a1755b110edb6 100644 --- a/crates/hir-def/src/item_tree/lower.rs +++ b/crates/hir-def/src/item_tree/lower.rs @@ -572,20 +572,22 @@ impl<'a> Ctx<'a> { } fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option> { - let name = m.name().map(|it| it.as_name())?; + let name = m.name()?; + let def_site = self.span_map().span_for_range(name.syntax().text_range()); let ast_id = self.source_ast_id_map.ast_id(m); - let res = MacroRules { name, ast_id }; + let res = MacroRules { name: name.as_name(), ast_id, def_site }; Some(id(self.data().macro_rules.alloc(res))) } fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option> { - let name = m.name().map(|it| it.as_name())?; + let name = m.name()?; + let def_site = self.span_map().span_for_range(name.syntax().text_range()); let ast_id = self.source_ast_id_map.ast_id(m); let visibility = self.lower_visibility(m); - let res = Macro2 { name, ast_id, visibility }; + let res = Macro2 { name: name.as_name(), ast_id, visibility, def_site }; Some(id(self.data().macro_defs.alloc(res))) } diff --git a/crates/hir-def/src/item_tree/pretty.rs b/crates/hir-def/src/item_tree/pretty.rs index 87c90a4c6ab94..7d5fdf056b060 100644 --- a/crates/hir-def/src/item_tree/pretty.rs +++ b/crates/hir-def/src/item_tree/pretty.rs @@ -498,13 +498,23 @@ impl Printer<'_> { wln!(self, "{}!(...);", path.display(self.db.upcast())); } ModItem::MacroRules(it) => { - let MacroRules { name, ast_id } = &self.tree[it]; - self.print_ast_id(ast_id.erase()); + let MacroRules { name, ast_id, def_site } = &self.tree[it]; + let _ = writeln!( + self, + "// AstId: {:?}, Span: {}", + ast_id.erase().into_raw(), + def_site, + ); wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast())); } ModItem::Macro2(it) => { - let Macro2 { name, visibility, ast_id } = &self.tree[it]; - self.print_ast_id(ast_id.erase()); + let Macro2 { name, visibility, ast_id, def_site } = &self.tree[it]; + let _ = writeln!( + self, + "// AstId: {:?}, Span: {}", + ast_id.erase().into_raw(), + def_site, + ); self.print_visibility(*visibility); wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast())); } diff --git a/crates/hir-def/src/item_tree/tests.rs b/crates/hir-def/src/item_tree/tests.rs index b294d288ac94d..0c11f34841c02 100644 --- a/crates/hir-def/src/item_tree/tests.rs +++ b/crates/hir-def/src/item_tree/tests.rs @@ -272,10 +272,10 @@ pub macro m2() {} m!(); "#, expect![[r#" - // AstId: 1 + // AstId: 1, Span: 0:1@13..14#0 macro_rules! m { ... } - // AstId: 2 + // AstId: 2, Span: 0:2@10..12#0 pub macro m2 { ... } // AstId: 3, Span: 0:3@0..1#0, ExpandTo: Items diff --git a/crates/hir-expand/src/quote.rs b/crates/hir-expand/src/quote.rs index 40a34385b2adf..a31a111c91174 100644 --- a/crates/hir-expand/src/quote.rs +++ b/crates/hir-expand/src/quote.rs @@ -269,7 +269,8 @@ mod tests { let t = format!("{quoted:#?}"); expect![[r#" SUBTREE $$ 937550:0@0..0#0 937550:0@0..0#0 - IDENT hello 937550:0@0..0#0"#]].assert_eq(&t); + IDENT hello 937550:0@0..0#0"#]] + .assert_eq(&t); } #[test] diff --git a/crates/ide-completion/src/lib.rs b/crates/ide-completion/src/lib.rs index 93265b74246e1..d89cfc8b6cb83 100644 --- a/crates/ide-completion/src/lib.rs +++ b/crates/ide-completion/src/lib.rs @@ -207,7 +207,7 @@ pub fn completions( CompletionAnalysis::String { original, expanded: Some(expanded) } => { completions::extern_abi::complete_extern_abi(acc, ctx, expanded); completions::format_string::format_string(acc, ctx, original, expanded); - completions::env_vars::complete_cargo_env_vars(acc, ctx,original, expanded); + completions::env_vars::complete_cargo_env_vars(acc, ctx, original, expanded); } CompletionAnalysis::UnexpandedAttrTT { colon_prefix, diff --git a/crates/proc-macro-srv/src/tests/mod.rs b/crates/proc-macro-srv/src/tests/mod.rs index 1e4bbf83d5fd9..11b008fc0b4bc 100644 --- a/crates/proc-macro-srv/src/tests/mod.rs +++ b/crates/proc-macro-srv/src/tests/mod.rs @@ -8,7 +8,12 @@ use expect_test::expect; #[test] fn test_derive_empty() { - assert_expand("DeriveEmpty", r#"struct S;"#, expect!["SUBTREE $$ 1 1"], expect!["SUBTREE $$ 42:2@0..100#0 42:2@0..100#0"]); + assert_expand( + "DeriveEmpty", + r#"struct S;"#, + expect!["SUBTREE $$ 1 1"], + expect!["SUBTREE $$ 42:2@0..100#0 42:2@0..100#0"], + ); } #[test] diff --git a/crates/stdx/src/anymap.rs b/crates/stdx/src/anymap.rs index 899cd8ac6bbef..d47b3d1647e93 100644 --- a/crates/stdx/src/anymap.rs +++ b/crates/stdx/src/anymap.rs @@ -194,21 +194,6 @@ impl<'a, A: ?Sized + Downcast, V: IntoBox> VacantEntry<'a, A, V> { mod tests { use super::*; - #[derive(Clone, Debug, PartialEq)] - struct A(i32); - #[derive(Clone, Debug, PartialEq)] - struct B(i32); - #[derive(Clone, Debug, PartialEq)] - struct C(i32); - #[derive(Clone, Debug, PartialEq)] - struct D(i32); - #[derive(Clone, Debug, PartialEq)] - struct E(i32); - #[derive(Clone, Debug, PartialEq)] - struct F(i32); - #[derive(Clone, Debug, PartialEq)] - struct J(i32); - #[test] fn test_varieties() { fn assert_send() {}