Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8423893

Browse files
committed
More incremental tests
1 parent 05f375e commit 8423893

File tree

1 file changed

+179
-47
lines changed

1 file changed

+179
-47
lines changed

crates/hir-def/src/nameres/tests/incremental.rs

Lines changed: 179 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
use base_db::SourceDatabaseExt;
1+
use base_db::{SourceDatabase, SourceDatabaseExt};
22
use triomphe::Arc;
33

4-
use crate::{db::DefDatabase, AdtId, ModuleDefId};
5-
6-
use super::*;
4+
use crate::{
5+
db::DefDatabase,
6+
nameres::tests::{TestDB, WithFixture},
7+
AdtId, ModuleDefId,
8+
};
79

810
fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) {
911
let (mut db, pos) = TestDB::with_position(ra_fixture_initial);
10-
let krate = db.test_crate();
12+
let krate = {
13+
let crate_graph = db.crate_graph();
14+
crate_graph.iter().last().unwrap()
15+
};
1116
{
1217
let events = db.log_executed(|| {
1318
db.crate_def_map(krate);
@@ -28,70 +33,197 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
2833
fn typing_inside_a_function_should_not_invalidate_def_map() {
2934
check_def_map_is_not_recomputed(
3035
r"
31-
//- /lib.rs
32-
mod foo;$0
36+
//- /lib.rs
37+
mod foo;$0
3338
34-
use crate::foo::bar::Baz;
39+
use crate::foo::bar::Baz;
3540
36-
enum E { A, B }
37-
use E::*;
41+
enum E { A, B }
42+
use E::*;
3843
39-
fn foo() -> i32 {
40-
1 + 1
41-
}
44+
fn foo() -> i32 {
45+
1 + 1
46+
}
4247
43-
#[cfg(never)]
44-
fn no() {}
45-
//- /foo/mod.rs
46-
pub mod bar;
48+
#[cfg(never)]
49+
fn no() {}
50+
//- /foo/mod.rs
51+
pub mod bar;
4752
48-
//- /foo/bar.rs
49-
pub struct Baz;
50-
",
53+
//- /foo/bar.rs
54+
pub struct Baz;
55+
",
5156
r"
52-
mod foo;
57+
mod foo;
5358
54-
use crate::foo::bar::Baz;
59+
use crate::foo::bar::Baz;
5560
56-
enum E { A, B }
57-
use E::*;
61+
enum E { A, B }
62+
use E::*;
5863
59-
fn foo() -> i32 { 92 }
64+
fn foo() -> i32 { 92 }
6065
61-
#[cfg(never)]
62-
fn no() {}
63-
",
66+
#[cfg(never)]
67+
fn no() {}
68+
",
6469
);
6570
}
6671

6772
#[test]
6873
fn typing_inside_a_macro_should_not_invalidate_def_map() {
6974
check_def_map_is_not_recomputed(
7075
r"
71-
//- /lib.rs
72-
macro_rules! m {
73-
($ident:ident) => {
74-
fn f() {
75-
$ident + $ident;
76-
};
77-
}
78-
}
79-
mod foo;
76+
//- /lib.rs
77+
macro_rules! m {
78+
($ident:ident) => {
79+
fn f() {
80+
$ident + $ident;
81+
};
82+
}
83+
}
84+
mod foo;
85+
86+
//- /foo/mod.rs
87+
pub mod bar;
88+
89+
//- /foo/bar.rs
90+
$0
91+
m!(X);
92+
93+
pub struct S {}
94+
",
95+
r"
96+
m!(Y);
97+
98+
pub struct S {}
99+
",
100+
);
101+
}
80102

81-
//- /foo/mod.rs
82-
pub mod bar;
103+
#[test]
104+
fn typing_inside_an_attribute_should_not_invalidate_def_map() {
105+
check_def_map_is_not_recomputed(
106+
r"
107+
//- proc_macros: identity
108+
//- /lib.rs
109+
mod foo;
83110
84-
//- /foo/bar.rs
85-
$0
86-
m!(X);
111+
//- /foo/mod.rs
112+
pub mod bar;
87113
88-
pub struct S {}
89-
",
114+
//- /foo/bar.rs
115+
$0
116+
#[proc_macros::identity]
117+
fn f() {}
118+
",
90119
r"
91-
m!(Y);
120+
#[proc_macros::identity]
121+
fn f() { foo }
122+
",
123+
);
124+
}
125+
126+
#[test]
127+
fn typing_inside_an_attribute_arg_should_not_invalidate_def_map() {
128+
check_def_map_is_not_recomputed(
129+
r"
130+
//- proc_macros: identity
131+
//- /lib.rs
132+
mod foo;
133+
134+
//- /foo/mod.rs
135+
pub mod bar;
92136
93-
pub struct S {}
94-
",
137+
//- /foo/bar.rs
138+
$0
139+
#[proc_macros::identity]
140+
fn f() {}
141+
",
142+
r"
143+
#[proc_macros::identity(foo)]
144+
fn f() {}
145+
",
146+
);
147+
}
148+
#[test]
149+
fn typing_inside_macro_heavy_file_should_not_invalidate_def_map() {
150+
check_def_map_is_not_recomputed(
151+
r"
152+
//- proc_macros: identity, derive_identity
153+
//- /lib.rs
154+
macro_rules! m {
155+
($ident:ident) => {
156+
fn fm() {
157+
$ident + $ident;
158+
};
159+
}
160+
}
161+
mod foo;
162+
163+
//- /foo/mod.rs
164+
pub mod bar;
165+
166+
//- /foo/bar.rs
167+
$0
168+
fn f() {}
169+
170+
m!(X);
171+
macro_rules! m2 {
172+
($ident:ident) => {
173+
fn f2() {
174+
$ident + $ident;
175+
};
176+
}
177+
}
178+
m2!(X);
179+
180+
#[proc_macros::identity]
181+
#[derive(proc_macros::DeriveIdentity)]
182+
pub struct S {}
183+
",
184+
r"
185+
fn f() {0}
186+
187+
m!(X);
188+
macro_rules! m2 {
189+
($ident:ident) => {
190+
fn f2() {
191+
$ident + $ident;
192+
};
193+
}
194+
}
195+
m2!(X);
196+
197+
#[proc_macros::identity]
198+
#[derive(proc_macros::DeriveIdentity)]
199+
pub struct S {}
200+
",
201+
);
202+
}
203+
204+
#[test]
205+
fn typing_inside_a_derive_should_not_invalidate_def_map() {
206+
check_def_map_is_not_recomputed(
207+
r"
208+
//- proc_macros: derive_identity
209+
//- minicore:derive
210+
//- /lib.rs
211+
mod foo;
212+
213+
//- /foo/mod.rs
214+
pub mod bar;
215+
216+
//- /foo/bar.rs
217+
$0
218+
#[derive(proc_macros::DeriveIdentity)]
219+
#[allow()]
220+
struct S;
221+
",
222+
r"
223+
#[derive(proc_macros::DeriveIdentity)]
224+
#[allow(dead_code)]
225+
struct S;
226+
",
95227
);
96228
}
97229

0 commit comments

Comments
 (0)