aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres/tests.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-06-01 12:39:19 +0100
committerJonas Schievink <[email protected]>2021-06-01 12:39:19 +0100
commitf96c1a0414ee302fe96503d89f2998483345c8a9 (patch)
tree6de19b3c128809cd56641f70873c35f17974aced /crates/hir_def/src/nameres/tests.rs
parent71117e6812f87e014bc8e984e195a75e222ac227 (diff)
Implement per-edition preludes
Diffstat (limited to 'crates/hir_def/src/nameres/tests.rs')
-rw-r--r--crates/hir_def/src/nameres/tests.rs131
1 files changed, 100 insertions, 31 deletions
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs
index 9f652731d..58c01354a 100644
--- a/crates/hir_def/src/nameres/tests.rs
+++ b/crates/hir_def/src/nameres/tests.rs
@@ -246,15 +246,16 @@ fn std_prelude() {
246 check( 246 check(
247 r#" 247 r#"
248//- /main.rs crate:main deps:test_crate 248//- /main.rs crate:main deps:test_crate
249#[prelude_import]
250use ::test_crate::prelude::*;
251
249use Foo::*; 252use Foo::*;
250 253
251//- /lib.rs crate:test_crate 254//- /lib.rs crate:test_crate
252mod prelude; 255pub mod prelude;
253#[prelude_import]
254use prelude::*;
255 256
256//- /prelude.rs 257//- /prelude.rs
257pub enum Foo { Bar, Baz }; 258pub enum Foo { Bar, Baz }
258"#, 259"#,
259 expect![[r#" 260 expect![[r#"
260 crate 261 crate
@@ -467,6 +468,74 @@ pub struct Bar;
467} 468}
468 469
469#[test] 470#[test]
471fn no_std_prelude() {
472 check(
473 r#"
474 //- /main.rs crate:main deps:core,std
475 #![cfg_attr(not(never), no_std)]
476 use Rust;
477
478 //- /core.rs crate:core
479 pub mod prelude {
480 pud mod rust_2018 {
481 pub struct Rust;
482 }
483 }
484 //- /std.rs crate:std deps:core
485 pub mod prelude {
486 pud mod rust_2018 {
487 }
488 }
489 "#,
490 expect![[r#"
491 crate
492 Rust: t v
493 "#]],
494 );
495}
496
497#[test]
498fn edition_specific_preludes() {
499 // We can't test the 2015 prelude here since you can't reexport its contents with 2015's
500 // absolute paths.
501
502 check(
503 r#"
504 //- /main.rs edition:2018 crate:main deps:std
505 use Rust2018;
506
507 //- /std.rs crate:std
508 pub mod prelude {
509 pud mod rust_2018 {
510 pub struct Rust2018;
511 }
512 }
513 "#,
514 expect![[r#"
515 crate
516 Rust2018: t v
517 "#]],
518 );
519 check(
520 r#"
521 //- /main.rs edition:2021 crate:main deps:std
522 use Rust2021;
523
524 //- /std.rs crate:std
525 pub mod prelude {
526 pud mod rust_2021 {
527 pub struct Rust2021;
528 }
529 }
530 "#,
531 expect![[r#"
532 crate
533 Rust2021: t v
534 "#]],
535 );
536}
537
538#[test]
470fn std_prelude_takes_precedence_above_core_prelude() { 539fn std_prelude_takes_precedence_above_core_prelude() {
471 check( 540 check(
472 r#" 541 r#"
@@ -474,18 +543,18 @@ fn std_prelude_takes_precedence_above_core_prelude() {
474use {Foo, Bar}; 543use {Foo, Bar};
475 544
476//- /std.rs crate:std deps:core 545//- /std.rs crate:std deps:core
477#[prelude_import] 546pub mod prelude {
478pub use self::prelude::*; 547 pub mod rust_2018 {
479mod prelude { 548 pub struct Foo;
480 pub struct Foo; 549 pub use core::prelude::rust_2018::Bar;
481 pub use core::prelude::Bar; 550 }
482} 551}
483 552
484//- /core.rs crate:core 553//- /core.rs crate:core
485#[prelude_import] 554pub mod prelude {
486pub use self::prelude::*; 555 pub mod rust_2018 {
487mod prelude { 556 pub struct Bar;
488 pub struct Bar; 557 }
489} 558}
490"#, 559"#,
491 expect![[r#" 560 expect![[r#"
@@ -504,15 +573,15 @@ fn cfg_not_test() {
504use {Foo, Bar, Baz}; 573use {Foo, Bar, Baz};
505 574
506//- /lib.rs crate:std 575//- /lib.rs crate:std
507#[prelude_import] 576pub mod prelude {
508pub use self::prelude::*; 577 pub mod rust_2018 {
509mod prelude { 578 #[cfg(test)]
510 #[cfg(test)] 579 pub struct Foo;
511 pub struct Foo; 580 #[cfg(not(test))]
512 #[cfg(not(test))] 581 pub struct Bar;
513 pub struct Bar; 582 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
514 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] 583 pub struct Baz;
515 pub struct Baz; 584 }
516} 585}
517"#, 586"#,
518 expect![[r#" 587 expect![[r#"
@@ -532,15 +601,15 @@ fn cfg_test() {
532use {Foo, Bar, Baz}; 601use {Foo, Bar, Baz};
533 602
534//- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42 603//- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42
535#[prelude_import] 604pub mod prelude {
536pub use self::prelude::*; 605 pub mod rust_2018 {
537mod prelude { 606 #[cfg(test)]
538 #[cfg(test)] 607 pub struct Foo;
539 pub struct Foo; 608 #[cfg(not(test))]
540 #[cfg(not(test))] 609 pub struct Bar;
541 pub struct Bar; 610 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
542 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] 611 pub struct Baz;
543 pub struct Baz; 612 }
544} 613}
545"#, 614"#,
546 expect![[r#" 615 expect![[r#"