aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_db/src/fixture.rs18
-rw-r--r--crates/ra_hir_def/src/nameres/tests.rs25
-rw-r--r--crates/test_utils/src/fixture.rs12
3 files changed, 2 insertions, 53 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index f7d9118a9..bf897baff 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -114,7 +114,6 @@ fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId
114 let crate_graph = if let Some(entry) = fixture { 114 let crate_graph = if let Some(entry) = fixture {
115 let meta = match ParsedMeta::from(&entry.meta) { 115 let meta = match ParsedMeta::from(&entry.meta) {
116 ParsedMeta::File(it) => it, 116 ParsedMeta::File(it) => it,
117 _ => panic!("with_single_file only support file meta"),
118 }; 117 };
119 118
120 let mut crate_graph = CrateGraph::default(); 119 let mut crate_graph = CrateGraph::default();
@@ -159,21 +158,14 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
159 let mut default_crate_root: Option<FileId> = None; 158 let mut default_crate_root: Option<FileId> = None;
160 159
161 let mut file_set = FileSet::default(); 160 let mut file_set = FileSet::default();
162 let mut source_root_id = WORKSPACE; 161 let source_root_id = WORKSPACE;
163 let mut source_root_prefix = "/".to_string(); 162 let source_root_prefix = "/".to_string();
164 let mut file_id = FileId(0); 163 let mut file_id = FileId(0);
165 164
166 let mut file_position = None; 165 let mut file_position = None;
167 166
168 for entry in fixture.iter() { 167 for entry in fixture.iter() {
169 let meta = match ParsedMeta::from(&entry.meta) { 168 let meta = match ParsedMeta::from(&entry.meta) {
170 ParsedMeta::Root { path } => {
171 let file_set = std::mem::replace(&mut file_set, FileSet::default());
172 db.set_source_root(source_root_id, Arc::new(SourceRoot::new_local(file_set)));
173 source_root_id.0 += 1;
174 source_root_prefix = path;
175 continue;
176 }
177 ParsedMeta::File(it) => it, 169 ParsedMeta::File(it) => it,
178 }; 170 };
179 assert!(meta.path.starts_with(&source_root_prefix)); 171 assert!(meta.path.starts_with(&source_root_prefix));
@@ -239,7 +231,6 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
239} 231}
240 232
241enum ParsedMeta { 233enum ParsedMeta {
242 Root { path: String },
243 File(FileMeta), 234 File(FileMeta),
244} 235}
245 236
@@ -255,11 +246,6 @@ struct FileMeta {
255impl From<&FixtureMeta> for ParsedMeta { 246impl From<&FixtureMeta> for ParsedMeta {
256 fn from(meta: &FixtureMeta) -> Self { 247 fn from(meta: &FixtureMeta) -> Self {
257 match meta { 248 match meta {
258 FixtureMeta::Root { path } => {
259 // `Self::Root` causes a false warning: 'variant is never constructed: `Root` '
260 // see https://github.com/rust-lang/rust/issues/69018
261 ParsedMeta::Root { path: path.to_owned() }
262 }
263 FixtureMeta::File(f) => Self::File(FileMeta { 249 FixtureMeta::File(f) => Self::File(FileMeta {
264 path: f.path.to_owned(), 250 path: f.path.to_owned(),
265 krate: f.crate_name.to_owned(), 251 krate: f.crate_name.to_owned(),
diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs
index 05cd0297d..503099fb7 100644
--- a/crates/ra_hir_def/src/nameres/tests.rs
+++ b/crates/ra_hir_def/src/nameres/tests.rs
@@ -424,31 +424,6 @@ fn extern_crate_rename_2015_edition() {
424} 424}
425 425
426#[test] 426#[test]
427fn import_across_source_roots() {
428 let map = def_map(
429 "
430 //- /main.rs crate:main deps:test_crate
431 use test_crate::a::b::C;
432
433 //- root /test_crate/
434
435 //- /test_crate/lib.rs crate:test_crate
436 pub mod a {
437 pub mod b {
438 pub struct C;
439 }
440 }
441
442 ",
443 );
444
445 assert_snapshot!(map, @r###"
446 ⋮crate
447 ⋮C: t v
448 "###);
449}
450
451#[test]
452fn reexport_across_crates() { 427fn reexport_across_crates() {
453 let map = def_map( 428 let map = def_map(
454 " 429 "
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index d0a732031..0dbeb01b1 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -10,7 +10,6 @@ pub struct FixtureEntry {
10 10
11#[derive(Debug, Eq, PartialEq)] 11#[derive(Debug, Eq, PartialEq)]
12pub enum FixtureMeta { 12pub enum FixtureMeta {
13 Root { path: String },
14 File(FileMeta), 13 File(FileMeta),
15} 14}
16 15
@@ -27,7 +26,6 @@ pub struct FileMeta {
27impl FixtureMeta { 26impl FixtureMeta {
28 pub fn path(&self) -> &str { 27 pub fn path(&self) -> &str {
29 match self { 28 match self {
30 FixtureMeta::Root { path } => &path,
31 FixtureMeta::File(f) => &f.path, 29 FixtureMeta::File(f) => &f.path,
32 } 30 }
33 } 31 }
@@ -35,21 +33,18 @@ impl FixtureMeta {
35 pub fn crate_name(&self) -> Option<&String> { 33 pub fn crate_name(&self) -> Option<&String> {
36 match self { 34 match self {
37 FixtureMeta::File(f) => f.crate_name.as_ref(), 35 FixtureMeta::File(f) => f.crate_name.as_ref(),
38 _ => None,
39 } 36 }
40 } 37 }
41 38
42 pub fn cfg_options(&self) -> Option<&CfgOptions> { 39 pub fn cfg_options(&self) -> Option<&CfgOptions> {
43 match self { 40 match self {
44 FixtureMeta::File(f) => Some(&f.cfg), 41 FixtureMeta::File(f) => Some(&f.cfg),
45 _ => None,
46 } 42 }
47 } 43 }
48 44
49 pub fn edition(&self) -> Option<&String> { 45 pub fn edition(&self) -> Option<&String> {
50 match self { 46 match self {
51 FixtureMeta::File(f) => f.edition.as_ref(), 47 FixtureMeta::File(f) => f.edition.as_ref(),
52 _ => None,
53 } 48 }
54 } 49 }
55 50
@@ -63,7 +58,6 @@ impl FixtureMeta {
63 Self { 58 Self {
64 iter: match meta { 59 iter: match meta {
65 FixtureMeta::File(f) => Some(f.env.iter()), 60 FixtureMeta::File(f) => Some(f.env.iter()),
66 _ => None,
67 }, 61 },
68 } 62 }
69 } 63 }
@@ -146,12 +140,6 @@ The offending line: {:?}"#,
146fn parse_meta(meta: &str) -> FixtureMeta { 140fn parse_meta(meta: &str) -> FixtureMeta {
147 let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); 141 let components = meta.split_ascii_whitespace().collect::<Vec<_>>();
148 142
149 if components[0] == "root" {
150 let path = components[1].to_string();
151 assert!(path.starts_with("/") && path.ends_with("/"));
152 return FixtureMeta::Root { path };
153 }
154
155 let path = components[0].to_string(); 143 let path = components[0].to_string();
156 assert!(path.starts_with("/")); 144 assert!(path.starts_with("/"));
157 145