aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/nameres/tests/mod_resolution.rs')
-rw-r--r--crates/ra_hir_def/src/nameres/tests/mod_resolution.rs1257
1 files changed, 608 insertions, 649 deletions
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}