2019-03-14 03:53:40 -05:00
|
|
|
mod globs;
|
|
|
|
mod incremental;
|
2019-11-03 14:35:48 -06:00
|
|
|
mod macros;
|
2019-09-05 13:43:32 -05:00
|
|
|
mod mod_resolution;
|
2019-11-03 14:35:48 -06:00
|
|
|
mod primitives;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2019-03-13 08:04:28 -05:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2021-02-01 06:20:35 -06:00
|
|
|
use base_db::{fixture::WithFixture, SourceDatabase};
|
2020-08-21 06:19:31 -05:00
|
|
|
use expect_test::{expect, Expect};
|
2019-03-13 08:04:28 -05:00
|
|
|
|
2021-02-04 06:44:54 -06:00
|
|
|
use crate::{db::DefDatabase, test_db::TestDB};
|
|
|
|
|
|
|
|
use super::DefMap;
|
2019-03-13 08:04:28 -05:00
|
|
|
|
2021-01-18 13:18:05 -06:00
|
|
|
fn compute_crate_def_map(ra_fixture: &str) -> Arc<DefMap> {
|
2020-12-18 18:12:41 -06:00
|
|
|
let db = TestDB::with_files(ra_fixture);
|
2019-10-31 10:45:10 -05:00
|
|
|
let krate = db.crate_graph().iter().next().unwrap();
|
2019-03-13 08:38:02 -05:00
|
|
|
db.crate_def_map(krate)
|
2019-03-13 08:04:28 -05:00
|
|
|
}
|
|
|
|
|
2021-02-04 06:44:54 -06:00
|
|
|
fn render_crate_def_map(ra_fixture: &str) -> String {
|
|
|
|
let db = TestDB::with_files(ra_fixture);
|
|
|
|
let krate = db.crate_graph().iter().next().unwrap();
|
|
|
|
db.crate_def_map(krate).dump(&db)
|
|
|
|
}
|
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
fn check(ra_fixture: &str, expect: Expect) {
|
2021-02-04 06:44:54 -06:00
|
|
|
let actual = render_crate_def_map(ra_fixture);
|
2020-07-17 07:37:51 -05:00
|
|
|
expect.assert_eq(&actual);
|
|
|
|
}
|
|
|
|
|
2019-03-13 08:04:28 -05:00
|
|
|
#[test]
|
|
|
|
fn crate_def_map_smoke_test() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
struct S;
|
|
|
|
use crate::foo::bar::E;
|
|
|
|
use self::E::V;
|
2019-11-25 08:30:50 -06:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/mod.rs
|
|
|
|
pub mod bar;
|
|
|
|
fn f() {}
|
2020-04-23 16:10:14 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/bar.rs
|
|
|
|
pub struct Baz;
|
|
|
|
|
|
|
|
union U { to_be: bool, not_to_be: u8 }
|
|
|
|
enum E { V }
|
|
|
|
|
|
|
|
extern {
|
2020-08-24 15:02:55 -05:00
|
|
|
type Ext;
|
2020-07-17 07:37:51 -05:00
|
|
|
static EXT: u8;
|
|
|
|
fn ext();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
E: t
|
|
|
|
S: t v
|
|
|
|
V: t v
|
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
bar: t
|
|
|
|
f: v
|
|
|
|
|
|
|
|
crate::foo::bar
|
|
|
|
Baz: t v
|
|
|
|
E: t
|
|
|
|
EXT: v
|
2020-08-24 15:02:55 -05:00
|
|
|
Ext: t
|
2020-07-17 07:37:51 -05:00
|
|
|
U: t
|
|
|
|
ext: v
|
|
|
|
"#]],
|
2019-03-13 08:04:28 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-29 21:48:55 -06:00
|
|
|
#[test]
|
|
|
|
fn crate_def_map_super_super() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod a {
|
|
|
|
const A: usize = 0;
|
|
|
|
mod b {
|
|
|
|
const B: usize = 0;
|
|
|
|
mod c {
|
|
|
|
use super::super::*;
|
2020-02-29 21:48:55 -06:00
|
|
|
}
|
2020-07-17 07:37:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
a: t
|
|
|
|
|
|
|
|
crate::a
|
|
|
|
A: v
|
|
|
|
b: t
|
|
|
|
|
|
|
|
crate::a::b
|
|
|
|
B: v
|
|
|
|
c: t
|
|
|
|
|
|
|
|
crate::a::b::c
|
|
|
|
A: v
|
|
|
|
b: t
|
|
|
|
"#]],
|
2020-02-29 21:48:55 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-10 21:58:17 -05:00
|
|
|
#[test]
|
|
|
|
fn crate_def_map_fn_mod_same_name() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod m {
|
|
|
|
pub mod z {}
|
|
|
|
pub fn z() {}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
m: t
|
|
|
|
|
|
|
|
crate::m
|
|
|
|
z: t v
|
|
|
|
|
|
|
|
crate::m::z
|
|
|
|
"#]],
|
2020-03-10 21:58:17 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-16 10:06:45 -05:00
|
|
|
#[test]
|
|
|
|
fn bogus_paths() {
|
2021-03-08 14:19:44 -06:00
|
|
|
cov_mark::check!(bogus_paths);
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
struct S;
|
|
|
|
use self;
|
|
|
|
|
|
|
|
//- /foo/mod.rs
|
|
|
|
use super;
|
|
|
|
use crate;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
S: t v
|
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
"#]],
|
2019-03-16 10:06:45 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-13 08:04:28 -05:00
|
|
|
#[test]
|
2019-03-14 03:53:40 -05:00
|
|
|
fn use_as() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
use crate::foo::Baz as Foo;
|
2019-03-13 08:04:28 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/mod.rs
|
|
|
|
pub struct Baz;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Foo: t v
|
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
Baz: t v
|
|
|
|
"#]],
|
2019-03-14 03:53:40 -05:00
|
|
|
);
|
2019-03-13 08:04:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-03-14 03:53:40 -05:00
|
|
|
fn use_trees() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
use crate::foo::bar::{Baz, Quux};
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/mod.rs
|
|
|
|
pub mod bar;
|
2019-03-13 08:04:28 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/bar.rs
|
|
|
|
pub struct Baz;
|
|
|
|
pub enum Quux {};
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Baz: t v
|
|
|
|
Quux: t
|
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
bar: t
|
|
|
|
|
|
|
|
crate::foo::bar
|
|
|
|
Baz: t v
|
|
|
|
Quux: t
|
|
|
|
"#]],
|
2019-03-13 08:04:28 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-03-14 03:53:40 -05:00
|
|
|
fn re_exports() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
use self::foo::Baz;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/mod.rs
|
|
|
|
pub mod bar;
|
|
|
|
pub use self::bar::Baz;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/bar.rs
|
|
|
|
pub struct Baz;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Baz: t v
|
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
Baz: t v
|
|
|
|
bar: t
|
|
|
|
|
|
|
|
crate::foo::bar
|
|
|
|
Baz: t v
|
|
|
|
"#]],
|
2019-03-13 08:04:28 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn std_prelude() {
|
2021-03-08 14:19:44 -06:00
|
|
|
cov_mark::check!(std_prelude);
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:test_crate
|
2021-06-01 06:39:19 -05:00
|
|
|
#[prelude_import]
|
|
|
|
use ::test_crate::prelude::*;
|
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
use Foo::*;
|
|
|
|
|
|
|
|
//- /lib.rs crate:test_crate
|
2021-06-01 06:39:19 -05:00
|
|
|
pub mod prelude;
|
2020-07-17 07:37:51 -05:00
|
|
|
|
|
|
|
//- /prelude.rs
|
2021-06-01 06:39:19 -05:00
|
|
|
pub enum Foo { Bar, Baz }
|
2020-07-17 07:37:51 -05:00
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Bar: t v
|
|
|
|
Baz: t v
|
|
|
|
"#]],
|
2019-03-13 08:04:28 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-03-14 03:53:40 -05:00
|
|
|
fn can_import_enum_variant() {
|
2021-03-08 14:19:44 -06:00
|
|
|
cov_mark::check!(can_import_enum_variant);
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum E { V }
|
|
|
|
use self::E::V;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
E: t
|
|
|
|
V: t v
|
|
|
|
"#]],
|
2019-03-14 03:53:40 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn edition_2015_imports() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:other_crate edition:2015
|
|
|
|
mod foo;
|
|
|
|
mod bar;
|
|
|
|
|
|
|
|
//- /bar.rs
|
|
|
|
struct Bar;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo.rs
|
|
|
|
use bar::Bar;
|
|
|
|
use other_crate::FromLib;
|
|
|
|
|
|
|
|
//- /lib.rs crate:other_crate edition:2018
|
2021-07-21 10:51:56 -05:00
|
|
|
pub struct FromLib;
|
2020-07-17 07:37:51 -05:00
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
bar: t
|
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::bar
|
|
|
|
Bar: t v
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
Bar: t v
|
|
|
|
FromLib: t v
|
|
|
|
"#]],
|
|
|
|
);
|
2019-03-14 03:53:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn item_map_using_self() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
use crate::foo::bar::Baz::{self};
|
|
|
|
|
|
|
|
//- /foo/mod.rs
|
|
|
|
pub mod bar;
|
|
|
|
|
|
|
|
//- /foo/bar.rs
|
|
|
|
pub struct Baz;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
2021-06-28 13:11:58 -05:00
|
|
|
Baz: t
|
2020-07-17 07:37:51 -05:00
|
|
|
foo: t
|
|
|
|
|
|
|
|
crate::foo
|
|
|
|
bar: t
|
|
|
|
|
|
|
|
crate::foo::bar
|
|
|
|
Baz: t v
|
|
|
|
"#]],
|
2019-03-14 03:53:40 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn item_map_across_crates() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:test_crate
|
|
|
|
use test_crate::Baz;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /lib.rs crate:test_crate
|
|
|
|
pub struct Baz;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Baz: t v
|
|
|
|
"#]],
|
|
|
|
);
|
2019-03-13 08:04:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-03-14 03:53:40 -05:00
|
|
|
fn extern_crate_rename() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:alloc
|
|
|
|
extern crate alloc as alloc_crate;
|
|
|
|
mod alloc;
|
|
|
|
mod sync;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /sync.rs
|
|
|
|
use alloc_crate::Arc;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /lib.rs crate:alloc
|
2021-07-21 10:51:56 -05:00
|
|
|
pub struct Arc;
|
2020-07-17 07:37:51 -05:00
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
alloc_crate: t
|
|
|
|
sync: t
|
|
|
|
|
|
|
|
crate::sync
|
|
|
|
Arc: t v
|
|
|
|
"#]],
|
2019-03-13 08:04:28 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-03-14 03:53:40 -05:00
|
|
|
fn extern_crate_rename_2015_edition() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:alloc edition:2015
|
|
|
|
extern crate alloc as alloc_crate;
|
|
|
|
mod alloc;
|
|
|
|
mod sync;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /sync.rs
|
|
|
|
use alloc_crate::Arc;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /lib.rs crate:alloc
|
2021-07-21 10:51:56 -05:00
|
|
|
pub struct Arc;
|
2020-07-17 07:37:51 -05:00
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
alloc_crate: t
|
|
|
|
sync: t
|
|
|
|
|
|
|
|
crate::sync
|
|
|
|
Arc: t v
|
|
|
|
"#]],
|
2019-03-14 03:53:40 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:05:52 -05:00
|
|
|
#[test]
|
2021-05-17 04:37:24 -05:00
|
|
|
fn macro_use_extern_crate_self() {
|
|
|
|
cov_mark::check!(ignore_macro_use_extern_crate_self);
|
2021-05-16 13:05:52 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main
|
|
|
|
#[macro_use]
|
|
|
|
extern crate self as bla;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
bla: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-14 03:53:40 -05:00
|
|
|
#[test]
|
|
|
|
fn reexport_across_crates() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:test_crate
|
|
|
|
use test_crate::Baz;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /lib.rs crate:test_crate
|
|
|
|
pub use foo::Baz;
|
|
|
|
mod foo;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo.rs
|
|
|
|
pub struct Baz;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Baz: t v
|
|
|
|
"#]],
|
2019-03-14 03:53:40 -05:00
|
|
|
);
|
2019-03-13 08:04:28 -05:00
|
|
|
}
|
2019-03-14 03:53:40 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn values_dont_shadow_extern_crates() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:foo
|
|
|
|
fn foo() {}
|
|
|
|
use foo::Bar;
|
2019-03-14 03:53:40 -05:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /foo/lib.rs crate:foo
|
|
|
|
pub struct Bar;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Bar: t v
|
|
|
|
foo: v
|
|
|
|
"#]],
|
|
|
|
);
|
2019-03-14 03:53:40 -05:00
|
|
|
}
|
2019-09-29 18:38:16 -05:00
|
|
|
|
2021-06-01 06:39:19 -05:00
|
|
|
#[test]
|
|
|
|
fn no_std_prelude() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:core,std
|
|
|
|
#![cfg_attr(not(never), no_std)]
|
|
|
|
use Rust;
|
|
|
|
|
|
|
|
//- /core.rs crate:core
|
|
|
|
pub mod prelude {
|
2021-07-21 10:51:56 -05:00
|
|
|
pub mod rust_2018 {
|
2021-06-01 06:39:19 -05:00
|
|
|
pub struct Rust;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//- /std.rs crate:std deps:core
|
|
|
|
pub mod prelude {
|
2021-07-21 10:51:56 -05:00
|
|
|
pub mod rust_2018 {
|
2021-06-01 06:39:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Rust: t v
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn edition_specific_preludes() {
|
|
|
|
// We can't test the 2015 prelude here since you can't reexport its contents with 2015's
|
|
|
|
// absolute paths.
|
|
|
|
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs edition:2018 crate:main deps:std
|
|
|
|
use Rust2018;
|
|
|
|
|
|
|
|
//- /std.rs crate:std
|
|
|
|
pub mod prelude {
|
2021-07-21 10:51:56 -05:00
|
|
|
pub mod rust_2018 {
|
2021-06-01 06:39:19 -05:00
|
|
|
pub struct Rust2018;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Rust2018: t v
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs edition:2021 crate:main deps:std
|
|
|
|
use Rust2021;
|
|
|
|
|
|
|
|
//- /std.rs crate:std
|
|
|
|
pub mod prelude {
|
2021-07-21 10:51:56 -05:00
|
|
|
pub mod rust_2021 {
|
2021-06-01 06:39:19 -05:00
|
|
|
pub struct Rust2021;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Rust2021: t v
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-09 19:38:08 -06:00
|
|
|
#[test]
|
|
|
|
fn std_prelude_takes_precedence_above_core_prelude() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
2019-11-09 19:38:08 -06:00
|
|
|
r#"
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /main.rs crate:main deps:core,std
|
|
|
|
use {Foo, Bar};
|
|
|
|
|
|
|
|
//- /std.rs crate:std deps:core
|
2021-06-01 06:39:19 -05:00
|
|
|
pub mod prelude {
|
|
|
|
pub mod rust_2018 {
|
|
|
|
pub struct Foo;
|
|
|
|
pub use core::prelude::rust_2018::Bar;
|
|
|
|
}
|
2020-07-17 07:37:51 -05:00
|
|
|
}
|
2019-11-09 19:38:08 -06:00
|
|
|
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /core.rs crate:core
|
2021-06-01 06:39:19 -05:00
|
|
|
pub mod prelude {
|
|
|
|
pub mod rust_2018 {
|
|
|
|
pub struct Bar;
|
|
|
|
}
|
2020-07-17 07:37:51 -05:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Bar: t v
|
|
|
|
Foo: t v
|
|
|
|
"#]],
|
2019-11-09 19:38:08 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-29 18:38:16 -05:00
|
|
|
#[test]
|
|
|
|
fn cfg_not_test() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
2019-09-29 18:38:16 -05:00
|
|
|
r#"
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /main.rs crate:main deps:std
|
|
|
|
use {Foo, Bar, Baz};
|
|
|
|
|
|
|
|
//- /lib.rs crate:std
|
2021-06-01 06:39:19 -05:00
|
|
|
pub mod prelude {
|
|
|
|
pub mod rust_2018 {
|
|
|
|
#[cfg(test)]
|
|
|
|
pub struct Foo;
|
|
|
|
#[cfg(not(test))]
|
|
|
|
pub struct Bar;
|
|
|
|
#[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
|
|
|
|
pub struct Baz;
|
|
|
|
}
|
2020-07-17 07:37:51 -05:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Bar: t v
|
|
|
|
Baz: _
|
|
|
|
Foo: _
|
|
|
|
"#]],
|
2019-09-29 18:38:16 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cfg_test() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
2019-09-29 18:38:16 -05:00
|
|
|
r#"
|
2020-07-17 07:37:51 -05:00
|
|
|
//- /main.rs crate:main deps:std
|
|
|
|
use {Foo, Bar, Baz};
|
|
|
|
|
|
|
|
//- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42
|
2021-06-01 06:39:19 -05:00
|
|
|
pub mod prelude {
|
|
|
|
pub mod rust_2018 {
|
|
|
|
#[cfg(test)]
|
|
|
|
pub struct Foo;
|
|
|
|
#[cfg(not(test))]
|
|
|
|
pub struct Bar;
|
|
|
|
#[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))]
|
|
|
|
pub struct Baz;
|
|
|
|
}
|
2020-07-17 07:37:51 -05:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Bar: _
|
|
|
|
Baz: t v
|
|
|
|
Foo: t v
|
|
|
|
"#]],
|
2019-09-29 18:38:16 -05:00
|
|
|
);
|
|
|
|
}
|
2019-12-03 05:33:48 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn infer_multiple_namespace() {
|
2020-07-17 07:37:51 -05:00
|
|
|
check(
|
2019-12-03 05:33:48 -06:00
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
mod a {
|
|
|
|
pub type T = ();
|
|
|
|
pub use crate::b::*;
|
|
|
|
}
|
|
|
|
|
|
|
|
use crate::a::T;
|
|
|
|
|
|
|
|
mod b {
|
|
|
|
pub const T: () = ();
|
|
|
|
}
|
|
|
|
"#,
|
2020-07-17 07:37:51 -05:00
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
T: t v
|
|
|
|
a: t
|
|
|
|
b: t
|
|
|
|
|
|
|
|
crate::b
|
|
|
|
T: v
|
|
|
|
|
|
|
|
crate::a
|
|
|
|
T: t v
|
|
|
|
"#]],
|
2019-12-03 05:33:48 -06:00
|
|
|
);
|
|
|
|
}
|
2020-07-21 10:52:43 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn underscore_import() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
use tr::Tr as _;
|
|
|
|
use tr::Tr2 as _;
|
|
|
|
|
|
|
|
mod tr {
|
|
|
|
pub trait Tr {}
|
|
|
|
pub trait Tr2 {}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
_: t
|
|
|
|
_: t
|
|
|
|
tr: t
|
|
|
|
|
|
|
|
crate::tr
|
|
|
|
Tr: t
|
|
|
|
Tr2: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn underscore_reexport() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
mod tr {
|
|
|
|
pub trait PubTr {}
|
|
|
|
pub trait PrivTr {}
|
|
|
|
}
|
|
|
|
mod reex {
|
|
|
|
use crate::tr::PrivTr as _;
|
|
|
|
pub use crate::tr::PubTr as _;
|
|
|
|
}
|
|
|
|
use crate::reex::*;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
_: t
|
|
|
|
reex: t
|
|
|
|
tr: t
|
|
|
|
|
|
|
|
crate::tr
|
|
|
|
PrivTr: t
|
|
|
|
PubTr: t
|
|
|
|
|
|
|
|
crate::reex
|
|
|
|
_: t
|
|
|
|
_: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn underscore_pub_crate_reexport() {
|
2021-03-08 14:19:44 -06:00
|
|
|
cov_mark::check!(upgrade_underscore_visibility);
|
2020-07-21 10:52:43 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs crate:main deps:lib
|
|
|
|
use lib::*;
|
|
|
|
|
|
|
|
//- /lib.rs crate:lib
|
|
|
|
use tr::Tr as _;
|
|
|
|
pub use tr::Tr as _;
|
|
|
|
|
|
|
|
mod tr {
|
2020-07-22 07:01:50 -05:00
|
|
|
pub trait Tr {}
|
2020-07-21 10:52:43 -05:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
_: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn underscore_nontrait() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
mod m {
|
|
|
|
pub struct Struct;
|
|
|
|
pub enum Enum {}
|
|
|
|
pub const CONST: () = ();
|
|
|
|
}
|
|
|
|
use crate::m::{Struct as _, Enum as _, CONST as _};
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
m: t
|
|
|
|
|
|
|
|
crate::m
|
|
|
|
CONST: v
|
|
|
|
Enum: t
|
|
|
|
Struct: t v
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn underscore_name_conflict() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
struct Tr;
|
|
|
|
|
|
|
|
use tr::Tr as _;
|
|
|
|
|
|
|
|
mod tr {
|
|
|
|
pub trait Tr {}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
_: t
|
|
|
|
Tr: t v
|
|
|
|
tr: t
|
|
|
|
|
|
|
|
crate::tr
|
|
|
|
Tr: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2020-10-26 10:04:08 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cfg_the_entire_crate() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
#![cfg(never)]
|
|
|
|
|
|
|
|
pub struct S;
|
|
|
|
pub enum E {}
|
|
|
|
pub fn f() {}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-03-17 16:24:51 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn use_crate_as() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
use crate as foo;
|
|
|
|
|
|
|
|
use foo::bar as baz;
|
|
|
|
|
|
|
|
fn bar() {}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
bar: v
|
|
|
|
baz: v
|
|
|
|
foo: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-06-28 13:11:58 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn self_imports_only_types() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /main.rs
|
|
|
|
mod m {
|
|
|
|
pub macro S() {}
|
|
|
|
pub struct S;
|
|
|
|
}
|
|
|
|
|
|
|
|
use self::m::S::{self};
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
S: t
|
|
|
|
m: t
|
|
|
|
|
|
|
|
crate::m
|
|
|
|
S: t v m
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-07-21 10:51:56 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn import_from_extern_crate_only_imports_public_items() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:lib deps:settings,macros
|
|
|
|
use macros::settings;
|
|
|
|
use settings::Settings;
|
|
|
|
//- /settings.rs crate:settings
|
|
|
|
pub struct Settings;
|
|
|
|
//- /macros.rs crate:macros
|
|
|
|
mod settings {}
|
|
|
|
pub const settings: () = ();
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Settings: t v
|
|
|
|
settings: v
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
2021-09-28 14:23:46 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn non_prelude_deps() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:lib deps:dep extern-prelude:
|
|
|
|
use dep::Struct;
|
|
|
|
//- /dep.rs crate:dep
|
|
|
|
pub struct Struct;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Struct: _
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:lib deps:dep extern-prelude:
|
|
|
|
extern crate dep;
|
|
|
|
use dep::Struct;
|
|
|
|
//- /dep.rs crate:dep
|
|
|
|
pub struct Struct;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
crate
|
|
|
|
Struct: t v
|
|
|
|
dep: t
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|