Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/tests/incremental.rs')
-rw-r--r--crates/hir-def/src/nameres/tests/incremental.rs241
1 files changed, 181 insertions, 60 deletions
diff --git a/crates/hir-def/src/nameres/tests/incremental.rs b/crates/hir-def/src/nameres/tests/incremental.rs
index 4a86f88e57..78cb78e833 100644
--- a/crates/hir-def/src/nameres/tests/incremental.rs
+++ b/crates/hir-def/src/nameres/tests/incremental.rs
@@ -1,13 +1,19 @@
-use base_db::SourceDatabaseExt;
+use base_db::{SourceDatabase, SourceDatabaseExt};
use triomphe::Arc;
-use crate::{db::DefDatabase, AdtId, ModuleDefId};
-
-use super::*;
+use crate::{
+ db::DefDatabase,
+ nameres::tests::{TestDB, WithFixture},
+ AdtId, ModuleDefId,
+};
fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) {
let (mut db, pos) = TestDB::with_position(ra_fixture_initial);
- let krate = db.test_crate();
+ let krate = {
+ let crate_graph = db.crate_graph();
+ // Some of these tests use minicore/proc-macros which will be injected as the first crate
+ crate_graph.iter().last().unwrap()
+ };
{
let events = db.log_executed(|| {
db.crate_def_map(krate);
@@ -28,84 +34,199 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
fn typing_inside_a_function_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
- //- /lib.rs
- mod foo;$0
+//- /lib.rs
+mod foo;$0
- use crate::foo::bar::Baz;
+use crate::foo::bar::Baz;
- enum E { A, B }
- use E::*;
+enum E { A, B }
+use E::*;
- fn foo() -> i32 {
- 1 + 1
- }
+fn foo() -> i32 {
+ 1 + 1
+}
- #[cfg(never)]
- fn no() {}
- //- /foo/mod.rs
- pub mod bar;
+#[cfg(never)]
+fn no() {}
+//- /foo/mod.rs
+pub mod bar;
- //- /foo/bar.rs
- pub struct Baz;
- ",
+//- /foo/bar.rs
+pub struct Baz;
+",
r"
- mod foo;
+mod foo;
- use crate::foo::bar::Baz;
+use crate::foo::bar::Baz;
- enum E { A, B }
- use E::*;
+enum E { A, B }
+use E::*;
- fn foo() -> i32 { 92 }
+fn foo() -> i32 { 92 }
- #[cfg(never)]
- fn no() {}
- ",
+#[cfg(never)]
+fn no() {}
+",
);
}
#[test]
fn typing_inside_a_macro_should_not_invalidate_def_map() {
- let (mut db, pos) = TestDB::with_position(
+ check_def_map_is_not_recomputed(
r"
- //- /lib.rs
- macro_rules! m {
- ($ident:ident) => {
- fn f() {
- $ident + $ident;
- };
- }
- }
- mod foo;
+//- /lib.rs
+macro_rules! m {
+ ($ident:ident) => {
+ fn f() {
+ $ident + $ident;
+ };
+ }
+}
+mod foo;
- //- /foo/mod.rs
- pub mod bar;
+//- /foo/mod.rs
+pub mod bar;
- //- /foo/bar.rs
- $0
- m!(X);
- ",
+//- /foo/bar.rs
+$0
+m!(X);
+
+pub struct S {}
+",
+ r"
+m!(Y);
+
+pub struct S {}
+",
);
- let krate = db.test_crate();
- {
- let events = db.log_executed(|| {
- let crate_def_map = db.crate_def_map(krate);
- let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
- assert_eq!(module_data.scope.resolutions().count(), 1);
- });
- assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
+}
+
+#[test]
+fn typing_inside_an_attribute_should_not_invalidate_def_map() {
+ check_def_map_is_not_recomputed(
+ r"
+//- proc_macros: identity
+//- /lib.rs
+mod foo;
+
+//- /foo/mod.rs
+pub mod bar;
+
+//- /foo/bar.rs
+$0
+#[proc_macros::identity]
+fn f() {}
+",
+ r"
+#[proc_macros::identity]
+fn f() { foo }
+",
+ );
+}
+
+#[test]
+fn typing_inside_an_attribute_arg_should_not_invalidate_def_map() {
+ check_def_map_is_not_recomputed(
+ r"
+//- proc_macros: identity
+//- /lib.rs
+mod foo;
+
+//- /foo/mod.rs
+pub mod bar;
+
+//- /foo/bar.rs
+$0
+#[proc_macros::identity]
+fn f() {}
+",
+ r"
+#[proc_macros::identity(foo)]
+fn f() {}
+",
+ );
+}
+#[test]
+fn typing_inside_macro_heavy_file_should_not_invalidate_def_map() {
+ check_def_map_is_not_recomputed(
+ r"
+//- proc_macros: identity, derive_identity
+//- /lib.rs
+macro_rules! m {
+ ($ident:ident) => {
+ fn fm() {
+ $ident + $ident;
+ };
}
- db.set_file_text(pos.file_id, Arc::from("m!(Y);"));
+}
+mod foo;
- {
- let events = db.log_executed(|| {
- let crate_def_map = db.crate_def_map(krate);
- let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
- assert_eq!(module_data.scope.resolutions().count(), 1);
- });
- assert!(!format!("{events:?}").contains("crate_def_map"), "{events:#?}")
+//- /foo/mod.rs
+pub mod bar;
+
+//- /foo/bar.rs
+$0
+fn f() {}
+
+m!(X);
+macro_rules! m2 {
+ ($ident:ident) => {
+ fn f2() {
+ $ident + $ident;
+ };
}
}
+m2!(X);
+
+#[proc_macros::identity]
+#[derive(proc_macros::DeriveIdentity)]
+pub struct S {}
+",
+ r"
+fn f() {0}
+
+m!(X);
+macro_rules! m2 {
+ ($ident:ident) => {
+ fn f2() {
+ $ident + $ident;
+ };
+ }
+}
+m2!(X);
+
+#[proc_macros::identity]
+#[derive(proc_macros::DeriveIdentity)]
+pub struct S {}
+",
+ );
+}
+
+#[test]
+fn typing_inside_a_derive_should_not_invalidate_def_map() {
+ check_def_map_is_not_recomputed(
+ r"
+//- proc_macros: derive_identity
+//- minicore:derive
+//- /lib.rs
+mod foo;
+
+//- /foo/mod.rs
+pub mod bar;
+
+//- /foo/bar.rs
+$0
+#[derive(proc_macros::DeriveIdentity)]
+#[allow()]
+struct S;
+",
+ r"
+#[derive(proc_macros::DeriveIdentity)]
+#[allow(dead_code)]
+struct S;
+",
+ );
+}
#[test]
fn typing_inside_a_function_should_not_invalidate_item_expansions() {