aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests
diff options
context:
space:
mode:
authoruHOOCCOOHu <[email protected]>2019-09-09 13:54:02 +0100
committeruHOOCCOOHu <[email protected]>2019-09-09 13:54:02 +0100
commit40f91341595508833d39eb6d97e4ec2ac7f685cb (patch)
tree3022252410b228efb6501e9e8ff6268c910c87cb /crates/ra_hir/src/nameres/tests
parent734a43e95afc97773c234956a95b78caed88f2a3 (diff)
Make macro scope a real name scope
Fix some details about module scoping
Diffstat (limited to 'crates/ra_hir/src/nameres/tests')
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs119
1 files changed, 109 insertions, 10 deletions
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index ebc4d6890..20ee63c67 100644
--- a/crates/ra_hir/src/nameres/tests/macros.rs
+++ b/crates/ra_hir/src/nameres/tests/macros.rs
@@ -21,7 +21,6 @@ fn macro_rules_are_globally_visible() {
21 ⋮crate 21 ⋮crate
22 ⋮Foo: t v 22 ⋮Foo: t v
23 ⋮nested: t 23 ⋮nested: t
24 ⋮structs: m
25 24
26 ⋮crate::nested 25 ⋮crate::nested
27 ⋮Bar: t v 26 ⋮Bar: t v
@@ -47,7 +46,6 @@ fn macro_rules_can_define_modules() {
47 ); 46 );
48 assert_snapshot!(map, @r###" 47 assert_snapshot!(map, @r###"
49 ⋮crate 48 ⋮crate
50 ⋮m: m
51 ⋮n1: t 49 ⋮n1: t
52 50
53 ⋮crate::n1 51 ⋮crate::n1
@@ -133,7 +131,6 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
133 ⋮crate 131 ⋮crate
134 ⋮Foo: t v 132 ⋮Foo: t v
135 ⋮bar: m 133 ⋮bar: m
136 ⋮baz: m
137 ⋮foo: m 134 ⋮foo: m
138 "###); 135 "###);
139} 136}
@@ -271,7 +268,6 @@ fn prelude_cycle() {
271 ⋮prelude: t 268 ⋮prelude: t
272 269
273 ⋮crate::prelude 270 ⋮crate::prelude
274 ⋮declare_mod: m
275 "###); 271 "###);
276} 272}
277 273
@@ -345,7 +341,6 @@ fn plain_macros_are_legacy_textual_scoped() {
345 ⋮Ok: t v 341 ⋮Ok: t v
346 ⋮OkAfter: t v 342 ⋮OkAfter: t v
347 ⋮OkShadowStop: t v 343 ⋮OkShadowStop: t v
348 ⋮foo: m
349 ⋮m1: t 344 ⋮m1: t
350 ⋮m2: t 345 ⋮m2: t
351 ⋮m3: t 346 ⋮m3: t
@@ -354,28 +349,132 @@ fn plain_macros_are_legacy_textual_scoped() {
354 ⋮ok_double_macro_use_shadow: v 349 ⋮ok_double_macro_use_shadow: v
355 350
356 ⋮crate::m7 351 ⋮crate::m7
357 ⋮baz: m
358 352
359 ⋮crate::m1 353 ⋮crate::m1
360 ⋮bar: m
361 354
362 ⋮crate::m5 355 ⋮crate::m5
363 ⋮m6: t 356 ⋮m6: t
364 357
365 ⋮crate::m5::m6 358 ⋮crate::m5::m6
366 ⋮foo: m
367 359
368 ⋮crate::m2 360 ⋮crate::m2
369 361
370 ⋮crate::m3 362 ⋮crate::m3
371 ⋮OkAfterInside: t v 363 ⋮OkAfterInside: t v
372 ⋮OkMacroUse: t v 364 ⋮OkMacroUse: t v
373 ⋮foo: m
374 ⋮m4: t 365 ⋮m4: t
375 ⋮ok_shadow: v 366 ⋮ok_shadow: v
376 367
377 ⋮crate::m3::m4 368 ⋮crate::m3::m4
378 ⋮bar: m
379 ⋮ok_shadow_deep: v 369 ⋮ok_shadow_deep: v
380 "###); 370 "###);
381} 371}
372
373#[test]
374fn type_value_macro_live_in_different_scopes() {
375 let map = def_map(
376 "
377 //- /main.rs
378 #[macro_export]
379 macro_rules! foo {
380 ($x:ident) => { type $x = (); }
381 }
382
383 foo!(foo);
384 use foo as bar;
385
386 use self::foo as baz;
387 fn baz() {}
388 ",
389 );
390 assert_snapshot!(map, @r###"
391 ⋮crate
392 ⋮bar: t m
393 ⋮baz: t v m
394 ⋮foo: t m
395 "###);
396}
397
398#[test]
399fn macro_use_can_be_aliased() {
400 let map = def_map_with_crate_graph(
401 "
402 //- /main.rs
403 #[macro_use]
404 extern crate foo;
405
406 foo!(Direct);
407 bar!(Alias);
408
409 //- /lib.rs
410 use crate::foo as bar;
411
412 mod m {
413 #[macro_export]
414 macro_rules! foo {
415 ($x:ident) => { struct $x; }
416 }
417 }
418 ",
419 crate_graph! {
420 "main": ("/main.rs", ["foo"]),
421 "foo": ("/lib.rs", []),
422 },
423 );
424 assert_snapshot!(map, @r###"
425 ⋮crate
426 ⋮Alias: t v
427 ⋮Direct: t v
428 ⋮foo: t
429 "###);
430}
431
432#[test]
433fn path_quantified_macros() {
434 let map = def_map(
435 "
436 //- /main.rs
437 macro_rules! foo {
438 ($x:ident) => { struct $x; }
439 }
440
441 crate::foo!(NotResolved);
442
443 crate::bar!(OkCrate);
444 bar!(OkPlain);
445 alias1!(NotHere);
446 m::alias1!(OkAliasPlain);
447 m::alias2!(OkAliasSuper);
448 m::alias3!(OkAliasCrate);
449 not_found!(NotFound);
450
451 mod m {
452 #[macro_export]
453 macro_rules! bar {
454 ($x:ident) => { struct $x; }
455 }
456
457 pub use bar as alias1;
458 pub use super::bar as alias2;
459 pub use crate::bar as alias3;
460 pub use self::bar as not_found;
461 }
462 ",
463 );
464 assert_snapshot!(map, @r###"
465 ⋮crate
466 ⋮OkAliasCrate: t v
467 ⋮OkAliasPlain: t v
468 ⋮OkAliasSuper: t v
469 ⋮OkCrate: t v
470 ⋮OkPlain: t v
471 ⋮bar: m
472 ⋮m: t
473
474 ⋮crate::m
475 ⋮alias1: m
476 ⋮alias2: m
477 ⋮alias3: m
478 ⋮not_found: _
479 "###);
480}