aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-17 13:38:52 +0100
committerGitHub <[email protected]>2020-07-17 13:38:52 +0100
commit23df3834333a4db1449b2ba52e878ade47d1dfb2 (patch)
tree33f5b632ed98ffd6cbd7d670b4d9ee79893e31de /crates
parent2ca0e9e00e5a55bd591ae0a85fb00918b111e063 (diff)
parentfcdac030335ba58e8267f3414101d4c2edb3797c (diff)
Merge #5422
5422: Rewrite def map tests from insta to expect r=matklad a=matklad Those indentation markers are annoying... bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_def/src/nameres/tests.rs844
-rw-r--r--crates/ra_hir_def/src/nameres/tests/globs.rs578
-rw-r--r--crates/ra_hir_def/src/nameres/tests/macros.rs1047
-rw-r--r--crates/ra_hir_def/src/nameres/tests/mod_resolution.rs1257
-rw-r--r--crates/ra_hir_def/src/nameres/tests/primitives.rs33
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs71
-rw-r--r--crates/ra_ide/src/lib.rs74
7 files changed, 1892 insertions, 2012 deletions
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs
index 503099fb7..02dca80c2 100644
--- a/crates/ra_hir_def/src/nameres/tests.rs
+++ b/crates/ra_hir_def/src/nameres/tests.rs
@@ -6,558 +6,531 @@ mod primitives;
6 6
7use std::sync::Arc; 7use std::sync::Arc;
8 8
9use insta::assert_snapshot; 9use expect::{expect, Expect};
10use ra_db::{fixture::WithFixture, SourceDatabase}; 10use ra_db::{fixture::WithFixture, SourceDatabase};
11use test_utils::mark; 11use test_utils::mark;
12 12
13use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; 13use crate::{db::DefDatabase, nameres::*, test_db::TestDB};
14 14
15fn def_map(ra_fixture: &str) -> String {
16 compute_crate_def_map(ra_fixture).dump()
17}
18
19fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> { 15fn compute_crate_def_map(fixture: &str) -> Arc<CrateDefMap> {
20 let db = TestDB::with_files(fixture); 16 let db = TestDB::with_files(fixture);
21 let krate = db.crate_graph().iter().next().unwrap(); 17 let krate = db.crate_graph().iter().next().unwrap();
22 db.crate_def_map(krate) 18 db.crate_def_map(krate)
23} 19}
24 20
21fn check(ra_fixture: &str, expect: Expect) {
22 let db = TestDB::with_files(ra_fixture);
23 let krate = db.crate_graph().iter().next().unwrap();
24 let actual = db.crate_def_map(krate).dump() + "\n";
25 expect.assert_eq(&actual);
26}
27
25#[test] 28#[test]
26fn crate_def_map_smoke_test() { 29fn crate_def_map_smoke_test() {
27 let map = def_map( 30 check(
28 r" 31 r#"
29 //- /lib.rs 32//- /lib.rs
30 mod foo; 33mod foo;
31 struct S; 34struct S;
32 use crate::foo::bar::E; 35use crate::foo::bar::E;
33 use self::E::V; 36use self::E::V;
34
35 //- /foo/mod.rs
36 pub mod bar;
37 fn f() {}
38
39 //- /foo/bar.rs
40 pub struct Baz;
41
42 union U {
43 to_be: bool,
44 not_to_be: u8,
45 }
46 37
47 enum E { V } 38//- /foo/mod.rs
39pub mod bar;
40fn f() {}
48 41
49 extern { 42//- /foo/bar.rs
50 static EXT: u8; 43pub struct Baz;
51 fn ext(); 44
52 } 45union U { to_be: bool, not_to_be: u8 }
53 ", 46enum E { V }
47
48extern {
49 static EXT: u8;
50 fn ext();
51}
52"#,
53 expect![[r#"
54 crate
55 E: t
56 S: t v
57 V: t v
58 foo: t
59
60 crate::foo
61 bar: t
62 f: v
63
64 crate::foo::bar
65 Baz: t v
66 E: t
67 EXT: v
68 U: t
69 ext: v
70 "#]],
54 ); 71 );
55 assert_snapshot!(map, @r###"
56 â‹®crate
57 â‹®E: t
58 â‹®S: t v
59 â‹®V: t v
60 â‹®foo: t
61 â‹®
62 â‹®crate::foo
63 â‹®bar: t
64 â‹®f: v
65 â‹®
66 â‹®crate::foo::bar
67 â‹®Baz: t v
68 â‹®E: t
69 â‹®EXT: v
70 â‹®U: t
71 â‹®ext: v
72 "###)
73} 72}
74 73
75#[test] 74#[test]
76fn crate_def_map_super_super() { 75fn crate_def_map_super_super() {
77 let map = def_map( 76 check(
78 " 77 r#"
79 //- /lib.rs 78mod a {
80 mod a { 79 const A: usize = 0;
81 const A: usize = 0; 80 mod b {
82 81 const B: usize = 0;
83 mod b { 82 mod c {
84 const B: usize = 0; 83 use super::super::*;
85
86 mod c {
87 use super::super::*;
88 }
89 }
90 } 84 }
91 ", 85 }
86}
87"#,
88 expect![[r#"
89 crate
90 a: t
91
92 crate::a
93 A: v
94 b: t
95
96 crate::a::b
97 B: v
98 c: t
99
100 crate::a::b::c
101 A: v
102 b: t
103 "#]],
92 ); 104 );
93 assert_snapshot!(map, @r###"
94 â‹®crate
95 â‹®a: t
96 â‹®
97 â‹®crate::a
98 â‹®A: v
99 â‹®b: t
100 â‹®
101 â‹®crate::a::b
102 â‹®B: v
103 â‹®c: t
104 â‹®
105 â‹®crate::a::b::c
106 â‹®A: v
107 â‹®b: t
108 "###)
109} 105}
110 106
111#[test] 107#[test]
112fn crate_def_map_fn_mod_same_name() { 108fn crate_def_map_fn_mod_same_name() {
113 let map = def_map( 109 check(
114 " 110 r#"
115 //- /lib.rs 111mod m {
116 mod m { 112 pub mod z {}
117 pub mod z {} 113 pub fn z() {}
118 pub fn z() {} 114}
119 } 115"#,
120 ", 116 expect![[r#"
117 crate
118 m: t
119
120 crate::m
121 z: t v
122
123 crate::m::z
124 "#]],
121 ); 125 );
122 assert_snapshot!(map, @r###"
123 â‹®crate
124 â‹®m: t
125 â‹®
126 â‹®crate::m
127 â‹®z: t v
128 â‹®
129 â‹®crate::m::z
130 "###)
131} 126}
132 127
133#[test] 128#[test]
134fn bogus_paths() { 129fn bogus_paths() {
135 mark::check!(bogus_paths); 130 mark::check!(bogus_paths);
136 let map = def_map( 131 check(
137 " 132 r#"
138 //- /lib.rs 133//- /lib.rs
139 mod foo; 134mod foo;
140 struct S; 135struct S;
141 use self; 136use self;
142 137
143 //- /foo/mod.rs 138//- /foo/mod.rs
144 use super; 139use super;
145 use crate; 140use crate;
146 141"#,
147 ", 142 expect![[r#"
143 crate
144 S: t v
145 foo: t
146
147 crate::foo
148 "#]],
148 ); 149 );
149 assert_snapshot!(map, @r###"
150 â‹®crate
151 â‹®S: t v
152 â‹®foo: t
153 â‹®
154 â‹®crate::foo
155 "###
156 )
157} 150}
158 151
159#[test] 152#[test]
160fn use_as() { 153fn use_as() {
161 let map = def_map( 154 check(
162 " 155 r#"
163 //- /lib.rs 156//- /lib.rs
164 mod foo; 157mod foo;
165 158use crate::foo::Baz as Foo;
166 use crate::foo::Baz as Foo;
167 159
168 //- /foo/mod.rs 160//- /foo/mod.rs
169 pub struct Baz; 161pub struct Baz;
170 ", 162"#,
171 ); 163 expect![[r#"
172 assert_snapshot!(map, 164 crate
173 @r###" 165 Foo: t v
174 â‹®crate 166 foo: t
175 â‹®Foo: t v 167
176 â‹®foo: t 168 crate::foo
177 â‹® 169 Baz: t v
178 â‹®crate::foo 170 "#]],
179 â‹®Baz: t v
180 "###
181 ); 171 );
182} 172}
183 173
184#[test] 174#[test]
185fn use_trees() { 175fn use_trees() {
186 let map = def_map( 176 check(
187 " 177 r#"
188 //- /lib.rs 178//- /lib.rs
189 mod foo; 179mod foo;
190 180use crate::foo::bar::{Baz, Quux};
191 use crate::foo::bar::{Baz, Quux};
192 181
193 //- /foo/mod.rs 182//- /foo/mod.rs
194 pub mod bar; 183pub mod bar;
195 184
196 //- /foo/bar.rs 185//- /foo/bar.rs
197 pub struct Baz; 186pub struct Baz;
198 pub enum Quux {}; 187pub enum Quux {};
199 ", 188"#,
189 expect![[r#"
190 crate
191 Baz: t v
192 Quux: t
193 foo: t
194
195 crate::foo
196 bar: t
197
198 crate::foo::bar
199 Baz: t v
200 Quux: t
201 "#]],
200 ); 202 );
201 assert_snapshot!(map, @r###"
202 â‹®crate
203 â‹®Baz: t v
204 â‹®Quux: t
205 â‹®foo: t
206 â‹®
207 â‹®crate::foo
208 â‹®bar: t
209 â‹®
210 â‹®crate::foo::bar
211 â‹®Baz: t v
212 â‹®Quux: t
213 "###);
214} 203}
215 204
216#[test] 205#[test]
217fn re_exports() { 206fn re_exports() {
218 let map = def_map( 207 check(
219 " 208 r#"
220 //- /lib.rs 209//- /lib.rs
221 mod foo; 210mod foo;
222 211use self::foo::Baz;
223 use self::foo::Baz;
224
225 //- /foo/mod.rs
226 pub mod bar;
227 212
228 pub use self::bar::Baz; 213//- /foo/mod.rs
214pub mod bar;
215pub use self::bar::Baz;
229 216
230 //- /foo/bar.rs 217//- /foo/bar.rs
231 pub struct Baz; 218pub struct Baz;
232 ", 219"#,
220 expect![[r#"
221 crate
222 Baz: t v
223 foo: t
224
225 crate::foo
226 Baz: t v
227 bar: t
228
229 crate::foo::bar
230 Baz: t v
231 "#]],
233 ); 232 );
234 assert_snapshot!(map, @r###"
235 â‹®crate
236 â‹®Baz: t v
237 â‹®foo: t
238 â‹®
239 â‹®crate::foo
240 â‹®Baz: t v
241 â‹®bar: t
242 â‹®
243 â‹®crate::foo::bar
244 â‹®Baz: t v
245 "###);
246} 233}
247 234
248#[test] 235#[test]
249fn std_prelude() { 236fn std_prelude() {
250 mark::check!(std_prelude); 237 mark::check!(std_prelude);
251 let map = def_map( 238 check(
252 " 239 r#"
253 //- /main.rs crate:main deps:test_crate 240//- /main.rs crate:main deps:test_crate
254 use Foo::*; 241use Foo::*;
255 242
256 //- /lib.rs crate:test_crate 243//- /lib.rs crate:test_crate
257 mod prelude; 244mod prelude;
258 #[prelude_import] 245#[prelude_import]
259 use prelude::*; 246use prelude::*;
260 247
261 //- /prelude.rs 248//- /prelude.rs
262 pub enum Foo { Bar, Baz }; 249pub enum Foo { Bar, Baz };
263 ", 250"#,
251 expect![[r#"
252 crate
253 Bar: t v
254 Baz: t v
255 "#]],
264 ); 256 );
265 assert_snapshot!(map, @r###"
266 â‹®crate
267 â‹®Bar: t v
268 â‹®Baz: t v
269 "###);
270} 257}
271 258
272#[test] 259#[test]
273fn can_import_enum_variant() { 260fn can_import_enum_variant() {
274 mark::check!(can_import_enum_variant); 261 mark::check!(can_import_enum_variant);
275 let map = def_map( 262 check(
276 " 263 r#"
277 //- /lib.rs 264enum E { V }
278 enum E { V } 265use self::E::V;
279 use self::E::V; 266"#,
280 ", 267 expect![[r#"
281 ); 268 crate
282 assert_snapshot!(map, @r###" 269 E: t
283 â‹®crate 270 V: t v
284 â‹®E: t 271 "#]],
285 â‹®V: t v
286 "###
287 ); 272 );
288} 273}
289 274
290#[test] 275#[test]
291fn edition_2015_imports() { 276fn edition_2015_imports() {
292 let map = def_map( 277 check(
293 " 278 r#"
294 //- /main.rs crate:main deps:other_crate edition:2015 279//- /main.rs crate:main deps:other_crate edition:2015
295 mod foo; 280mod foo;
296 mod bar; 281mod bar;
297 282
298 //- /bar.rs 283//- /bar.rs
299 struct Bar; 284struct Bar;
300
301 //- /foo.rs
302 use bar::Bar;
303 use other_crate::FromLib;
304
305 //- /lib.rs crate:other_crate edition:2018
306 struct FromLib;
307 ",
308 );
309 285
310 assert_snapshot!(map, @r###" 286//- /foo.rs
311 â‹®crate 287use bar::Bar;
312 â‹®bar: t 288use other_crate::FromLib;
313 â‹®foo: t 289
314 â‹® 290//- /lib.rs crate:other_crate edition:2018
315 â‹®crate::bar 291struct FromLib;
316 â‹®Bar: t v 292"#,
317 â‹® 293 expect![[r#"
318 â‹®crate::foo 294 crate
319 â‹®Bar: t v 295 bar: t
320 â‹®FromLib: t v 296 foo: t
321 "###); 297
298 crate::bar
299 Bar: t v
300
301 crate::foo
302 Bar: t v
303 FromLib: t v
304 "#]],
305 );
322} 306}
323 307
324#[test] 308#[test]
325fn item_map_using_self() { 309fn item_map_using_self() {
326 let map = def_map( 310 check(
327 " 311 r#"
328 //- /lib.rs 312//- /lib.rs
329 mod foo; 313mod foo;
330 use crate::foo::bar::Baz::{self}; 314use crate::foo::bar::Baz::{self};
331 //- /foo/mod.rs 315
332 pub mod bar; 316//- /foo/mod.rs
333 //- /foo/bar.rs 317pub mod bar;
334 pub struct Baz; 318
335 ", 319//- /foo/bar.rs
320pub struct Baz;
321"#,
322 expect![[r#"
323 crate
324 Baz: t v
325 foo: t
326
327 crate::foo
328 bar: t
329
330 crate::foo::bar
331 Baz: t v
332 "#]],
336 ); 333 );
337 assert_snapshot!(map, @r###"
338 â‹®crate
339 â‹®Baz: t v
340 â‹®foo: t
341 â‹®
342 â‹®crate::foo
343 â‹®bar: t
344 â‹®
345 â‹®crate::foo::bar
346 â‹®Baz: t v
347 "###);
348} 334}
349 335
350#[test] 336#[test]
351fn item_map_across_crates() { 337fn item_map_across_crates() {
352 let map = def_map( 338 check(
353 " 339 r#"
354 //- /main.rs crate:main deps:test_crate 340//- /main.rs crate:main deps:test_crate
355 use test_crate::Baz; 341use test_crate::Baz;
356
357 //- /lib.rs crate:test_crate
358 pub struct Baz;
359 ",
360 );
361 342
362 assert_snapshot!(map, @r###" 343//- /lib.rs crate:test_crate
363 â‹®crate 344pub struct Baz;
364 â‹®Baz: t v 345"#,
365 "###); 346 expect![[r#"
347 crate
348 Baz: t v
349 "#]],
350 );
366} 351}
367 352
368#[test] 353#[test]
369fn extern_crate_rename() { 354fn extern_crate_rename() {
370 let map = def_map( 355 check(
371 " 356 r#"
372 //- /main.rs crate:main deps:alloc 357//- /main.rs crate:main deps:alloc
373 extern crate alloc as alloc_crate; 358extern crate alloc as alloc_crate;
374 359mod alloc;
375 mod alloc; 360mod sync;
376 mod sync;
377 361
378 //- /sync.rs 362//- /sync.rs
379 use alloc_crate::Arc; 363use alloc_crate::Arc;
380 364
381 //- /lib.rs crate:alloc 365//- /lib.rs crate:alloc
382 struct Arc; 366struct Arc;
383 ", 367"#,
368 expect![[r#"
369 crate
370 alloc_crate: t
371 sync: t
372
373 crate::sync
374 Arc: t v
375 "#]],
384 ); 376 );
385
386 assert_snapshot!(map, @r###"
387 â‹®crate
388 â‹®alloc_crate: t
389 â‹®sync: t
390 â‹®
391 â‹®crate::sync
392 â‹®Arc: t v
393 "###);
394} 377}
395 378
396#[test] 379#[test]
397fn extern_crate_rename_2015_edition() { 380fn extern_crate_rename_2015_edition() {
398 let map = def_map( 381 check(
399 " 382 r#"
400 //- /main.rs crate:main deps:alloc edition:2015 383//- /main.rs crate:main deps:alloc edition:2015
401 extern crate alloc as alloc_crate; 384extern crate alloc as alloc_crate;
402 385mod alloc;
403 mod alloc; 386mod sync;
404 mod sync;
405
406 //- /sync.rs
407 use alloc_crate::Arc;
408 387
409 //- /lib.rs crate:alloc 388//- /sync.rs
410 struct Arc; 389use alloc_crate::Arc;
411 ",
412 );
413 390
414 assert_snapshot!(map, 391//- /lib.rs crate:alloc
415 @r###" 392struct Arc;
416 â‹®crate 393"#,
417 â‹®alloc_crate: t 394 expect![[r#"
418 â‹®sync: t 395 crate
419 â‹® 396 alloc_crate: t
420 â‹®crate::sync 397 sync: t
421 â‹®Arc: t v 398
422 "### 399 crate::sync
400 Arc: t v
401 "#]],
423 ); 402 );
424} 403}
425 404
426#[test] 405#[test]
427fn reexport_across_crates() { 406fn reexport_across_crates() {
428 let map = def_map( 407 check(
429 " 408 r#"
430 //- /main.rs crate:main deps:test_crate 409//- /main.rs crate:main deps:test_crate
431 use test_crate::Baz; 410use test_crate::Baz;
432
433 //- /lib.rs crate:test_crate
434 pub use foo::Baz;
435 411
436 mod foo; 412//- /lib.rs crate:test_crate
413pub use foo::Baz;
414mod foo;
437 415
438 //- /foo.rs 416//- /foo.rs
439 pub struct Baz; 417pub struct Baz;
440 ", 418"#,
419 expect![[r#"
420 crate
421 Baz: t v
422 "#]],
441 ); 423 );
442
443 assert_snapshot!(map, @r###"
444 â‹®crate
445 â‹®Baz: t v
446 "###);
447} 424}
448 425
449#[test] 426#[test]
450fn values_dont_shadow_extern_crates() { 427fn values_dont_shadow_extern_crates() {
451 let map = def_map( 428 check(
452 " 429 r#"
453 //- /main.rs crate:main deps:foo 430//- /main.rs crate:main deps:foo
454 fn foo() {} 431fn foo() {}
455 use foo::Bar; 432use foo::Bar;
456
457 //- /foo/lib.rs crate:foo
458 pub struct Bar;
459 ",
460 );
461 433
462 assert_snapshot!(map, @r###" 434//- /foo/lib.rs crate:foo
463 â‹®crate 435pub struct Bar;
464 â‹®Bar: t v 436"#,
465 â‹®foo: v 437 expect![[r#"
466 "###); 438 crate
439 Bar: t v
440 foo: v
441 "#]],
442 );
467} 443}
468 444
469#[test] 445#[test]
470fn std_prelude_takes_precedence_above_core_prelude() { 446fn std_prelude_takes_precedence_above_core_prelude() {
471 let map = def_map( 447 check(
472 r#" 448 r#"
473 //- /main.rs crate:main deps:core,std 449//- /main.rs crate:main deps:core,std
474 use {Foo, Bar}; 450use {Foo, Bar};
475 451
476 //- /std.rs crate:std deps:core 452//- /std.rs crate:std deps:core
477 #[prelude_import] 453#[prelude_import]
478 pub use self::prelude::*; 454pub use self::prelude::*;
479 mod prelude { 455mod prelude {
480 pub struct Foo; 456 pub struct Foo;
481 pub use core::prelude::Bar; 457 pub use core::prelude::Bar;
482 } 458}
483 459
484 //- /core.rs crate:core 460//- /core.rs crate:core
485 #[prelude_import] 461#[prelude_import]
486 pub use self::prelude::*; 462pub use self::prelude::*;
487 mod prelude { 463mod prelude {
488 pub struct Bar; 464 pub struct Bar;
489 } 465}
490 "#, 466"#,
467 expect![[r#"
468 crate
469 Bar: t v
470 Foo: t v
471 "#]],
491 ); 472 );
492
493 assert_snapshot!(map, @r###"
494 â‹®crate
495 â‹®Bar: t v
496 â‹®Foo: t v
497 "###);
498} 473}
499 474
500#[test] 475#[test]
501fn cfg_not_test() { 476fn cfg_not_test() {
502 let map = def_map( 477 check(
503 r#" 478 r#"
504 //- /main.rs crate:main deps:std 479//- /main.rs crate:main deps:std
505 use {Foo, Bar, Baz}; 480use {Foo, Bar, Baz};
506 481
507 //- /lib.rs crate:std 482//- /lib.rs crate:std
508 #[prelude_import] 483#[prelude_import]
509 pub use self::prelude::*; 484pub use self::prelude::*;
510 mod prelude { 485mod prelude {
511 #[cfg(test)] 486 #[cfg(test)]
512 pub struct Foo; 487 pub struct Foo;
513 #[cfg(not(test))] 488 #[cfg(not(test))]
514 pub struct Bar; 489 pub struct Bar;
515 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] 490 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
516 pub struct Baz; 491 pub struct Baz;
517 } 492}
518 "#, 493"#,
494 expect![[r#"
495 crate
496 Bar: t v
497 Baz: _
498 Foo: _
499 "#]],
519 ); 500 );
520
521 assert_snapshot!(map, @r###"
522 â‹®crate
523 â‹®Bar: t v
524 â‹®Baz: _
525 â‹®Foo: _
526 "###);
527} 501}
528 502
529#[test] 503#[test]
530fn cfg_test() { 504fn cfg_test() {
531 let map = def_map( 505 check(
532 r#" 506 r#"
533 //- /main.rs crate:main deps:std 507//- /main.rs crate:main deps:std
534 use {Foo, Bar, Baz}; 508use {Foo, Bar, Baz};
535 509
536 //- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42 510//- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42
537 #[prelude_import] 511#[prelude_import]
538 pub use self::prelude::*; 512pub use self::prelude::*;
539 mod prelude { 513mod prelude {
540 #[cfg(test)] 514 #[cfg(test)]
541 pub struct Foo; 515 pub struct Foo;
542 #[cfg(not(test))] 516 #[cfg(not(test))]
543 pub struct Bar; 517 pub struct Bar;
544 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] 518 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
545 pub struct Baz; 519 pub struct Baz;
546 } 520}
547 "#, 521"#,
522 expect![[r#"
523 crate
524 Bar: _
525 Baz: t v
526 Foo: t v
527 "#]],
548 ); 528 );
549
550 assert_snapshot!(map, @r###"
551 â‹®crate
552 â‹®Bar: _
553 â‹®Baz: t v
554 â‹®Foo: t v
555 "###);
556} 529}
557 530
558#[test] 531#[test]
559fn infer_multiple_namespace() { 532fn infer_multiple_namespace() {
560 let map = def_map( 533 check(
561 r#" 534 r#"
562//- /main.rs 535//- /main.rs
563mod a { 536mod a {
@@ -571,18 +544,17 @@ mod b {
571 pub const T: () = (); 544 pub const T: () = ();
572} 545}
573"#, 546"#,
547 expect![[r#"
548 crate
549 T: t v
550 a: t
551 b: t
552
553 crate::b
554 T: v
555
556 crate::a
557 T: t v
558 "#]],
574 ); 559 );
575
576 assert_snapshot!(map, @r###"
577 â‹®crate
578 â‹®T: t v
579 â‹®a: t
580 â‹®b: t
581 â‹®
582 â‹®crate::b
583 â‹®T: v
584 â‹®
585 â‹®crate::a
586 â‹®T: t v
587"###);
588} 560}
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs
index 7f3d7509c..2ae836e3c 100644
--- a/crates/ra_hir_def/src/nameres/tests/globs.rs
+++ b/crates/ra_hir_def/src/nameres/tests/globs.rs
@@ -2,367 +2,337 @@ use super::*;
2 2
3#[test] 3#[test]
4fn glob_1() { 4fn glob_1() {
5 let map = def_map( 5 check(
6 r" 6 r#"
7 //- /lib.rs 7//- /lib.rs
8 mod foo; 8mod foo;
9 use foo::*; 9use foo::*;
10 10
11 //- /foo/mod.rs 11//- /foo/mod.rs
12 pub mod bar; 12pub mod bar;
13 pub use self::bar::Baz; 13pub use self::bar::Baz;
14 pub struct Foo; 14pub struct Foo;
15 15
16 //- /foo/bar.rs 16//- /foo/bar.rs
17 pub struct Baz; 17pub struct Baz;
18 ", 18"#,
19 ); 19 expect![[r#"
20 assert_snapshot!(map, @r###" 20 crate
21 â‹®crate 21 Baz: t v
22 â‹®Baz: t v 22 Foo: t v
23 â‹®Foo: t v 23 bar: t
24 â‹®bar: t 24 foo: t
25 â‹®foo: t 25
26 â‹® 26 crate::foo
27 â‹®crate::foo 27 Baz: t v
28 â‹®Baz: t v 28 Foo: t v
29 â‹®Foo: t v 29 bar: t
30 â‹®bar: t 30
31 â‹® 31 crate::foo::bar
32 â‹®crate::foo::bar 32 Baz: t v
33 â‹®Baz: t v 33 "#]],
34 "###
35 ); 34 );
36} 35}
37 36
38#[test] 37#[test]
39fn glob_2() { 38fn glob_2() {
40 let map = def_map( 39 check(
41 " 40 r#"
42 //- /lib.rs 41//- /lib.rs
43 mod foo; 42mod foo;
44 use foo::*; 43use foo::*;
45 44
46 //- /foo/mod.rs 45//- /foo/mod.rs
47 pub mod bar; 46pub mod bar;
48 pub use self::bar::*; 47pub use self::bar::*;
49 pub struct Foo; 48pub struct Foo;
50 49
51 //- /foo/bar.rs 50//- /foo/bar.rs
52 pub struct Baz; 51pub struct Baz;
53 pub use super::*; 52pub use super::*;
54 ", 53"#,
55 ); 54 expect![[r#"
56 assert_snapshot!(map, @r###" 55 crate
57 â‹®crate 56 Baz: t v
58 â‹®Baz: t v 57 Foo: t v
59 â‹®Foo: t v 58 bar: t
60 â‹®bar: t 59 foo: t
61 â‹®foo: t 60
62 â‹® 61 crate::foo
63 â‹®crate::foo 62 Baz: t v
64 â‹®Baz: t v 63 Foo: t v
65 â‹®Foo: t v 64 bar: t
66 â‹®bar: t 65
67 â‹® 66 crate::foo::bar
68 â‹®crate::foo::bar 67 Baz: t v
69 â‹®Baz: t v 68 Foo: t v
70 â‹®Foo: t v 69 bar: t
71 â‹®bar: t 70 "#]],
72 "###
73 ); 71 );
74} 72}
75 73
76#[test] 74#[test]
77fn glob_privacy_1() { 75fn glob_privacy_1() {
78 let map = def_map( 76 check(
79 r" 77 r"
80 //- /lib.rs 78//- /lib.rs
81 mod foo; 79mod foo;
82 use foo::*; 80use foo::*;
83 81
84 //- /foo/mod.rs 82//- /foo/mod.rs
85 pub mod bar; 83pub mod bar;
86 pub use self::bar::*; 84pub use self::bar::*;
87 struct PrivateStructFoo; 85struct PrivateStructFoo;
88 86
89 //- /foo/bar.rs 87//- /foo/bar.rs
90 pub struct Baz; 88pub struct Baz;
91 struct PrivateStructBar; 89struct PrivateStructBar;
92 pub use super::*; 90pub use super::*;
93 ", 91",
94 ); 92 expect![[r#"
95 assert_snapshot!(map, @r###" 93 crate
96 â‹®crate 94 Baz: t v
97 â‹®Baz: t v 95 bar: t
98 â‹®bar: t 96 foo: t
99 â‹®foo: t 97
100 â‹® 98 crate::foo
101 â‹®crate::foo 99 Baz: t v
102 â‹®Baz: t v 100 PrivateStructFoo: t v
103 â‹®PrivateStructFoo: t v 101 bar: t
104 â‹®bar: t 102
105 â‹® 103 crate::foo::bar
106 â‹®crate::foo::bar 104 Baz: t v
107 â‹®Baz: t v 105 PrivateStructBar: t v
108 â‹®PrivateStructBar: t v 106 PrivateStructFoo: t v
109 â‹®PrivateStructFoo: t v 107 bar: t
110 â‹®bar: t 108 "#]],
111 "###
112 ); 109 );
113} 110}
114 111
115#[test] 112#[test]
116fn glob_privacy_2() { 113fn glob_privacy_2() {
117 let map = def_map( 114 check(
118 r" 115 r"
119 //- /lib.rs 116//- /lib.rs
120 mod foo; 117mod foo;
121 use foo::*; 118use foo::*;
122 use foo::bar::*; 119use foo::bar::*;
123 120
124 //- /foo/mod.rs 121//- /foo/mod.rs
125 mod bar; 122mod bar;
126 fn Foo() {}; 123fn Foo() {};
127 pub struct Foo {}; 124pub struct Foo {};
128 125
129 //- /foo/bar.rs 126//- /foo/bar.rs
130 pub(super) struct PrivateBaz; 127pub(super) struct PrivateBaz;
131 struct PrivateBar; 128struct PrivateBar;
132 pub(crate) struct PubCrateStruct; 129pub(crate) struct PubCrateStruct;
133 ", 130",
134 ); 131 expect![[r#"
135 assert_snapshot!(map, @r###" 132 crate
136 â‹®crate 133 Foo: t
137 â‹®Foo: t 134 PubCrateStruct: t v
138 â‹®PubCrateStruct: t v 135 foo: t
139 â‹®foo: t 136
140 â‹® 137 crate::foo
141 â‹®crate::foo 138 Foo: t v
142 â‹®Foo: t v 139 bar: t
143 â‹®bar: t 140
144 â‹® 141 crate::foo::bar
145 â‹®crate::foo::bar 142 PrivateBar: t v
146 â‹®PrivateBar: t v 143 PrivateBaz: t v
147 â‹®PrivateBaz: t v 144 PubCrateStruct: t v
148 â‹®PubCrateStruct: t v 145 "#]],
149 "###
150 ); 146 );
151} 147}
152 148
153#[test] 149#[test]
154fn glob_across_crates() { 150fn glob_across_crates() {
155 mark::check!(glob_across_crates); 151 mark::check!(glob_across_crates);
156 let map = def_map( 152 check(
157 r" 153 r#"
158 //- /main.rs crate:main deps:test_crate 154//- /main.rs crate:main deps:test_crate
159 use test_crate::*; 155use test_crate::*;
160 156
161 //- /lib.rs crate:test_crate 157//- /lib.rs crate:test_crate
162 pub struct Baz; 158pub struct Baz;
163 ", 159"#,
164 ); 160 expect![[r#"
165 assert_snapshot!(map, @r###" 161 crate
166 â‹®crate 162 Baz: t v
167 â‹®Baz: t v 163 "#]],
168 "###
169 ); 164 );
170} 165}
171 166
172#[test] 167#[test]
173fn glob_privacy_across_crates() { 168fn glob_privacy_across_crates() {
174 let map = def_map( 169 check(
175 r" 170 r#"
176 //- /main.rs crate:main deps:test_crate 171//- /main.rs crate:main deps:test_crate
177 use test_crate::*; 172use test_crate::*;
178 173
179 //- /lib.rs crate:test_crate 174//- /lib.rs crate:test_crate
180 pub struct Baz; 175pub struct Baz;
181 struct Foo; 176struct Foo;
182 ", 177"#,
183 ); 178 expect![[r#"
184 assert_snapshot!(map, @r###" 179 crate
185 â‹®crate 180 Baz: t v
186 â‹®Baz: t v 181 "#]],
187 "###
188 ); 182 );
189} 183}
190 184
191#[test] 185#[test]
192fn glob_enum() { 186fn glob_enum() {
193 mark::check!(glob_enum); 187 mark::check!(glob_enum);
194 let map = def_map( 188 check(
195 " 189 r#"
196 //- /lib.rs 190enum Foo { Bar, Baz }
197 enum Foo { 191use self::Foo::*;
198 Bar, Baz 192"#,
199 } 193 expect![[r#"
200 use self::Foo::*; 194 crate
201 ", 195 Bar: t v
202 ); 196 Baz: t v
203 assert_snapshot!(map, @r###" 197 Foo: t
204 â‹®crate 198 "#]],
205 â‹®Bar: t v
206 â‹®Baz: t v
207 â‹®Foo: t
208 "###
209 ); 199 );
210} 200}
211 201
212#[test] 202#[test]
213fn glob_enum_group() { 203fn glob_enum_group() {
214 mark::check!(glob_enum_group); 204 mark::check!(glob_enum_group);
215 let map = def_map( 205 check(
216 r" 206 r#"
217 //- /lib.rs 207enum Foo { Bar, Baz }
218 enum Foo { 208use self::Foo::{*};
219 Bar, Baz 209"#,
220 } 210 expect![[r#"
221 use self::Foo::{*}; 211 crate
222 ", 212 Bar: t v
223 ); 213 Baz: t v
224 assert_snapshot!(map, @r###" 214 Foo: t
225 â‹®crate 215 "#]],
226 â‹®Bar: t v
227 â‹®Baz: t v
228 â‹®Foo: t
229 "###
230 ); 216 );
231} 217}
232 218
233#[test] 219#[test]
234fn glob_shadowed_def() { 220fn glob_shadowed_def() {
235 mark::check!(import_shadowed); 221 mark::check!(import_shadowed);
236 let map = def_map( 222 check(
237 r###" 223 r#"
238 //- /lib.rs 224//- /lib.rs
239 mod foo; 225mod foo;
240 mod bar; 226mod bar;
241 227use foo::*;
242 use foo::*; 228use bar::baz;
243 use bar::baz; 229use baz::Bar;
244 230
245 use baz::Bar; 231//- /foo.rs
246 232pub mod baz { pub struct Foo; }
247 //- /foo.rs 233
248 pub mod baz { 234//- /bar.rs
249 pub struct Foo; 235pub mod baz { pub struct Bar; }
250 } 236"#,
251 237 expect![[r#"
252 //- /bar.rs 238 crate
253 pub mod baz { 239 Bar: t v
254 pub struct Bar; 240 bar: t
255 } 241 baz: t
256 "###, 242 foo: t
257 ); 243
258 assert_snapshot!(map, @r###" 244 crate::bar
259 â‹®crate 245 baz: t
260 â‹®Bar: t v 246
261 â‹®bar: t 247 crate::bar::baz
262 â‹®baz: t 248 Bar: t v
263 â‹®foo: t 249
264 â‹® 250 crate::foo
265 â‹®crate::bar 251 baz: t
266 â‹®baz: t 252
267 â‹® 253 crate::foo::baz
268 â‹®crate::bar::baz 254 Foo: t v
269 â‹®Bar: t v 255 "#]],
270 â‹®
271 â‹®crate::foo
272 â‹®baz: t
273 â‹®
274 â‹®crate::foo::baz
275 â‹®Foo: t v
276 "###
277 ); 256 );
278} 257}
279 258
280#[test] 259#[test]
281fn glob_shadowed_def_reversed() { 260fn glob_shadowed_def_reversed() {
282 let map = def_map( 261 check(
283 r###" 262 r#"
284 //- /lib.rs 263//- /lib.rs
285 mod foo; 264mod foo;
286 mod bar; 265mod bar;
287 266use bar::baz;
288 use bar::baz; 267use foo::*;
289 use foo::*; 268use baz::Bar;
290 269
291 use baz::Bar; 270//- /foo.rs
292 271pub mod baz { pub struct Foo; }
293 //- /foo.rs 272
294 pub mod baz { 273//- /bar.rs
295 pub struct Foo; 274pub mod baz { pub struct Bar; }
296 } 275"#,
297 276 expect![[r#"
298 //- /bar.rs 277 crate
299 pub mod baz { 278 Bar: t v
300 pub struct Bar; 279 bar: t
301 } 280 baz: t
302 "###, 281 foo: t
303 ); 282
304 assert_snapshot!(map, @r###" 283 crate::bar
305 â‹®crate 284 baz: t
306 â‹®Bar: t v 285
307 â‹®bar: t 286 crate::bar::baz
308 â‹®baz: t 287 Bar: t v
309 â‹®foo: t 288
310 â‹® 289 crate::foo
311 â‹®crate::bar 290 baz: t
312 â‹®baz: t 291
313 â‹® 292 crate::foo::baz
314 â‹®crate::bar::baz 293 Foo: t v
315 â‹®Bar: t v 294 "#]],
316 â‹®
317 â‹®crate::foo
318 â‹®baz: t
319 â‹®
320 â‹®crate::foo::baz
321 â‹®Foo: t v
322 "###
323 ); 295 );
324} 296}
325 297
326#[test] 298#[test]
327fn glob_shadowed_def_dependencies() { 299fn glob_shadowed_def_dependencies() {
328 let map = def_map( 300 check(
329 r###" 301 r#"
330 //- /lib.rs 302mod a { pub mod foo { pub struct X; } }
331 mod a { pub mod foo { pub struct X; } } 303mod b { pub use super::a::foo; }
332 mod b { pub use super::a::foo; } 304mod c { pub mod foo { pub struct Y; } }
333 mod c { pub mod foo { pub struct Y; } } 305mod d {
334 mod d { 306 use super::c::foo;
335 use super::c::foo; 307 use super::b::*;
336 use super::b::*; 308 use foo::Y;
337 use foo::Y; 309}
338 } 310"#,
339 "###, 311 expect![[r#"
340 ); 312 crate
341 assert_snapshot!(map, @r###" 313 a: t
342 â‹®crate 314 b: t
343 â‹®a: t 315 c: t
344 â‹®b: t 316 d: t
345 â‹®c: t 317
346 â‹®d: t 318 crate::d
347 â‹® 319 Y: t v
348 â‹®crate::d 320 foo: t
349 â‹®Y: t v 321
350 â‹®foo: t 322 crate::c
351 â‹® 323 foo: t
352 â‹®crate::c 324
353 â‹®foo: t 325 crate::c::foo
354 â‹® 326 Y: t v
355 â‹®crate::c::foo 327
356 â‹®Y: t v 328 crate::b
357 â‹® 329 foo: t
358 â‹®crate::b 330
359 â‹®foo: t 331 crate::a
360 â‹® 332 foo: t
361 â‹®crate::a 333
362 â‹®foo: t 334 crate::a::foo
363 â‹® 335 X: t v
364 â‹®crate::a::foo 336 "#]],
365 â‹®X: t v
366 "###
367 ); 337 );
368} 338}
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs
index c52341a07..e0fb8bdef 100644
--- a/crates/ra_hir_def/src/nameres/tests/macros.rs
+++ b/crates/ra_hir_def/src/nameres/tests/macros.rs
@@ -2,655 +2,635 @@ use super::*;
2 2
3#[test] 3#[test]
4fn macro_rules_are_globally_visible() { 4fn macro_rules_are_globally_visible() {
5 let map = def_map( 5 check(
6 r" 6 r#"
7 //- /lib.rs 7//- /lib.rs
8 macro_rules! structs { 8macro_rules! structs {
9 ($($i:ident),*) => { 9 ($($i:ident),*) => {
10 $(struct $i { field: u32 } )* 10 $(struct $i { field: u32 } )*
11 } 11 }
12 } 12}
13 structs!(Foo); 13structs!(Foo);
14 mod nested; 14mod nested;
15 15
16 //- /nested.rs 16//- /nested.rs
17 structs!(Bar, Baz); 17structs!(Bar, Baz);
18 ", 18"#,
19 expect![[r#"
20 crate
21 Foo: t
22 nested: t
23
24 crate::nested
25 Bar: t
26 Baz: t
27 "#]],
19 ); 28 );
20 assert_snapshot!(map, @r###"
21 â‹®crate
22 â‹®Foo: t
23 â‹®nested: t
24 â‹®
25 â‹®crate::nested
26 â‹®Bar: t
27 â‹®Baz: t
28 "###);
29} 29}
30 30
31#[test] 31#[test]
32fn macro_rules_can_define_modules() { 32fn macro_rules_can_define_modules() {
33 let map = def_map( 33 check(
34 r" 34 r#"
35 //- /lib.rs 35//- /lib.rs
36 macro_rules! m { 36macro_rules! m {
37 ($name:ident) => { mod $name; } 37 ($name:ident) => { mod $name; }
38 } 38}
39 m!(n1); 39m!(n1);
40 40mod m { m!(n3) }
41 mod m { 41
42 m!(n3) 42//- /n1.rs
43 } 43m!(n2)
44 44//- /n1/n2.rs
45 //- /n1.rs 45struct X;
46 m!(n2) 46//- /m/n3.rs
47 //- /n1/n2.rs 47struct Y;
48 struct X; 48"#,
49 //- /m/n3.rs 49 expect![[r#"
50 struct Y; 50 crate
51 ", 51 m: t
52 n1: t
53
54 crate::m
55 n3: t
56
57 crate::m::n3
58 Y: t v
59
60 crate::n1
61 n2: t
62
63 crate::n1::n2
64 X: t v
65 "#]],
52 ); 66 );
53 assert_snapshot!(map, @r###"
54 â‹®crate
55 â‹®m: t
56 â‹®n1: t
57 â‹®
58 â‹®crate::m
59 â‹®n3: t
60 â‹®
61 â‹®crate::m::n3
62 â‹®Y: t v
63 â‹®
64 â‹®crate::n1
65 â‹®n2: t
66 â‹®
67 â‹®crate::n1::n2
68 â‹®X: t v
69 "###);
70} 67}
71 68
72#[test] 69#[test]
73fn macro_rules_from_other_crates_are_visible() { 70fn macro_rules_from_other_crates_are_visible() {
74 let map = def_map( 71 check(
75 " 72 r#"
76 //- /main.rs crate:main deps:foo 73//- /main.rs crate:main deps:foo
77 foo::structs!(Foo, Bar) 74foo::structs!(Foo, Bar)
78 mod bar; 75mod bar;
79 76
80 //- /bar.rs 77//- /bar.rs
81 use crate::*; 78use crate::*;
82 79
83 //- /lib.rs crate:foo 80//- /lib.rs crate:foo
84 #[macro_export] 81#[macro_export]
85 macro_rules! structs { 82macro_rules! structs {
86 ($($i:ident),*) => { 83 ($($i:ident),*) => {
87 $(struct $i { field: u32 } )* 84 $(struct $i { field: u32 } )*
88 } 85 }
89 } 86}
90 ", 87"#,
88 expect![[r#"
89 crate
90 Bar: t
91 Foo: t
92 bar: t
93
94 crate::bar
95 Bar: t
96 Foo: t
97 bar: t
98 "#]],
91 ); 99 );
92 assert_snapshot!(map, @r###"
93 â‹®crate
94 â‹®Bar: t
95 â‹®Foo: t
96 â‹®bar: t
97 â‹®
98 â‹®crate::bar
99 â‹®Bar: t
100 â‹®Foo: t
101 â‹®bar: t
102 "###);
103} 100}
104 101
105#[test] 102#[test]
106fn macro_rules_export_with_local_inner_macros_are_visible() { 103fn macro_rules_export_with_local_inner_macros_are_visible() {
107 let map = def_map( 104 check(
108 " 105 r#"
109 //- /main.rs crate:main deps:foo 106//- /main.rs crate:main deps:foo
110 foo::structs!(Foo, Bar) 107foo::structs!(Foo, Bar)
111 mod bar; 108mod bar;
112 109
113 //- /bar.rs 110//- /bar.rs
114 use crate::*; 111use crate::*;
115 112
116 //- /lib.rs crate:foo 113//- /lib.rs crate:foo
117 #[macro_export(local_inner_macros)] 114#[macro_export(local_inner_macros)]
118 macro_rules! structs { 115macro_rules! structs {
119 ($($i:ident),*) => { 116 ($($i:ident),*) => {
120 $(struct $i { field: u32 } )* 117 $(struct $i { field: u32 } )*
121 } 118 }
122 } 119}
123 ", 120"#,
121 expect![[r#"
122 crate
123 Bar: t
124 Foo: t
125 bar: t
126
127 crate::bar
128 Bar: t
129 Foo: t
130 bar: t
131 "#]],
124 ); 132 );
125 assert_snapshot!(map, @r###"
126 â‹®crate
127 â‹®Bar: t
128 â‹®Foo: t
129 â‹®bar: t
130 â‹®
131 â‹®crate::bar
132 â‹®Bar: t
133 â‹®Foo: t
134 â‹®bar: t
135 "###);
136} 133}
137 134
138#[test] 135#[test]
139fn local_inner_macros_makes_local_macros_usable() { 136fn local_inner_macros_makes_local_macros_usable() {
140 let map = def_map( 137 check(
141 " 138 r#"
142 //- /main.rs crate:main deps:foo 139//- /main.rs crate:main deps:foo
143 foo::structs!(Foo, Bar); 140foo::structs!(Foo, Bar);
144 mod bar; 141mod bar;
145 //- /bar.rs 142
146 use crate::*; 143//- /bar.rs
147 //- /lib.rs crate:foo 144use crate::*;
148 #[macro_export(local_inner_macros)] 145
149 macro_rules! structs { 146//- /lib.rs crate:foo
150 ($($i:ident),*) => { 147#[macro_export(local_inner_macros)]
151 inner!($($i),*); 148macro_rules! structs {
152 } 149 ($($i:ident),*) => {
153 } 150 inner!($($i),*);
154 #[macro_export] 151 }
155 macro_rules! inner { 152}
156 ($($i:ident),*) => { 153#[macro_export]
157 $(struct $i { field: u32 } )* 154macro_rules! inner {
158 } 155 ($($i:ident),*) => {
159 } 156 $(struct $i { field: u32 } )*
160 ", 157 }
158}
159"#,
160 expect![[r#"
161 crate
162 Bar: t
163 Foo: t
164 bar: t
165
166 crate::bar
167 Bar: t
168 Foo: t
169 bar: t
170 "#]],
161 ); 171 );
162 assert_snapshot!(map, @r###"
163 â‹®crate
164 â‹®Bar: t
165 â‹®Foo: t
166 â‹®bar: t
167 â‹®
168 â‹®crate::bar
169 â‹®Bar: t
170 â‹®Foo: t
171 â‹®bar: t
172 "###);
173} 172}
174 173
175#[test] 174#[test]
176fn unexpanded_macro_should_expand_by_fixedpoint_loop() { 175fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
177 let map = def_map( 176 check(
178 " 177 r#"
179 //- /main.rs crate:main deps:foo 178//- /main.rs crate:main deps:foo
180 macro_rules! baz { 179macro_rules! baz {
181 () => { 180 () => {
182 use foo::bar; 181 use foo::bar;
183 } 182 }
184 } 183}
185 184foo!();
186 foo!(); 185bar!();
187 bar!(); 186baz!();
188 baz!(); 187
189 188//- /lib.rs crate:foo
190 //- /lib.rs crate:foo 189#[macro_export]
191 #[macro_export] 190macro_rules! foo {
192 macro_rules! foo { 191 () => {
193 () => { 192 struct Foo { field: u32 }
194 struct Foo { field: u32 } 193 }
195 } 194}
196 } 195#[macro_export]
197 #[macro_export] 196macro_rules! bar {
198 macro_rules! bar { 197 () => {
199 () => { 198 use foo::foo;
200 use foo::foo; 199 }
201 } 200}
202 } 201"#,
203 ", 202 expect![[r#"
203 crate
204 Foo: t
205 bar: m
206 foo: m
207 "#]],
204 ); 208 );
205 assert_snapshot!(map, @r###"
206 â‹®crate
207 â‹®Foo: t
208 â‹®bar: m
209 â‹®foo: m
210 "###);
211} 209}
212 210
213#[test] 211#[test]
214fn macro_rules_from_other_crates_are_visible_with_macro_use() { 212fn macro_rules_from_other_crates_are_visible_with_macro_use() {
215 mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use); 213 mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use);
216 let map = def_map( 214 check(
217 " 215 r#"
218 //- /main.rs crate:main deps:foo 216//- /main.rs crate:main deps:foo
219 structs!(Foo); 217structs!(Foo);
220 structs_priv!(Bar); 218structs_priv!(Bar);
221 structs_not_exported!(MacroNotResolved1); 219structs_not_exported!(MacroNotResolved1);
222 crate::structs!(MacroNotResolved2); 220crate::structs!(MacroNotResolved2);
223 221
224 mod bar; 222mod bar;
225 223
226 #[macro_use] 224#[macro_use]
227 extern crate foo; 225extern crate foo;
228 226
229 //- /bar.rs 227//- /bar.rs
230 structs!(Baz); 228structs!(Baz);
231 crate::structs!(MacroNotResolved3); 229crate::structs!(MacroNotResolved3);
232 230
233 //- /lib.rs crate:foo 231//- /lib.rs crate:foo
234 #[macro_export] 232#[macro_export]
235 macro_rules! structs { 233macro_rules! structs {
236 ($i:ident) => { struct $i; } 234 ($i:ident) => { struct $i; }
237 } 235}
238 236
239 macro_rules! structs_not_exported { 237macro_rules! structs_not_exported {
240 ($i:ident) => { struct $i; } 238 ($i:ident) => { struct $i; }
241 } 239}
242 240
243 mod priv_mod { 241mod priv_mod {
244 #[macro_export] 242 #[macro_export]
245 macro_rules! structs_priv { 243 macro_rules! structs_priv {
246 ($i:ident) => { struct $i; } 244 ($i:ident) => { struct $i; }
247 } 245 }
248 } 246}
249 ", 247"#,
248 expect![[r#"
249 crate
250 Bar: t v
251 Foo: t v
252 bar: t
253 foo: t
254
255 crate::bar
256 Baz: t v
257 "#]],
250 ); 258 );
251 assert_snapshot!(map, @r###"
252 â‹®crate
253 â‹®Bar: t v
254 â‹®Foo: t v
255 â‹®bar: t
256 â‹®foo: t
257 â‹®
258 â‹®crate::bar
259 â‹®Baz: t v
260 "###);
261} 259}
262 260
263#[test] 261#[test]
264fn prelude_is_macro_use() { 262fn prelude_is_macro_use() {
265 mark::check!(prelude_is_macro_use); 263 mark::check!(prelude_is_macro_use);
266 let map = def_map( 264 check(
267 " 265 r#"
268 //- /main.rs crate:main deps:foo 266//- /main.rs crate:main deps:foo
269 structs!(Foo); 267structs!(Foo);
270 structs_priv!(Bar); 268structs_priv!(Bar);
271 structs_outside!(Out); 269structs_outside!(Out);
272 crate::structs!(MacroNotResolved2); 270crate::structs!(MacroNotResolved2);
273
274 mod bar;
275
276 //- /bar.rs
277 structs!(Baz);
278 crate::structs!(MacroNotResolved3);
279
280 //- /lib.rs crate:foo
281 #[prelude_import]
282 use self::prelude::*;
283
284 mod prelude {
285 #[macro_export]
286 macro_rules! structs {
287 ($i:ident) => { struct $i; }
288 }
289
290 mod priv_mod {
291 #[macro_export]
292 macro_rules! structs_priv {
293 ($i:ident) => { struct $i; }
294 }
295 }
296 }
297 271
272mod bar;
273
274//- /bar.rs
275structs!(Baz);
276crate::structs!(MacroNotResolved3);
277
278//- /lib.rs crate:foo
279#[prelude_import]
280use self::prelude::*;
281
282mod prelude {
283 #[macro_export]
284 macro_rules! structs {
285 ($i:ident) => { struct $i; }
286 }
287
288 mod priv_mod {
298 #[macro_export] 289 #[macro_export]
299 macro_rules! structs_outside { 290 macro_rules! structs_priv {
300 ($i:ident) => { struct $i; } 291 ($i:ident) => { struct $i; }
301 } 292 }
302 ", 293 }
294}
295
296#[macro_export]
297macro_rules! structs_outside {
298 ($i:ident) => { struct $i; }
299}
300"#,
301 expect![[r#"
302 crate
303 Bar: t v
304 Foo: t v
305 Out: t v
306 bar: t
307
308 crate::bar
309 Baz: t v
310 "#]],
303 ); 311 );
304 assert_snapshot!(map, @r###"
305 â‹®crate
306 â‹®Bar: t v
307 â‹®Foo: t v
308 â‹®Out: t v
309 â‹®bar: t
310 â‹®
311 â‹®crate::bar
312 â‹®Baz: t v
313 "###);
314} 312}
315 313
316#[test] 314#[test]
317fn prelude_cycle() { 315fn prelude_cycle() {
318 let map = def_map( 316 check(
319 " 317 r#"
320 //- /lib.rs 318#[prelude_import]
321 #[prelude_import] 319use self::prelude::*;
322 use self::prelude::*;
323 320
324 declare_mod!(); 321declare_mod!();
325 322
326 mod prelude { 323mod prelude {
327 macro_rules! declare_mod { 324 macro_rules! declare_mod {
328 () => (mod foo {}) 325 () => (mod foo {})
329 } 326 }
330 } 327}
331 ", 328"#,
329 expect![[r#"
330 crate
331 prelude: t
332
333 crate::prelude
334 "#]],
332 ); 335 );
333 assert_snapshot!(map, @r###"
334 â‹®crate
335 â‹®prelude: t
336 â‹®
337 â‹®crate::prelude
338 "###);
339} 336}
340 337
341#[test] 338#[test]
342fn plain_macros_are_legacy_textual_scoped() { 339fn plain_macros_are_legacy_textual_scoped() {
343 let map = def_map( 340 check(
344 r#" 341 r#"
345 //- /main.rs 342//- /main.rs
346 mod m1; 343mod m1;
347 bar!(NotFoundNotMacroUse); 344bar!(NotFoundNotMacroUse);
348 345
349 mod m2 { 346mod m2 { foo!(NotFoundBeforeInside2); }
350 foo!(NotFoundBeforeInside2);
351 }
352 347
353 macro_rules! foo { 348macro_rules! foo {
354 ($x:ident) => { struct $x; } 349 ($x:ident) => { struct $x; }
355 } 350}
356 foo!(Ok); 351foo!(Ok);
357
358 mod m3;
359 foo!(OkShadowStop);
360 bar!(NotFoundMacroUseStop);
361
362 #[macro_use]
363 mod m5 {
364 #[macro_use]
365 mod m6 {
366 macro_rules! foo {
367 ($x:ident) => { fn $x() {} }
368 }
369 }
370 }
371 foo!(ok_double_macro_use_shadow);
372
373 baz!(NotFoundBefore);
374 #[macro_use]
375 mod m7 {
376 macro_rules! baz {
377 ($x:ident) => { struct $x; }
378 }
379 }
380 baz!(OkAfter);
381 352
382 //- /m1.rs 353mod m3;
383 foo!(NotFoundBeforeInside1); 354foo!(OkShadowStop);
384 macro_rules! bar { 355bar!(NotFoundMacroUseStop);
385 ($x:ident) => { struct $x; }
386 }
387 356
388 //- /m3/mod.rs 357#[macro_use]
389 foo!(OkAfterInside); 358mod m5 {
359 #[macro_use]
360 mod m6 {
390 macro_rules! foo { 361 macro_rules! foo {
391 ($x:ident) => { fn $x() {} } 362 ($x:ident) => { fn $x() {} }
392 } 363 }
393 foo!(ok_shadow); 364 }
365}
366foo!(ok_double_macro_use_shadow);
367
368baz!(NotFoundBefore);
369#[macro_use]
370mod m7 {
371 macro_rules! baz {
372 ($x:ident) => { struct $x; }
373 }
374}
375baz!(OkAfter);
394 376
395 #[macro_use] 377//- /m1.rs
396 mod m4; 378foo!(NotFoundBeforeInside1);
397 bar!(OkMacroUse); 379macro_rules! bar {
380 ($x:ident) => { struct $x; }
381}
398 382
399 //- /m3/m4.rs 383//- /m3/mod.rs
400 foo!(ok_shadow_deep); 384foo!(OkAfterInside);
401 macro_rules! bar { 385macro_rules! foo {
402 ($x:ident) => { struct $x; } 386 ($x:ident) => { fn $x() {} }
403 } 387}
404 "#, 388foo!(ok_shadow);
389
390#[macro_use]
391mod m4;
392bar!(OkMacroUse);
393
394//- /m3/m4.rs
395foo!(ok_shadow_deep);
396macro_rules! bar {
397 ($x:ident) => { struct $x; }
398}
399"#,
400 expect![[r#"
401 crate
402 Ok: t v
403 OkAfter: t v
404 OkShadowStop: t v
405 m1: t
406 m2: t
407 m3: t
408 m5: t
409 m7: t
410 ok_double_macro_use_shadow: v
411
412 crate::m7
413
414 crate::m1
415
416 crate::m5
417 m6: t
418
419 crate::m5::m6
420
421 crate::m2
422
423 crate::m3
424 OkAfterInside: t v
425 OkMacroUse: t v
426 m4: t
427 ok_shadow: v
428
429 crate::m3::m4
430 ok_shadow_deep: v
431 "#]],
405 ); 432 );
406 assert_snapshot!(map, @r###"
407 â‹®crate
408 â‹®Ok: t v
409 â‹®OkAfter: t v
410 â‹®OkShadowStop: t v
411 â‹®m1: t
412 â‹®m2: t
413 â‹®m3: t
414 â‹®m5: t
415 â‹®m7: t
416 â‹®ok_double_macro_use_shadow: v
417 â‹®
418 â‹®crate::m7
419 â‹®
420 â‹®crate::m1
421 â‹®
422 â‹®crate::m5
423 â‹®m6: t
424 â‹®
425 â‹®crate::m5::m6
426 â‹®
427 â‹®crate::m2
428 â‹®
429 â‹®crate::m3
430 â‹®OkAfterInside: t v
431 â‹®OkMacroUse: t v
432 â‹®m4: t
433 â‹®ok_shadow: v
434 â‹®
435 â‹®crate::m3::m4
436 â‹®ok_shadow_deep: v
437 "###);
438} 433}
439 434
440#[test] 435#[test]
441fn type_value_macro_live_in_different_scopes() { 436fn type_value_macro_live_in_different_scopes() {
442 let map = def_map( 437 check(
443 " 438 r#"
444 //- /main.rs 439#[macro_export]
445 #[macro_export] 440macro_rules! foo {
446 macro_rules! foo { 441 ($x:ident) => { type $x = (); }
447 ($x:ident) => { type $x = (); } 442}
448 }
449
450 foo!(foo);
451 use foo as bar;
452 443
453 use self::foo as baz; 444foo!(foo);
454 fn baz() {} 445use foo as bar;
455 ", 446
447use self::foo as baz;
448fn baz() {}
449"#,
450 expect![[r#"
451 crate
452 bar: t m
453 baz: t v m
454 foo: t m
455 "#]],
456 ); 456 );
457 assert_snapshot!(map, @r###"
458 â‹®crate
459 â‹®bar: t m
460 â‹®baz: t v m
461 â‹®foo: t m
462 "###);
463} 457}
464 458
465#[test] 459#[test]
466fn macro_use_can_be_aliased() { 460fn macro_use_can_be_aliased() {
467 let map = def_map( 461 check(
468 " 462 r#"
469 //- /main.rs crate:main deps:foo 463//- /main.rs crate:main deps:foo
470 #[macro_use] 464#[macro_use]
471 extern crate foo; 465extern crate foo;
472 466
473 foo!(Direct); 467foo!(Direct);
474 bar!(Alias); 468bar!(Alias);
475 469
476 //- /lib.rs crate:foo 470//- /lib.rs crate:foo
477 use crate::foo as bar; 471use crate::foo as bar;
478 472
479 mod m { 473mod m {
480 #[macro_export] 474 #[macro_export]
481 macro_rules! foo { 475 macro_rules! foo {
482 ($x:ident) => { struct $x; } 476 ($x:ident) => { struct $x; }
483 } 477 }
484 } 478}
485 ", 479"#,
480 expect![[r#"
481 crate
482 Alias: t v
483 Direct: t v
484 foo: t
485 "#]],
486 ); 486 );
487 assert_snapshot!(map, @r###"
488 â‹®crate
489 â‹®Alias: t v
490 â‹®Direct: t v
491 â‹®foo: t
492 "###);
493} 487}
494 488
495#[test] 489#[test]
496fn path_qualified_macros() { 490fn path_qualified_macros() {
497 let map = def_map( 491 check(
498 " 492 r#"
499 //- /main.rs 493macro_rules! foo {
500 macro_rules! foo { 494 ($x:ident) => { struct $x; }
501 ($x:ident) => { struct $x; } 495}
502 }
503 496
504 crate::foo!(NotResolved); 497crate::foo!(NotResolved);
505 498
506 crate::bar!(OkCrate); 499crate::bar!(OkCrate);
507 bar!(OkPlain); 500bar!(OkPlain);
508 alias1!(NotHere); 501alias1!(NotHere);
509 m::alias1!(OkAliasPlain); 502m::alias1!(OkAliasPlain);
510 m::alias2!(OkAliasSuper); 503m::alias2!(OkAliasSuper);
511 m::alias3!(OkAliasCrate); 504m::alias3!(OkAliasCrate);
512 not_found!(NotFound); 505not_found!(NotFound);
513 506
514 mod m { 507mod m {
515 #[macro_export] 508 #[macro_export]
516 macro_rules! bar { 509 macro_rules! bar {
517 ($x:ident) => { struct $x; } 510 ($x:ident) => { struct $x; }
518 } 511 }
519 512 pub use bar as alias1;
520 pub use bar as alias1; 513 pub use super::bar as alias2;
521 pub use super::bar as alias2; 514 pub use crate::bar as alias3;
522 pub use crate::bar as alias3; 515 pub use self::bar as not_found;
523 pub use self::bar as not_found; 516}
524 } 517"#,
525 ", 518 expect![[r#"
519 crate
520 OkAliasCrate: t v
521 OkAliasPlain: t v
522 OkAliasSuper: t v
523 OkCrate: t v
524 OkPlain: t v
525 bar: m
526 m: t
527
528 crate::m
529 alias1: m
530 alias2: m
531 alias3: m
532 not_found: _
533 "#]],
526 ); 534 );
527 assert_snapshot!(map, @r###"
528 â‹®crate
529 â‹®OkAliasCrate: t v
530 â‹®OkAliasPlain: t v
531 â‹®OkAliasSuper: t v
532 â‹®OkCrate: t v
533 â‹®OkPlain: t v
534 â‹®bar: m
535 â‹®m: t
536 â‹®
537 â‹®crate::m
538 â‹®alias1: m
539 â‹®alias2: m
540 â‹®alias3: m
541 â‹®not_found: _
542 "###);
543} 535}
544 536
545#[test] 537#[test]
546fn macro_dollar_crate_is_correct_in_item() { 538fn macro_dollar_crate_is_correct_in_item() {
547 mark::check!(macro_dollar_crate_self); 539 mark::check!(macro_dollar_crate_self);
548 let map = def_map( 540 check(
549 " 541 r#"
550 //- /main.rs crate:main deps:foo 542//- /main.rs crate:main deps:foo
551 #[macro_use] 543#[macro_use]
552 extern crate foo; 544extern crate foo;
553 545
554 #[macro_use] 546#[macro_use]
555 mod m { 547mod m {
556 macro_rules! current { 548 macro_rules! current {
557 () => { 549 () => {
558 use $crate::Foo as FooSelf; 550 use $crate::Foo as FooSelf;
559 }
560 }
561 } 551 }
552 }
553}
562 554
563 struct Foo; 555struct Foo;
564 556
565 current!(); 557current!();
566 not_current1!(); 558not_current1!();
567 foo::not_current2!(); 559foo::not_current2!();
568
569 //- /lib.rs crate:foo
570 mod m {
571 #[macro_export]
572 macro_rules! not_current1 {
573 () => {
574 use $crate::Bar;
575 }
576 }
577 }
578 560
579 #[macro_export] 561//- /lib.rs crate:foo
580 macro_rules! not_current2 { 562mod m {
581 () => { 563 #[macro_export]
582 use $crate::Baz; 564 macro_rules! not_current1 {
583 } 565 () => {
566 use $crate::Bar;
584 } 567 }
568 }
569}
585 570
586 struct Bar; 571#[macro_export]
587 struct Baz; 572macro_rules! not_current2 {
588 ", 573 () => {
574 use $crate::Baz;
575 }
576}
577
578struct Bar;
579struct Baz;
580"#,
581 expect![[r#"
582 crate
583 Bar: t v
584 Baz: t v
585 Foo: t v
586 FooSelf: t v
587 foo: t
588 m: t
589
590 crate::m
591 "#]],
589 ); 592 );
590 assert_snapshot!(map, @r###"
591 â‹®crate
592 â‹®Bar: t v
593 â‹®Baz: t v
594 â‹®Foo: t v
595 â‹®FooSelf: t v
596 â‹®foo: t
597 â‹®m: t
598 â‹®
599 â‹®crate::m
600 "###);
601} 593}
602 594
603#[test] 595#[test]
604fn macro_dollar_crate_is_correct_in_indirect_deps() { 596fn macro_dollar_crate_is_correct_in_indirect_deps() {
605 mark::check!(macro_dollar_crate_other); 597 mark::check!(macro_dollar_crate_other);
606 // From std 598 // From std
607 let map = def_map( 599 check(
608 r#" 600 r#"
609 //- /main.rs crate:main deps:std 601//- /main.rs crate:main deps:std
610 foo!(); 602foo!();
611 603
612 //- /std.rs crate:std deps:core 604//- /std.rs crate:std deps:core
613 #[prelude_import] 605#[prelude_import]
614 use self::prelude::*; 606use self::prelude::*;
615 607
616 pub use core::foo; 608pub use core::foo;
617 609
618 mod prelude {} 610mod prelude {}
619 611
620 #[macro_use] 612#[macro_use]
621 mod std_macros; 613mod std_macros;
622 614
623 //- /core.rs crate:core 615//- /core.rs crate:core
624 #[macro_export] 616#[macro_export]
625 macro_rules! foo { 617macro_rules! foo {
626 () => { 618 () => {
627 use $crate::bar; 619 use $crate::bar;
628 } 620 }
629 }
630
631 pub struct bar;
632 "#,
633 );
634 assert_snapshot!(map, @r###"
635 â‹®crate
636 â‹®bar: t v
637 "###);
638} 621}
639 622
640#[test] 623pub struct bar;
641fn expand_derive() { 624"#,
642 let map = compute_crate_def_map( 625 expect![[r#"
643 " 626 crate
644 //- /main.rs 627 bar: t v
645 #[derive(Clone)] 628 "#]],
646 struct Foo;
647 ",
648 ); 629 );
649 assert_eq!(map.modules[map.root].scope.impls().len(), 1);
650} 630}
651 631
652#[test] 632#[test]
653fn expand_multiple_derive() { 633fn expand_derive() {
654 let map = compute_crate_def_map( 634 let map = compute_crate_def_map(
655 " 635 "
656 //- /main.rs 636 //- /main.rs
@@ -664,8 +644,8 @@ fn expand_multiple_derive() {
664#[test] 644#[test]
665fn macro_expansion_overflow() { 645fn macro_expansion_overflow() {
666 mark::check!(macro_expansion_overflow); 646 mark::check!(macro_expansion_overflow);
667 compute_crate_def_map( 647 check(
668 " 648 r#"
669macro_rules! a { 649macro_rules! a {
670 ($e:expr; $($t:tt)*) => { 650 ($e:expr; $($t:tt)*) => {
671 b!($($t)*); 651 b!($($t)*);
@@ -681,6 +661,9 @@ macro_rules! b {
681} 661}
682 662
683b! { static = #[] (); } 663b! { static = #[] (); }
684", 664"#,
665 expect![[r#"
666 crate
667 "#]],
685 ); 668 );
686} 669}
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
index 753684201..3da16fbe3 100644
--- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
@@ -3,710 +3,672 @@ use super::*;
3#[test] 3#[test]
4fn name_res_works_for_broken_modules() { 4fn name_res_works_for_broken_modules() {
5 mark::check!(name_res_works_for_broken_modules); 5 mark::check!(name_res_works_for_broken_modules);
6 let map = def_map( 6 check(
7 r" 7 r"
8 //- /lib.rs 8//- /lib.rs
9 mod foo // no `;`, no body 9mod foo // no `;`, no body
10 10use self::foo::Baz;
11 use self::foo::Baz; 11
12 12//- /foo/mod.rs
13 //- /foo/mod.rs 13pub mod bar;
14 pub mod bar; 14pub use self::bar::Baz;
15 15
16 pub use self::bar::Baz; 16//- /foo/bar.rs
17 17pub struct Baz;
18 //- /foo/bar.rs 18",
19 pub struct Baz; 19 expect![[r#"
20 ", 20 crate
21 Baz: _
22 foo: t
23
24 crate::foo
25 "#]],
21 ); 26 );
22 assert_snapshot!(map, @r###"
23crate
24Baz: _
25foo: t
26
27crate::foo
28 "###);
29} 27}
30 28
31#[test] 29#[test]
32fn nested_module_resolution() { 30fn nested_module_resolution() {
33 let map = def_map( 31 check(
34 r" 32 r#"
35 //- /lib.rs 33//- /lib.rs
36 mod n1; 34mod n1;
37 35
38 //- /n1.rs 36//- /n1.rs
39 mod n2; 37mod n2;
40 38
41 //- /n1/n2.rs 39//- /n1/n2.rs
42 struct X; 40struct X;
43 ", 41"#,
42 expect![[r#"
43 crate
44 n1: t
45
46 crate::n1
47 n2: t
48
49 crate::n1::n2
50 X: t v
51 "#]],
44 ); 52 );
45
46 assert_snapshot!(map, @r###"
47 â‹®crate
48 â‹®n1: t
49 â‹®
50 â‹®crate::n1
51 â‹®n2: t
52 â‹®
53 â‹®crate::n1::n2
54 â‹®X: t v
55 "###);
56} 53}
57 54
58#[test] 55#[test]
59fn nested_module_resolution_2() { 56fn nested_module_resolution_2() {
60 let map = def_map( 57 check(
61 r" 58 r#"
62 //- /lib.rs 59//- /lib.rs
63 mod prelude; 60mod prelude;
64 mod iter; 61mod iter;
65 62
66 //- /prelude.rs 63//- /prelude.rs
67 pub use crate::iter::Iterator; 64pub use crate::iter::Iterator;
68 65
69 //- /iter.rs 66//- /iter.rs
70 pub use self::traits::Iterator; 67pub use self::traits::Iterator;
71 mod traits; 68mod traits;
72 69
73 //- /iter/traits.rs 70//- /iter/traits.rs
74 pub use self::iterator::Iterator; 71pub use self::iterator::Iterator;
75 mod iterator; 72mod iterator;
76 73
77 //- /iter/traits/iterator.rs 74//- /iter/traits/iterator.rs
78 pub trait Iterator; 75pub trait Iterator;
79 ", 76"#,
77 expect![[r#"
78 crate
79 iter: t
80 prelude: t
81
82 crate::iter
83 Iterator: t
84 traits: t
85
86 crate::iter::traits
87 Iterator: t
88 iterator: t
89
90 crate::iter::traits::iterator
91 Iterator: t
92
93 crate::prelude
94 Iterator: t
95 "#]],
80 ); 96 );
81
82 assert_snapshot!(map, @r###"
83 â‹®crate
84 â‹®iter: t
85 â‹®prelude: t
86 â‹®
87 â‹®crate::iter
88 â‹®Iterator: t
89 â‹®traits: t
90 â‹®
91 â‹®crate::iter::traits
92 â‹®Iterator: t
93 â‹®iterator: t
94 â‹®
95 â‹®crate::iter::traits::iterator
96 â‹®Iterator: t
97 â‹®
98 â‹®crate::prelude
99 â‹®Iterator: t
100 "###);
101} 97}
102 98
103#[test] 99#[test]
104fn module_resolution_works_for_non_standard_filenames() { 100fn module_resolution_works_for_non_standard_filenames() {
105 let map = def_map( 101 check(
106 " 102 r#"
107 //- /my_library.rs crate:my_library 103//- /my_library.rs crate:my_library
108 mod foo; 104mod foo;
109 use self::foo::Bar; 105use self::foo::Bar;
110 106
111 //- /foo/mod.rs 107//- /foo/mod.rs
112 pub struct Bar; 108pub struct Bar;
113 ", 109"#,
110 expect![[r#"
111 crate
112 Bar: t v
113 foo: t
114
115 crate::foo
116 Bar: t v
117 "#]],
114 ); 118 );
115
116 assert_snapshot!(map, @r###"
117 â‹®crate
118 â‹®Bar: t v
119 â‹®foo: t
120 â‹®
121 â‹®crate::foo
122 â‹®Bar: t v
123 "###);
124} 119}
125 120
126#[test] 121#[test]
127fn module_resolution_works_for_raw_modules() { 122fn module_resolution_works_for_raw_modules() {
128 let map = def_map( 123 check(
129 " 124 r#"
130 //- /lib.rs 125//- /lib.rs
131 mod r#async; 126mod r#async;
132 use self::r#async::Bar; 127use self::r#async::Bar;
133 128
134 //- /async.rs 129//- /async.rs
135 pub struct Bar; 130pub struct Bar;
136 ", 131"#,
132 expect![[r#"
133 crate
134 Bar: t v
135 async: t
136
137 crate::async
138 Bar: t v
139 "#]],
137 ); 140 );
138
139 assert_snapshot!(map, @r###"
140 â‹®crate
141 â‹®Bar: t v
142 â‹®async: t
143 â‹®
144 â‹®crate::async
145 â‹®Bar: t v
146 "###);
147} 141}
148 142
149#[test] 143#[test]
150fn module_resolution_decl_path() { 144fn module_resolution_decl_path() {
151 let map = def_map( 145 check(
152 r###" 146 r#"
153 //- /lib.rs 147//- /lib.rs
154 #[path = "bar/baz/foo.rs"] 148#[path = "bar/baz/foo.rs"]
155 mod foo; 149mod foo;
156 use self::foo::Bar; 150use self::foo::Bar;
157 151
158 //- /bar/baz/foo.rs 152//- /bar/baz/foo.rs
159 pub struct Bar; 153pub struct Bar;
160 "###, 154"#,
155 expect![[r#"
156 crate
157 Bar: t v
158 foo: t
159
160 crate::foo
161 Bar: t v
162 "#]],
161 ); 163 );
162
163 assert_snapshot!(map, @r###"
164 â‹®crate
165 â‹®Bar: t v
166 â‹®foo: t
167 â‹®
168 â‹®crate::foo
169 â‹®Bar: t v
170 "###);
171} 164}
172 165
173#[test] 166#[test]
174fn module_resolution_module_with_path_in_mod_rs() { 167fn module_resolution_module_with_path_in_mod_rs() {
175 let map = def_map( 168 check(
176 r###" 169 r#"
177 //- /main.rs 170//- /main.rs
178 mod foo; 171mod foo;
179 172
180 //- /foo/mod.rs 173//- /foo/mod.rs
181 #[path = "baz.rs"] 174#[path = "baz.rs"]
182 pub mod bar; 175pub mod bar;
183 176use self::bar::Baz;
184 use self::bar::Baz; 177
185 178//- /foo/baz.rs
186 //- /foo/baz.rs 179pub struct Baz;
187 pub struct Baz; 180"#,
188 "###, 181 expect![[r#"
182 crate
183 foo: t
184
185 crate::foo
186 Baz: t v
187 bar: t
188
189 crate::foo::bar
190 Baz: t v
191 "#]],
189 ); 192 );
190
191 assert_snapshot!(map, @r###"
192 â‹®crate
193 â‹®foo: t
194 â‹®
195 â‹®crate::foo
196 â‹®Baz: t v
197 â‹®bar: t
198 â‹®
199 â‹®crate::foo::bar
200 â‹®Baz: t v
201 "###);
202} 193}
203 194
204#[test] 195#[test]
205fn module_resolution_module_with_path_non_crate_root() { 196fn module_resolution_module_with_path_non_crate_root() {
206 let map = def_map( 197 check(
207 r###" 198 r#"
208 //- /main.rs 199//- /main.rs
209 mod foo; 200mod foo;
210 201
211 //- /foo.rs 202//- /foo.rs
212 #[path = "baz.rs"] 203#[path = "baz.rs"]
213 pub mod bar; 204pub mod bar;
214 205use self::bar::Baz;
215 use self::bar::Baz; 206
216 207//- /baz.rs
217 //- /baz.rs 208pub struct Baz;
218 pub struct Baz; 209"#,
219 "###, 210 expect![[r#"
211 crate
212 foo: t
213
214 crate::foo
215 Baz: t v
216 bar: t
217
218 crate::foo::bar
219 Baz: t v
220 "#]],
220 ); 221 );
221
222 assert_snapshot!(map, @r###"
223 â‹®crate
224 â‹®foo: t
225 â‹®
226 â‹®crate::foo
227 â‹®Baz: t v
228 â‹®bar: t
229 â‹®
230 â‹®crate::foo::bar
231 â‹®Baz: t v
232 "###);
233} 222}
234 223
235#[test] 224#[test]
236fn module_resolution_module_decl_path_super() { 225fn module_resolution_module_decl_path_super() {
237 let map = def_map( 226 check(
238 r###" 227 r#"
239 //- /main.rs 228//- /main.rs
240 #[path = "bar/baz/module.rs"] 229#[path = "bar/baz/module.rs"]
241 mod foo; 230mod foo;
242 pub struct Baz; 231pub struct Baz;
243 232
244 //- /bar/baz/module.rs 233//- /bar/baz/module.rs
245 use super::Baz; 234use super::Baz;
246 "###, 235"#,
236 expect![[r#"
237 crate
238 Baz: t v
239 foo: t
240
241 crate::foo
242 Baz: t v
243 "#]],
247 ); 244 );
248
249 assert_snapshot!(map, @r###"
250 â‹®crate
251 â‹®Baz: t v
252 â‹®foo: t
253 â‹®
254 â‹®crate::foo
255 â‹®Baz: t v
256 "###);
257} 245}
258 246
259#[test] 247#[test]
260fn module_resolution_explicit_path_mod_rs() { 248fn module_resolution_explicit_path_mod_rs() {
261 let map = def_map( 249 check(
262 r###" 250 r#"
263 //- /main.rs 251//- /main.rs
264 #[path = "module/mod.rs"] 252#[path = "module/mod.rs"]
265 mod foo; 253mod foo;
266 254
267 //- /module/mod.rs 255//- /module/mod.rs
268 pub struct Baz; 256pub struct Baz;
269 "###, 257"#,
258 expect![[r#"
259 crate
260 foo: t
261
262 crate::foo
263 Baz: t v
264 "#]],
270 ); 265 );
271
272 assert_snapshot!(map, @r###"
273 â‹®crate
274 â‹®foo: t
275 â‹®
276 â‹®crate::foo
277 â‹®Baz: t v
278 "###);
279} 266}
280 267
281#[test] 268#[test]
282fn module_resolution_relative_path() { 269fn module_resolution_relative_path() {
283 let map = def_map( 270 check(
284 r###" 271 r#"
285 //- /main.rs 272//- /main.rs
286 mod foo; 273mod foo;
287 274
288 //- /foo.rs 275//- /foo.rs
289 #[path = "./sub.rs"] 276#[path = "./sub.rs"]
290 pub mod foo_bar; 277pub mod foo_bar;
291 278
292 //- /sub.rs 279//- /sub.rs
293 pub struct Baz; 280pub struct Baz;
294 "###, 281"#,
282 expect![[r#"
283 crate
284 foo: t
285
286 crate::foo
287 foo_bar: t
288
289 crate::foo::foo_bar
290 Baz: t v
291 "#]],
295 ); 292 );
296
297 assert_snapshot!(map, @r###"
298 â‹®crate
299 â‹®foo: t
300 â‹®
301 â‹®crate::foo
302 â‹®foo_bar: t
303 â‹®
304 â‹®crate::foo::foo_bar
305 â‹®Baz: t v
306 "###);
307} 293}
308 294
309#[test] 295#[test]
310fn module_resolution_relative_path_2() { 296fn module_resolution_relative_path_2() {
311 let map = def_map( 297 check(
312 r###" 298 r#"
313 //- /main.rs 299//- /main.rs
314 mod foo; 300mod foo;
315 301
316 //- /foo/mod.rs 302//- /foo/mod.rs
317 #[path="../sub.rs"] 303#[path="../sub.rs"]
318 pub mod foo_bar; 304pub mod foo_bar;
319 305
320 //- /sub.rs 306//- /sub.rs
321 pub struct Baz; 307pub struct Baz;
322 "###, 308"#,
309 expect![[r#"
310 crate
311 foo: t
312
313 crate::foo
314 foo_bar: t
315
316 crate::foo::foo_bar
317 Baz: t v
318 "#]],
323 ); 319 );
324
325 assert_snapshot!(map, @r###"
326 â‹®crate
327 â‹®foo: t
328 â‹®
329 â‹®crate::foo
330 â‹®foo_bar: t
331 â‹®
332 â‹®crate::foo::foo_bar
333 â‹®Baz: t v
334 "###);
335} 320}
336 321
337#[test] 322#[test]
338fn module_resolution_relative_path_outside_root() { 323fn module_resolution_relative_path_outside_root() {
339 let map = def_map( 324 check(
340 r###" 325 r#"
341 //- /main.rs 326//- /main.rs
342 327#[path="../../../../../outside.rs"]
343 #[path="../../../../../outside.rs"] 328mod foo;
344 mod foo; 329"#,
345 "###, 330 expect![[r#"
331 crate
332 "#]],
346 ); 333 );
347
348 assert_snapshot!(map, @r###"
349 â‹®crate
350 "###);
351} 334}
352 335
353#[test] 336#[test]
354fn module_resolution_explicit_path_mod_rs_2() { 337fn module_resolution_explicit_path_mod_rs_2() {
355 let map = def_map( 338 check(
356 r###" 339 r#"
357 //- /main.rs 340//- /main.rs
358 #[path = "module/bar/mod.rs"] 341#[path = "module/bar/mod.rs"]
359 mod foo; 342mod foo;
360 343
361 //- /module/bar/mod.rs 344//- /module/bar/mod.rs
362 pub struct Baz; 345pub struct Baz;
363 "###, 346"#,
347 expect![[r#"
348 crate
349 foo: t
350
351 crate::foo
352 Baz: t v
353 "#]],
364 ); 354 );
365
366 assert_snapshot!(map, @r###"
367 â‹®crate
368 â‹®foo: t
369 â‹®
370 â‹®crate::foo
371 â‹®Baz: t v
372 "###);
373} 355}
374 356
375#[test] 357#[test]
376fn module_resolution_explicit_path_mod_rs_with_win_separator() { 358fn module_resolution_explicit_path_mod_rs_with_win_separator() {
377 let map = def_map( 359 check(
378 r###" 360 r#"
379 //- /main.rs 361//- /main.rs
380 #[path = "module\bar\mod.rs"] 362#[path = "module\bar\mod.rs"]
381 mod foo; 363mod foo;
382 364
383 //- /module/bar/mod.rs 365//- /module/bar/mod.rs
384 pub struct Baz; 366pub struct Baz;
385 "###, 367"#,
368 expect![[r#"
369 crate
370 foo: t
371
372 crate::foo
373 Baz: t v
374 "#]],
386 ); 375 );
387
388 assert_snapshot!(map, @r###"
389 â‹®crate
390 â‹®foo: t
391 â‹®
392 â‹®crate::foo
393 â‹®Baz: t v
394 "###);
395} 376}
396 377
397#[test] 378#[test]
398fn module_resolution_decl_inside_inline_module_with_path_attribute() { 379fn module_resolution_decl_inside_inline_module_with_path_attribute() {
399 let map = def_map( 380 check(
400 r###" 381 r#"
401 //- /main.rs 382//- /main.rs
402 #[path = "models"] 383#[path = "models"]
403 mod foo { 384mod foo { mod bar; }
404 mod bar; 385
405 } 386//- /models/bar.rs
406 387pub struct Baz;
407 //- /models/bar.rs 388"#,
408 pub struct Baz; 389 expect![[r#"
409 "###, 390 crate
391 foo: t
392
393 crate::foo
394 bar: t
395
396 crate::foo::bar
397 Baz: t v
398 "#]],
410 ); 399 );
411
412 assert_snapshot!(map, @r###"
413 â‹®crate
414 â‹®foo: t
415 â‹®
416 â‹®crate::foo
417 â‹®bar: t
418 â‹®
419 â‹®crate::foo::bar
420 â‹®Baz: t v
421 "###);
422} 400}
423 401
424#[test] 402#[test]
425fn module_resolution_decl_inside_inline_module() { 403fn module_resolution_decl_inside_inline_module() {
426 let map = def_map( 404 check(
427 r###" 405 r#"
428 //- /main.rs 406//- /main.rs
429 mod foo { 407mod foo { mod bar; }
430 mod bar; 408
431 } 409//- /foo/bar.rs
432 410pub struct Baz;
433 //- /foo/bar.rs 411"#,
434 pub struct Baz; 412 expect![[r#"
435 "###, 413 crate
414 foo: t
415
416 crate::foo
417 bar: t
418
419 crate::foo::bar
420 Baz: t v
421 "#]],
436 ); 422 );
437
438 assert_snapshot!(map, @r###"
439 â‹®crate
440 â‹®foo: t
441 â‹®
442 â‹®crate::foo
443 â‹®bar: t
444 â‹®
445 â‹®crate::foo::bar
446 â‹®Baz: t v
447 "###);
448} 423}
449 424
450#[test] 425#[test]
451fn module_resolution_decl_inside_inline_module_2_with_path_attribute() { 426fn module_resolution_decl_inside_inline_module_2_with_path_attribute() {
452 let map = def_map( 427 check(
453 r###" 428 r#"
454 //- /main.rs 429//- /main.rs
455 #[path = "models/db"] 430#[path = "models/db"]
456 mod foo { 431mod foo { mod bar; }
457 mod bar; 432
458 } 433//- /models/db/bar.rs
459 434pub struct Baz;
460 //- /models/db/bar.rs 435"#,
461 pub struct Baz; 436 expect![[r#"
462 "###, 437 crate
438 foo: t
439
440 crate::foo
441 bar: t
442
443 crate::foo::bar
444 Baz: t v
445 "#]],
463 ); 446 );
464
465 assert_snapshot!(map, @r###"
466 â‹®crate
467 â‹®foo: t
468 â‹®
469 â‹®crate::foo
470 â‹®bar: t
471 â‹®
472 â‹®crate::foo::bar
473 â‹®Baz: t v
474 "###);
475} 447}
476 448
477#[test] 449#[test]
478fn module_resolution_decl_inside_inline_module_3() { 450fn module_resolution_decl_inside_inline_module_3() {
479 let map = def_map( 451 check(
480 r###" 452 r#"
481 //- /main.rs 453//- /main.rs
482 #[path = "models/db"] 454#[path = "models/db"]
483 mod foo { 455mod foo {
484 #[path = "users.rs"] 456 #[path = "users.rs"]
485 mod bar; 457 mod bar;
486 } 458}
487
488 //- /models/db/users.rs
489 pub struct Baz;
490 "###,
491 );
492 459
493 assert_snapshot!(map, @r###" 460//- /models/db/users.rs
494 â‹®crate 461pub struct Baz;
495 â‹®foo: t 462"#,
496 â‹® 463 expect![[r#"
497 â‹®crate::foo 464 crate
498 â‹®bar: t 465 foo: t
499 â‹® 466
500 â‹®crate::foo::bar 467 crate::foo
501 â‹®Baz: t v 468 bar: t
502 "###); 469
470 crate::foo::bar
471 Baz: t v
472 "#]],
473 );
503} 474}
504 475
505#[test] 476#[test]
506fn module_resolution_decl_inside_inline_module_empty_path() { 477fn module_resolution_decl_inside_inline_module_empty_path() {
507 let map = def_map( 478 check(
508 r###" 479 r#"
509 //- /main.rs 480//- /main.rs
510 #[path = ""] 481#[path = ""]
511 mod foo { 482mod foo {
512 #[path = "users.rs"] 483 #[path = "users.rs"]
513 mod bar; 484 mod bar;
514 } 485}
515 486
516 //- /users.rs 487//- /users.rs
517 pub struct Baz; 488pub struct Baz;
518 "###, 489"#,
519 ); 490 expect![[r#"
491 crate
492 foo: t
520 493
521 assert_snapshot!(map, @r###" 494 crate::foo
522 â‹®crate 495 bar: t
523 â‹®foo: t 496
524 â‹® 497 crate::foo::bar
525 â‹®crate::foo 498 Baz: t v
526 â‹®bar: t 499 "#]],
527 â‹® 500 );
528 â‹®crate::foo::bar
529 â‹®Baz: t v
530 "###);
531} 501}
532 502
533#[test] 503#[test]
534fn module_resolution_decl_empty_path() { 504fn module_resolution_decl_empty_path() {
535 let map = def_map( 505 check(
536 r###" 506 r#"
537 //- /main.rs 507//- /main.rs
538 #[path = ""] // Should try to read `/` (a directory) 508#[path = ""] // Should try to read `/` (a directory)
539 mod foo; 509mod foo;
540 510
541 //- /foo.rs 511//- /foo.rs
542 pub struct Baz; 512pub struct Baz;
543 "###, 513"#,
514 expect![[r#"
515 crate
516 "#]],
544 ); 517 );
545
546 assert_snapshot!(map, @r###"
547 â‹®crate
548 "###);
549} 518}
550 519
551#[test] 520#[test]
552fn module_resolution_decl_inside_inline_module_relative_path() { 521fn module_resolution_decl_inside_inline_module_relative_path() {
553 let map = def_map( 522 check(
554 r###" 523 r#"
555 //- /main.rs 524//- /main.rs
556 #[path = "./models"] 525#[path = "./models"]
557 mod foo { 526mod foo { mod bar; }
558 mod bar; 527
559 } 528//- /models/bar.rs
560 529pub struct Baz;
561 //- /models/bar.rs 530"#,
562 pub struct Baz; 531 expect![[r#"
563 "###, 532 crate
533 foo: t
534
535 crate::foo
536 bar: t
537
538 crate::foo::bar
539 Baz: t v
540 "#]],
564 ); 541 );
565
566 assert_snapshot!(map, @r###"
567 â‹®crate
568 â‹®foo: t
569 â‹®
570 â‹®crate::foo
571 â‹®bar: t
572 â‹®
573 â‹®crate::foo::bar
574 â‹®Baz: t v
575 "###);
576} 542}
577 543
578#[test] 544#[test]
579fn module_resolution_decl_inside_inline_module_in_crate_root() { 545fn module_resolution_decl_inside_inline_module_in_crate_root() {
580 let map = def_map( 546 check(
581 r###" 547 r#"
582 //- /main.rs 548//- /main.rs
583 mod foo { 549mod foo {
584 #[path = "baz.rs"] 550 #[path = "baz.rs"]
585 mod bar; 551 mod bar;
586 } 552}
587 use self::foo::bar::Baz; 553use self::foo::bar::Baz;
588 554
589 //- /foo/baz.rs 555//- /foo/baz.rs
590 pub struct Baz; 556pub struct Baz;
591 "###, 557"#,
558 expect![[r#"
559 crate
560 Baz: t v
561 foo: t
562
563 crate::foo
564 bar: t
565
566 crate::foo::bar
567 Baz: t v
568 "#]],
592 ); 569 );
593
594 assert_snapshot!(map, @r###"
595 â‹®crate
596 â‹®Baz: t v
597 â‹®foo: t
598 â‹®
599 â‹®crate::foo
600 â‹®bar: t
601 â‹®
602 â‹®crate::foo::bar
603 â‹®Baz: t v
604 "###);
605} 570}
606 571
607#[test] 572#[test]
608fn module_resolution_decl_inside_inline_module_in_mod_rs() { 573fn module_resolution_decl_inside_inline_module_in_mod_rs() {
609 let map = def_map( 574 check(
610 r###" 575 r#"
611 //- /main.rs 576//- /main.rs
612 mod foo; 577mod foo;
578
579//- /foo/mod.rs
580mod bar {
581 #[path = "qwe.rs"]
582 pub mod baz;
583}
584use self::bar::baz::Baz;
613 585
614 //- /foo/mod.rs 586//- /foo/bar/qwe.rs
615 mod bar { 587pub struct Baz;
616 #[path = "qwe.rs"] 588"#,
617 pub mod baz; 589 expect![[r#"
618 } 590 crate
619 use self::bar::baz::Baz; 591 foo: t
620 592
621 //- /foo/bar/qwe.rs 593 crate::foo
622 pub struct Baz; 594 Baz: t v
623 "###, 595 bar: t
624 ); 596
597 crate::foo::bar
598 baz: t
625 599
626 assert_snapshot!(map, @r###" 600 crate::foo::bar::baz
627 â‹®crate 601 Baz: t v
628 â‹®foo: t 602 "#]],
629 â‹® 603 );
630 â‹®crate::foo
631 â‹®Baz: t v
632 â‹®bar: t
633 â‹®
634 â‹®crate::foo::bar
635 â‹®baz: t
636 â‹®
637 â‹®crate::foo::bar::baz
638 â‹®Baz: t v
639 "###);
640} 604}
641 605
642#[test] 606#[test]
643fn module_resolution_decl_inside_inline_module_in_non_crate_root() { 607fn module_resolution_decl_inside_inline_module_in_non_crate_root() {
644 let map = def_map( 608 check(
645 r###" 609 r#"
646 //- /main.rs 610//- /main.rs
647 mod foo; 611mod foo;
612
613//- /foo.rs
614mod bar {
615 #[path = "qwe.rs"]
616 pub mod baz;
617}
618use self::bar::baz::Baz;
648 619
649 //- /foo.rs 620//- /foo/bar/qwe.rs
650 mod bar { 621pub struct Baz;
651 #[path = "qwe.rs"] 622"#,
652 pub mod baz; 623 expect![[r#"
653 } 624 crate
654 use self::bar::baz::Baz; 625 foo: t
655 626
656 //- /foo/bar/qwe.rs 627 crate::foo
657 pub struct Baz; 628 Baz: t v
658 "###, 629 bar: t
659 );
660 630
661 assert_snapshot!(map, @r###" 631 crate::foo::bar
662 â‹®crate 632 baz: t
663 â‹®foo: t 633
664 â‹® 634 crate::foo::bar::baz
665 â‹®crate::foo 635 Baz: t v
666 â‹®Baz: t v 636 "#]],
667 â‹®bar: t 637 );
668 â‹®
669 â‹®crate::foo::bar
670 â‹®baz: t
671 â‹®
672 â‹®crate::foo::bar::baz
673 â‹®Baz: t v
674 "###);
675} 638}
676 639
677#[test] 640#[test]
678fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() { 641fn module_resolution_decl_inside_inline_module_in_non_crate_root_2() {
679 let map = def_map( 642 check(
680 r###" 643 r#"
681 //- /main.rs 644//- /main.rs
682 mod foo; 645mod foo;
646
647//- /foo.rs
648#[path = "bar"]
649mod bar {
650 pub mod baz;
651}
652use self::bar::baz::Baz;
683 653
684 //- /foo.rs 654//- /bar/baz.rs
685 #[path = "bar"] 655pub struct Baz;
686 mod bar { 656"#,
687 pub mod baz; 657 expect![[r#"
688 } 658 crate
689 use self::bar::baz::Baz; 659 foo: t
690
691 //- /bar/baz.rs
692 pub struct Baz;
693 "###,
694 );
695 660
696 assert_snapshot!(map, @r###" 661 crate::foo
697 â‹®crate 662 Baz: t v
698 â‹®foo: t 663 bar: t
699 â‹® 664
700 â‹®crate::foo 665 crate::foo::bar
701 â‹®Baz: t v 666 baz: t
702 â‹®bar: t 667
703 â‹® 668 crate::foo::bar::baz
704 â‹®crate::foo::bar 669 Baz: t v
705 â‹®baz: t 670 "#]],
706 â‹® 671 );
707 â‹®crate::foo::bar::baz
708 â‹®Baz: t v
709 "###);
710} 672}
711 673
712#[test] 674#[test]
@@ -749,91 +711,88 @@ fn unresolved_module_diagnostics() {
749 711
750#[test] 712#[test]
751fn module_resolution_decl_inside_module_in_non_crate_root_2() { 713fn module_resolution_decl_inside_module_in_non_crate_root_2() {
752 let map = def_map( 714 check(
753 r###" 715 r#"
754 //- /main.rs 716//- /main.rs
755 #[path="module/m2.rs"] 717#[path="module/m2.rs"]
756 mod module; 718mod module;
757 719
758 //- /module/m2.rs 720//- /module/m2.rs
759 pub mod submod; 721pub mod submod;
760 722
761 //- /module/submod.rs 723//- /module/submod.rs
762 pub struct Baz; 724pub struct Baz;
763 "###, 725"#,
726 expect![[r#"
727 crate
728 module: t
729
730 crate::module
731 submod: t
732
733 crate::module::submod
734 Baz: t v
735 "#]],
764 ); 736 );
765
766 assert_snapshot!(map, @r###"
767 â‹®crate
768 â‹®module: t
769 â‹®
770 â‹®crate::module
771 â‹®submod: t
772 â‹®
773 â‹®crate::module::submod
774 â‹®Baz: t v
775 "###);
776} 737}
777 738
778#[test] 739#[test]
779fn nested_out_of_line_module() { 740fn nested_out_of_line_module() {
780 let map = def_map( 741 check(
781 r###" 742 r#"
782 //- /lib.rs 743//- /lib.rs
783 mod a { 744mod a {
784 mod b { 745 mod b {
785 mod c; 746 mod c;
786 } 747 }
787 } 748}
788
789 //- /a/b/c.rs
790 struct X;
791 "###,
792 );
793 749
794 assert_snapshot!(map, @r###" 750//- /a/b/c.rs
795 â‹®crate 751struct X;
796 â‹®a: t 752"#,
797 â‹® 753 expect![[r#"
798 â‹®crate::a 754 crate
799 â‹®b: t 755 a: t
800 â‹® 756
801 â‹®crate::a::b 757 crate::a
802 â‹®c: t 758 b: t
803 â‹® 759
804 â‹®crate::a::b::c 760 crate::a::b
805 â‹®X: t v 761 c: t
806 "###); 762
763 crate::a::b::c
764 X: t v
765 "#]],
766 );
807} 767}
808 768
809#[test] 769#[test]
810fn nested_out_of_line_module_with_path() { 770fn nested_out_of_line_module_with_path() {
811 let map = def_map( 771 check(
812 r###" 772 r#"
813 //- /lib.rs 773//- /lib.rs
814 mod a { 774mod a {
815 #[path = "d/e"] 775 #[path = "d/e"]
816 mod b { 776 mod b {
817 mod c; 777 mod c;
818 } 778 }
819 } 779}
820 780
821 //- /a/d/e/c.rs 781//- /a/d/e/c.rs
822 struct X; 782struct X;
823 "###, 783"#,
824 ); 784 expect![[r#"
785 crate
786 a: t
825 787
826 assert_snapshot!(map, @r###" 788 crate::a
827 â‹®crate 789 b: t
828 â‹®a: t 790
829 â‹® 791 crate::a::b
830 â‹®crate::a 792 c: t
831 â‹®b: t 793
832 â‹® 794 crate::a::b::c
833 â‹®crate::a::b 795 X: t v
834 â‹®c: t 796 "#]],
835 â‹® 797 );
836 â‹®crate::a::b::c
837 â‹®X: t v
838 "###);
839} 798}
diff --git a/crates/ra_hir_def/src/nameres/tests/primitives.rs b/crates/ra_hir_def/src/nameres/tests/primitives.rs
index 0e2708658..215e8952d 100644
--- a/crates/ra_hir_def/src/nameres/tests/primitives.rs
+++ b/crates/ra_hir_def/src/nameres/tests/primitives.rs
@@ -2,23 +2,22 @@ use super::*;
2 2
3#[test] 3#[test]
4fn primitive_reexport() { 4fn primitive_reexport() {
5 let map = def_map( 5 check(
6 " 6 r#"
7 //- /lib.rs 7//- /lib.rs
8 mod foo; 8mod foo;
9 use foo::int; 9use foo::int;
10 10
11 //- /foo.rs 11//- /foo.rs
12 pub use i32 as int; 12pub use i32 as int;
13 ", 13"#,
14 ); 14 expect![[r#"
15 assert_snapshot!(map, @r###" 15 crate
16 â‹®crate 16 foo: t
17 â‹®foo: t 17 int: t
18 â‹®int: t 18
19 â‹® 19 crate::foo
20 â‹®crate::foo 20 int: t
21 â‹®int: t 21 "#]],
22 "###
23 ); 22 );
24} 23}
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 6dcb9415a..fd245705c 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -418,3 +418,74 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) ->
418 } 418 }
419 } 419 }
420} 420}
421
422#[cfg(test)]
423mod tests {
424 use expect::expect;
425
426 use crate::{mock_analysis::single_file, Query};
427
428 #[test]
429 fn test_nav_for_symbol() {
430 let (analysis, _) = single_file(
431 r#"
432enum FooInner { }
433fn foo() { enum FooInner { } }
434"#,
435 );
436
437 let navs = analysis.symbol_search(Query::new("FooInner".to_string())).unwrap();
438 expect![[r#"
439 [
440 NavigationTarget {
441 file_id: FileId(
442 1,
443 ),
444 full_range: 0..17,
445 focus_range: Some(
446 5..13,
447 ),
448 name: "FooInner",
449 kind: ENUM_DEF,
450 container_name: None,
451 description: Some(
452 "enum FooInner",
453 ),
454 docs: None,
455 },
456 NavigationTarget {
457 file_id: FileId(
458 1,
459 ),
460 full_range: 29..46,
461 focus_range: Some(
462 34..42,
463 ),
464 name: "FooInner",
465 kind: ENUM_DEF,
466 container_name: Some(
467 "foo",
468 ),
469 description: Some(
470 "enum FooInner",
471 ),
472 docs: None,
473 },
474 ]
475 "#]]
476 .assert_debug_eq(&navs);
477 }
478
479 #[test]
480 fn test_world_symbols_are_case_sensitive() {
481 let (analysis, _) = single_file(
482 r#"
483fn foo() {}
484struct Foo;
485"#,
486 );
487
488 let navs = analysis.symbol_search(Query::new("foo".to_string())).unwrap();
489 assert_eq!(navs.len(), 2)
490 }
491}
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 353f430ff..dc9192d42 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -526,77 +526,3 @@ fn analysis_is_send() {
526 fn is_send<T: Send>() {} 526 fn is_send<T: Send>() {}
527 is_send::<Analysis>(); 527 is_send::<Analysis>();
528} 528}
529
530#[cfg(test)]
531mod tests {
532 use crate::{display::NavigationTarget, mock_analysis::single_file, Query};
533 use ra_syntax::{
534 SmolStr,
535 SyntaxKind::{FN_DEF, STRUCT_DEF},
536 };
537
538 #[test]
539 fn test_world_symbols_with_no_container() {
540 let code = r#"
541 enum FooInner { }
542 "#;
543
544 let mut symbols = get_symbols_matching(code, "FooInner");
545
546 let s = symbols.pop().unwrap();
547
548 assert_eq!(s.name, "FooInner");
549 assert!(s.container_name.is_none());
550 }
551
552 #[test]
553 fn test_world_symbols_include_container_name() {
554 let code = r#"
555fn foo() {
556 enum FooInner { }
557}
558 "#;
559
560 let mut symbols = get_symbols_matching(code, "FooInner");
561
562 let s = symbols.pop().unwrap();
563
564 assert_eq!(s.name, "FooInner");
565 assert_eq!(s.container_name, Some(SmolStr::new("foo")));
566
567 let code = r#"
568mod foo {
569 struct FooInner;
570}
571 "#;
572
573 let mut symbols = get_symbols_matching(code, "FooInner");
574
575 let s = symbols.pop().unwrap();
576
577 assert_eq!(s.name, "FooInner");
578 assert_eq!(s.container_name, Some(SmolStr::new("foo")));
579 }
580
581 #[test]
582 fn test_world_symbols_are_case_sensitive() {
583 let code = r#"
584fn foo() {}
585
586struct Foo;
587 "#;
588
589 let symbols = get_symbols_matching(code, "Foo");
590
591 let fn_match = symbols.iter().find(|s| s.name == "foo").map(|s| s.kind);
592 let struct_match = symbols.iter().find(|s| s.name == "Foo").map(|s| s.kind);
593
594 assert_eq!(fn_match, Some(FN_DEF));
595 assert_eq!(struct_match, Some(STRUCT_DEF));
596 }
597
598 fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> {
599 let (analysis, _) = single_file(text);
600 analysis.symbol_search(Query::new(query.into())).unwrap()
601 }
602}