aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-22 23:15:22 +0100
committerGitHub <[email protected]>2020-06-22 23:15:22 +0100
commit98c3e4e887dcc5a8242c3e67c04a3cedbb1b9c58 (patch)
tree34caf163e19c51ea286b3e64698b29d0af22cfe2
parentceb69203b55d83aeaf4e58bff4a58f2f17d4087d (diff)
parent6a6098d4c31f6b54c8768e32f24182645ac077d6 (diff)
Merge #5000
5000: Remove RelativePathBuf from fixture r=matklad a=matklad The paths in fixture are not really relative (the default one is `/main.rs`), so it doesn't make sense to use `RelativePathBuf` here. bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_assists/src/handlers/add_from_impl_for_enum.rs2
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs2
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs2
-rw-r--r--crates/ra_db/src/fixture.rs10
-rw-r--r--crates/ra_hir_ty/src/tests/method_resolution.rs2
-rw-r--r--crates/ra_ide/src/mock_analysis.rs10
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs54
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs2
-rw-r--r--crates/test_utils/src/lib.rs10
9 files changed, 47 insertions, 47 deletions
diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
index 776bddf91..b0e56e1b5 100644
--- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
+++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
@@ -128,7 +128,7 @@ impl From<foo::bar::baz::Boo> for A {
128 128
129 fn check_not_applicable(ra_fixture: &str) { 129 fn check_not_applicable(ra_fixture: &str) {
130 let fixture = 130 let fixture =
131 format!("//- main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); 131 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
132 check_assist_not_applicable(add_from_impl_for_enum, &fixture) 132 check_assist_not_applicable(add_from_impl_for_enum, &fixture)
133 } 133 }
134 134
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
index 44db7917a..43b4584b4 100644
--- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -301,7 +301,7 @@ fn another_fn() {
301 301
302 fn check_not_applicable(ra_fixture: &str) { 302 fn check_not_applicable(ra_fixture: &str) {
303 let fixture = 303 let fixture =
304 format!("//- main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); 304 format!("//- /main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
305 check_assist_not_applicable(extract_struct_from_enum_variant, &fixture) 305 check_assist_not_applicable(extract_struct_from_enum_variant, &fixture)
306 } 306 }
307 307
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 569efb768..3c12c1daa 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -765,7 +765,7 @@ fn foo(opt: Option<i32>) {
765 } 765 }
766}"#; 766}"#;
767 let before = 767 let before =
768 &format!("//- main.rs crate:main deps:core\n{}{}", before, FamousDefs::FIXTURE); 768 &format!("//- /main.rs crate:main deps:core\n{}{}", before, FamousDefs::FIXTURE);
769 769
770 check_assist( 770 check_assist(
771 fill_match_arms, 771 fill_match_arms,
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs
index 482a2f3e6..af8fe11ec 100644
--- a/crates/ra_db/src/fixture.rs
+++ b/crates/ra_db/src/fixture.rs
@@ -164,7 +164,7 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
164 164
165 let mut source_root = SourceRoot::new_local(); 165 let mut source_root = SourceRoot::new_local();
166 let mut source_root_id = WORKSPACE; 166 let mut source_root_id = WORKSPACE;
167 let mut source_root_prefix: RelativePathBuf = "/".into(); 167 let mut source_root_prefix = "/".to_string();
168 let mut file_id = FileId(0); 168 let mut file_id = FileId(0);
169 169
170 let mut file_position = None; 170 let mut file_position = None;
@@ -212,9 +212,9 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
212 }; 212 };
213 213
214 db.set_file_text(file_id, Arc::new(text)); 214 db.set_file_text(file_id, Arc::new(text));
215 db.set_file_relative_path(file_id, meta.path.clone()); 215 db.set_file_relative_path(file_id, meta.path.clone().into());
216 db.set_file_source_root(file_id, source_root_id); 216 db.set_file_source_root(file_id, source_root_id);
217 source_root.insert_file(meta.path, file_id); 217 source_root.insert_file(meta.path.into(), file_id);
218 218
219 file_id.0 += 1; 219 file_id.0 += 1;
220 } 220 }
@@ -245,12 +245,12 @@ fn with_files(db: &mut dyn SourceDatabaseExt, fixture: &str) -> Option<FilePosit
245} 245}
246 246
247enum ParsedMeta { 247enum ParsedMeta {
248 Root { path: RelativePathBuf }, 248 Root { path: String },
249 File(FileMeta), 249 File(FileMeta),
250} 250}
251 251
252struct FileMeta { 252struct FileMeta {
253 path: RelativePathBuf, 253 path: String,
254 krate: Option<String>, 254 krate: Option<String>,
255 deps: Vec<String>, 255 deps: Vec<String>,
256 cfg: CfgOptions, 256 cfg: CfgOptions,
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs
index 804297315..a98efb1cc 100644
--- a/crates/ra_hir_ty/src/tests/method_resolution.rs
+++ b/crates/ra_hir_ty/src/tests/method_resolution.rs
@@ -933,7 +933,7 @@ fn method_resolution_overloaded_method() {
933 test_utils::mark::check!(impl_self_type_match_without_receiver); 933 test_utils::mark::check!(impl_self_type_match_without_receiver);
934 let t = type_at( 934 let t = type_at(
935 r#" 935 r#"
936//- main.rs 936//- /main.rs
937struct Wrapper<T>(T); 937struct Wrapper<T>(T);
938struct Foo<T>(T); 938struct Foo<T>(T);
939struct Bar<T>(T); 939struct Bar<T>(T);
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs
index ad78d2d93..76910d09b 100644
--- a/crates/ra_ide/src/mock_analysis.rs
+++ b/crates/ra_ide/src/mock_analysis.rs
@@ -4,7 +4,7 @@ use std::str::FromStr;
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use ra_cfg::CfgOptions; 6use ra_cfg::CfgOptions;
7use ra_db::{CrateName, Env, RelativePathBuf}; 7use ra_db::{CrateName, Env};
8use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER}; 8use test_utils::{extract_offset, extract_range, parse_fixture, FixtureEntry, CURSOR_MARKER};
9 9
10use crate::{ 10use crate::{
@@ -28,7 +28,7 @@ impl MockFileData {
28 fn path(&self) -> &str { 28 fn path(&self) -> &str {
29 match self { 29 match self {
30 MockFileData::Plain { path, .. } => path.as_str(), 30 MockFileData::Plain { path, .. } => path.as_str(),
31 MockFileData::Fixture(f) => f.meta.path().as_str(), 31 MockFileData::Fixture(f) => f.meta.path(),
32 } 32 }
33 } 33 }
34 34
@@ -167,7 +167,6 @@ impl MockAnalysis {
167 for (i, data) in self.files.into_iter().enumerate() { 167 for (i, data) in self.files.into_iter().enumerate() {
168 let path = data.path(); 168 let path = data.path();
169 assert!(path.starts_with('/')); 169 assert!(path.starts_with('/'));
170 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
171 let cfg_options = data.cfg_options(); 170 let cfg_options = data.cfg_options();
172 let file_id = FileId(i as u32 + 1); 171 let file_id = FileId(i as u32 + 1);
173 let edition = data.edition(); 172 let edition = data.edition();
@@ -183,7 +182,8 @@ impl MockAnalysis {
183 Default::default(), 182 Default::default(),
184 )); 183 ));
185 } else if path.ends_with("/lib.rs") { 184 } else if path.ends_with("/lib.rs") {
186 let crate_name = path.parent().unwrap().file_name().unwrap(); 185 let base = &path[..path.len() - "/lib.rs".len()];
186 let crate_name = &base[base.rfind('/').unwrap() + '/'.len_utf8()..];
187 let other_crate = crate_graph.add_crate_root( 187 let other_crate = crate_graph.add_crate_root(
188 file_id, 188 file_id,
189 edition, 189 edition,
@@ -199,7 +199,7 @@ impl MockAnalysis {
199 .unwrap(); 199 .unwrap();
200 } 200 }
201 } 201 }
202 change.add_file(source_root, file_id, path, Arc::new(data.content().to_owned())); 202 change.add_file(source_root, file_id, path.into(), Arc::new(data.content().to_owned()));
203 } 203 }
204 change.set_crate_graph(crate_graph); 204 change.set_crate_graph(crate_graph);
205 host.apply_change(change); 205 host.apply_change(change);
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index 0e2a83c6a..48ce831af 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -29,12 +29,12 @@ fn completes_items_from_standard_library() {
29 let project_start = Instant::now(); 29 let project_start = Instant::now();
30 let server = Project::with_fixture( 30 let server = Project::with_fixture(
31 r#" 31 r#"
32//- Cargo.toml 32//- /Cargo.toml
33[package] 33[package]
34name = "foo" 34name = "foo"
35version = "0.0.0" 35version = "0.0.0"
36 36
37//- src/lib.rs 37//- /src/lib.rs
38use std::collections::Spam; 38use std::collections::Spam;
39"#, 39"#,
40 ) 40 )
@@ -63,24 +63,24 @@ fn test_runnables_project() {
63 } 63 }
64 64
65 let code = r#" 65 let code = r#"
66//- foo/Cargo.toml 66//- /foo/Cargo.toml
67[package] 67[package]
68name = "foo" 68name = "foo"
69version = "0.0.0" 69version = "0.0.0"
70 70
71//- foo/src/lib.rs 71//- /foo/src/lib.rs
72pub fn foo() {} 72pub fn foo() {}
73 73
74//- foo/tests/spam.rs 74//- /foo/tests/spam.rs
75#[test] 75#[test]
76fn test_eggs() {} 76fn test_eggs() {}
77 77
78//- bar/Cargo.toml 78//- /bar/Cargo.toml
79[package] 79[package]
80name = "bar" 80name = "bar"
81version = "0.0.0" 81version = "0.0.0"
82 82
83//- bar/src/main.rs 83//- /bar/src/main.rs
84fn main() {} 84fn main() {}
85"#; 85"#;
86 86
@@ -140,12 +140,12 @@ fn test_format_document() {
140 140
141 let server = project( 141 let server = project(
142 r#" 142 r#"
143//- Cargo.toml 143//- /Cargo.toml
144[package] 144[package]
145name = "foo" 145name = "foo"
146version = "0.0.0" 146version = "0.0.0"
147 147
148//- src/lib.rs 148//- /src/lib.rs
149mod bar; 149mod bar;
150 150
151fn main() { 151fn main() {
@@ -200,13 +200,13 @@ fn test_format_document_2018() {
200 200
201 let server = project( 201 let server = project(
202 r#" 202 r#"
203//- Cargo.toml 203//- /Cargo.toml
204[package] 204[package]
205name = "foo" 205name = "foo"
206version = "0.0.0" 206version = "0.0.0"
207edition = "2018" 207edition = "2018"
208 208
209//- src/lib.rs 209//- /src/lib.rs
210mod bar; 210mod bar;
211 211
212async fn test() { 212async fn test() {
@@ -266,12 +266,12 @@ fn test_missing_module_code_action() {
266 266
267 let server = project( 267 let server = project(
268 r#" 268 r#"
269//- Cargo.toml 269//- /Cargo.toml
270[package] 270[package]
271name = "foo" 271name = "foo"
272version = "0.0.0" 272version = "0.0.0"
273 273
274//- src/lib.rs 274//- /src/lib.rs
275mod bar; 275mod bar;
276 276
277fn main() {} 277fn main() {}
@@ -335,10 +335,10 @@ fn test_missing_module_code_action_in_json_project() {
335 335
336 let code = format!( 336 let code = format!(
337 r#" 337 r#"
338//- rust-project.json 338//- /rust-project.json
339{PROJECT} 339{PROJECT}
340 340
341//- src/lib.rs 341//- /src/lib.rs
342mod bar; 342mod bar;
343 343
344fn main() {{}} 344fn main() {{}}
@@ -391,15 +391,15 @@ fn diagnostics_dont_block_typing() {
391 } 391 }
392 392
393 let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect(); 393 let librs: String = (0..10).map(|i| format!("mod m{};", i)).collect();
394 let libs: String = (0..10).map(|i| format!("//- src/m{}.rs\nfn foo() {{}}\n\n", i)).collect(); 394 let libs: String = (0..10).map(|i| format!("//- /src/m{}.rs\nfn foo() {{}}\n\n", i)).collect();
395 let server = Project::with_fixture(&format!( 395 let server = Project::with_fixture(&format!(
396 r#" 396 r#"
397//- Cargo.toml 397//- /Cargo.toml
398[package] 398[package]
399name = "foo" 399name = "foo"
400version = "0.0.0" 400version = "0.0.0"
401 401
402//- src/lib.rs 402//- /src/lib.rs
403{} 403{}
404 404
405{} 405{}
@@ -449,12 +449,12 @@ fn preserves_dos_line_endings() {
449 449
450 let server = Project::with_fixture( 450 let server = Project::with_fixture(
451 &" 451 &"
452//- Cargo.toml 452//- /Cargo.toml
453[package] 453[package]
454name = \"foo\" 454name = \"foo\"
455version = \"0.0.0\" 455version = \"0.0.0\"
456 456
457//- src/main.rs 457//- /src/main.rs
458/// Some Docs\r\nfn main() {} 458/// Some Docs\r\nfn main() {}
459", 459",
460 ) 460 )
@@ -484,12 +484,12 @@ fn out_dirs_check() {
484 484
485 let server = Project::with_fixture( 485 let server = Project::with_fixture(
486 r###" 486 r###"
487//- Cargo.toml 487//- /Cargo.toml
488[package] 488[package]
489name = "foo" 489name = "foo"
490version = "0.0.0" 490version = "0.0.0"
491 491
492//- build.rs 492//- /build.rs
493use std::{env, fs, path::Path}; 493use std::{env, fs, path::Path};
494 494
495fn main() { 495fn main() {
@@ -504,7 +504,7 @@ fn main() {
504 println!("cargo:rustc-cfg=featlike=\"set\""); 504 println!("cargo:rustc-cfg=featlike=\"set\"");
505 println!("cargo:rerun-if-changed=build.rs"); 505 println!("cargo:rerun-if-changed=build.rs");
506} 506}
507//- src/main.rs 507//- /src/main.rs
508#[rustc_builtin_macro] macro_rules! include {} 508#[rustc_builtin_macro] macro_rules! include {}
509#[rustc_builtin_macro] macro_rules! concat {} 509#[rustc_builtin_macro] macro_rules! concat {}
510#[rustc_builtin_macro] macro_rules! env {} 510#[rustc_builtin_macro] macro_rules! env {}
@@ -599,7 +599,7 @@ fn resolve_proc_macro() {
599 } 599 }
600 let server = Project::with_fixture( 600 let server = Project::with_fixture(
601 r###" 601 r###"
602//- foo/Cargo.toml 602//- /foo/Cargo.toml
603[package] 603[package]
604name = "foo" 604name = "foo"
605version = "0.0.0" 605version = "0.0.0"
@@ -607,7 +607,7 @@ edition = "2018"
607[dependencies] 607[dependencies]
608bar = {path = "../bar"} 608bar = {path = "../bar"}
609 609
610//- foo/src/main.rs 610//- /foo/src/main.rs
611use bar::Bar; 611use bar::Bar;
612trait Bar { 612trait Bar {
613 fn bar(); 613 fn bar();
@@ -618,7 +618,7 @@ fn main() {
618 Foo::bar(); 618 Foo::bar();
619} 619}
620 620
621//- bar/Cargo.toml 621//- /bar/Cargo.toml
622[package] 622[package]
623name = "bar" 623name = "bar"
624version = "0.0.0" 624version = "0.0.0"
@@ -627,7 +627,7 @@ edition = "2018"
627[lib] 627[lib]
628proc-macro = true 628proc-macro = true
629 629
630//- bar/src/lib.rs 630//- /bar/src/lib.rs
631extern crate proc_macro; 631extern crate proc_macro;
632use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; 632use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
633macro_rules! t { 633macro_rules! t {
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index 30d03b622..f58790ded 100644
--- a/crates/rust-analyzer/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -69,7 +69,7 @@ impl<'a> Project<'a> {
69 let mut paths = vec![]; 69 let mut paths = vec![];
70 70
71 for entry in parse_fixture(self.fixture) { 71 for entry in parse_fixture(self.fixture) {
72 let path = tmp_dir.path().join(entry.meta.path().as_str()); 72 let path = tmp_dir.path().join(&entry.meta.path()['/'.len_utf8()..]);
73 fs::create_dir_all(path.parent().unwrap()).unwrap(); 73 fs::create_dir_all(path.parent().unwrap()).unwrap();
74 fs::write(path.as_path(), entry.text.as_bytes()).unwrap(); 74 fs::write(path.as_path(), entry.text.as_bytes()).unwrap();
75 paths.push((path, entry.text)); 75 paths.push((path, entry.text));
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs
index 981565cd7..b1333cf15 100644
--- a/crates/test_utils/src/lib.rs
+++ b/crates/test_utils/src/lib.rs
@@ -168,13 +168,13 @@ pub struct FixtureEntry {
168 168
169#[derive(Debug, Eq, PartialEq)] 169#[derive(Debug, Eq, PartialEq)]
170pub enum FixtureMeta { 170pub enum FixtureMeta {
171 Root { path: RelativePathBuf }, 171 Root { path: String },
172 File(FileMeta), 172 File(FileMeta),
173} 173}
174 174
175#[derive(Debug, Eq, PartialEq)] 175#[derive(Debug, Eq, PartialEq)]
176pub struct FileMeta { 176pub struct FileMeta {
177 pub path: RelativePathBuf, 177 pub path: String,
178 pub crate_name: Option<String>, 178 pub crate_name: Option<String>,
179 pub deps: Vec<String>, 179 pub deps: Vec<String>,
180 pub cfg: CfgOptions, 180 pub cfg: CfgOptions,
@@ -183,7 +183,7 @@ pub struct FileMeta {
183} 183}
184 184
185impl FixtureMeta { 185impl FixtureMeta {
186 pub fn path(&self) -> &RelativePath { 186 pub fn path(&self) -> &str {
187 match self { 187 match self {
188 FixtureMeta::Root { path } => &path, 188 FixtureMeta::Root { path } => &path,
189 FixtureMeta::File(f) => &f.path, 189 FixtureMeta::File(f) => &f.path,
@@ -292,12 +292,12 @@ fn parse_meta(meta: &str) -> FixtureMeta {
292 let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); 292 let components = meta.split_ascii_whitespace().collect::<Vec<_>>();
293 293
294 if components[0] == "root" { 294 if components[0] == "root" {
295 let path: RelativePathBuf = components[1].into(); 295 let path = components[1].to_string();
296 assert!(path.starts_with("/") && path.ends_with("/")); 296 assert!(path.starts_with("/") && path.ends_with("/"));
297 return FixtureMeta::Root { path }; 297 return FixtureMeta::Root { path };
298 } 298 }
299 299
300 let path: RelativePathBuf = components[0].into(); 300 let path = components[0].to_string();
301 assert!(path.starts_with("/")); 301 assert!(path.starts_with("/"));
302 302
303 let mut krate = None; 303 let mut krate = None;