1
- use base_db:: SourceDatabaseExt ;
1
+ use base_db:: { SourceDatabase , SourceDatabaseExt } ;
2
2
use triomphe:: Arc ;
3
3
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
+ } ;
7
9
8
10
fn check_def_map_is_not_recomputed ( ra_fixture_initial : & str , ra_fixture_change : & str ) {
9
11
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
+ } ;
11
16
{
12
17
let events = db. log_executed ( || {
13
18
db. crate_def_map ( krate) ;
@@ -28,70 +33,197 @@ fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change:
28
33
fn typing_inside_a_function_should_not_invalidate_def_map ( ) {
29
34
check_def_map_is_not_recomputed (
30
35
r"
31
- //- /lib.rs
32
- mod foo;$0
36
+ //- /lib.rs
37
+ mod foo;$0
33
38
34
- use crate::foo::bar::Baz;
39
+ use crate::foo::bar::Baz;
35
40
36
- enum E { A, B }
37
- use E::*;
41
+ enum E { A, B }
42
+ use E::*;
38
43
39
- fn foo() -> i32 {
40
- 1 + 1
41
- }
44
+ fn foo() -> i32 {
45
+ 1 + 1
46
+ }
42
47
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;
47
52
48
- //- /foo/bar.rs
49
- pub struct Baz;
50
- ",
53
+ //- /foo/bar.rs
54
+ pub struct Baz;
55
+ " ,
51
56
r"
52
- mod foo;
57
+ mod foo;
53
58
54
- use crate::foo::bar::Baz;
59
+ use crate::foo::bar::Baz;
55
60
56
- enum E { A, B }
57
- use E::*;
61
+ enum E { A, B }
62
+ use E::*;
58
63
59
- fn foo() -> i32 { 92 }
64
+ fn foo() -> i32 { 92 }
60
65
61
- #[cfg(never)]
62
- fn no() {}
63
- ",
66
+ #[cfg(never)]
67
+ fn no() {}
68
+ " ,
64
69
) ;
65
70
}
66
71
67
72
#[ test]
68
73
fn typing_inside_a_macro_should_not_invalidate_def_map ( ) {
69
74
check_def_map_is_not_recomputed (
70
75
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
+ }
80
102
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;
83
110
84
- //- /foo/bar.rs
85
- $0
86
- m!(X);
111
+ //- /foo/mod.rs
112
+ pub mod bar;
87
113
88
- pub struct S {}
89
- " ,
114
+ //- /foo/bar.rs
115
+ $0
116
+ #[proc_macros::identity]
117
+ fn f() {}
118
+ " ,
90
119
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;
92
136
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
+ " ,
95
227
) ;
96
228
}
97
229
0 commit comments