9 use base_db
::{fixture::WithFixture, SourceDatabase}
;
10 use expect_test
::{expect, Expect}
;
12 use crate::{db::DefDatabase, test_db::TestDB}
;
16 fn compute_crate_def_map(ra_fixture
: &str) -> Arc
<DefMap
> {
17 let db
= TestDB
::with_files(ra_fixture
);
18 let krate
= db
.crate_graph().iter().next().unwrap();
19 db
.crate_def_map(krate
)
22 fn render_crate_def_map(ra_fixture
: &str) -> String
{
23 let db
= TestDB
::with_files(ra_fixture
);
24 let krate
= db
.crate_graph().iter().next().unwrap();
25 db
.crate_def_map(krate
).dump(&db
)
28 fn check(ra_fixture
: &str, expect
: Expect
) {
29 let actual
= render_crate_def_map(ra_fixture
);
30 expect
.assert_eq(&actual
);
34 fn crate_def_map_smoke_test() {
40 use crate::foo::bar::E;
50 union U { to_be: bool, not_to_be: u8 }
82 fn crate_def_map_super_super() {
115 fn crate_def_map_fn_mod_same_name() {
137 cov_mark
::check
!(bogus_paths
);
165 use crate::foo::Baz as Foo;
187 use crate::foo::bar::{Baz, Quux};
222 pub use self::bar::Baz;
244 cov_mark
::check
!(std_prelude
);
247 //- /main.rs crate:main deps:test_crate
249 use ::test_crate::prelude::*;
253 //- /lib.rs crate:test_crate
257 pub enum Foo { Bar, Baz }
268 fn can_import_enum_variant() {
269 cov_mark
::check
!(can_import_enum_variant
);
284 fn edition_2015_imports() {
287 //- /main.rs crate:main deps:other_crate edition:2015
296 use other_crate::FromLib;
298 //- /lib.rs crate:other_crate edition:2018
317 fn item_map_using_self() {
322 use crate::foo::bar::Baz::{self};
345 fn item_map_across_crates() {
348 //- /main.rs crate:main deps:test_crate
351 //- /lib.rs crate:test_crate
362 fn extern_crate_rename() {
365 //- /main.rs crate:main deps:alloc
366 extern crate alloc as alloc_crate;
371 use alloc_crate::Arc;
373 //- /lib.rs crate:alloc
391 fn extern_crate_rename_2015_edition() {
394 //- /main.rs crate:main deps:alloc edition:2015
395 extern crate alloc as alloc_crate;
400 use alloc_crate::Arc;
402 //- /lib.rs crate:alloc
420 fn macro_use_extern_crate_self() {
421 cov_mark
::check
!(ignore_macro_use_extern_crate_self
);
424 //- /main.rs crate:main
426 extern crate self as bla;
436 fn reexport_across_crates() {
439 //- /main.rs crate:main deps:test_crate
442 //- /lib.rs crate:test_crate
457 fn values_dont_shadow_extern_crates() {
460 //- /main.rs crate:main deps:foo
464 //- /foo/lib.rs crate:foo
476 fn no_std_prelude() {
479 //- /main.rs edition:2018 crate:main deps:core,std
480 #![cfg_attr(not(never), no_std)]
483 //- /core.rs crate:core
489 //- /std.rs crate:std deps:core
503 fn edition_specific_preludes() {
504 // We can't test the 2015 prelude here since you can't reexport its contents with 2015's
509 //- /main.rs edition:2018 crate:main deps:std
512 //- /std.rs crate:std
526 //- /main.rs edition:2021 crate:main deps:std
529 //- /std.rs crate:std
544 fn std_prelude_takes_precedence_above_core_prelude() {
547 //- /main.rs edition:2018 crate:main deps:core,std
550 //- /std.rs crate:std deps:core
554 pub use core::prelude::rust_2018::Bar;
558 //- /core.rs crate:core
577 //- /main.rs edition:2018 crate:main deps:std
580 //- /lib.rs crate:std
587 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
605 //- /main.rs edition:2018 crate:main deps:std
608 //- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42
615 #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
630 fn infer_multiple_namespace() {
642 pub const T: () = ();
661 fn underscore_import() {
687 fn underscore_reexport() {
696 use crate::tr::PrivTr as _;
697 pub use crate::tr::PubTr as _;
719 fn underscore_pub_crate_reexport() {
720 cov_mark
::check
!(upgrade_underscore_visibility
);
723 //- /main.rs crate:main deps:lib
726 //- /lib.rs crate:lib
742 fn underscore_nontrait() {
749 pub const CONST: () = ();
751 use crate::m::{Struct as _, Enum as _, CONST as _};
766 fn underscore_name_conflict() {
791 fn cfg_the_entire_crate() {
827 fn self_imports_only_types() {
836 use self::m::S::{self};
850 fn import_from_extern_crate_only_imports_public_items() {
853 //- /lib.rs crate:lib deps:settings,macros
854 use macros::settings;
855 use settings::Settings;
856 //- /settings.rs crate:settings
858 //- /macros.rs crate:macros
860 pub const settings: () = ();
871 fn non_prelude_deps() {
874 //- /lib.rs crate:lib deps:dep extern-prelude:
876 //- /dep.rs crate:dep
886 //- /lib.rs crate:lib deps:dep extern-prelude:
889 //- /dep.rs crate:dep
901 fn braced_supers_in_use_tree() {
902 cov_mark
::check
!(concat_super_mod_paths
);
906 pub fn unknown_func() {}
911 use { super::{ super::unknown_func, }, };
915 use some_module::unknown_func;
926 crate::other_module::some_submodule