Skip to content

Commit d2d7a44

Browse files
committed
Test Fixture ExplicitRoot + ModuleResolutionRelativePathOutsideRoot.
1 parent bf84e49 commit d2d7a44

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

crates/base_db/src/fixture.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ impl ChangeFixture {
150150
entry.text.clone()
151151
};
152152

153+
let explicit_root = entry.explicit_root;
154+
153155
let meta = FileMeta::from(entry);
154156
assert!(meta.path.starts_with(&source_root_prefix));
155157

@@ -169,7 +171,7 @@ impl ChangeFixture {
169171
let dep = CrateName::normalize_dashes(&dep);
170172
crate_deps.push((crate_name.clone(), dep))
171173
}
172-
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" {
174+
} else if meta.path == "/main.rs" || meta.path == "/lib.rs" || explicit_root {
173175
assert!(default_crate_root.is_none());
174176
default_crate_root = Some(file_id);
175177
default_cfg = meta.cfg;

crates/hir_def/src/nameres/tests/mod_resolution.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,26 @@ pub struct Baz;
323323
fn module_resolution_relative_path_outside_root() {
324324
check(
325325
r#"
326-
//- /main.rs
326+
//- /a/b/c/d/e/main.rs root:
327327
#[path="../../../../../outside.rs"]
328328
mod foo;
329+
330+
//- /outside.rs
331+
mod bar;
332+
333+
//- /bar.rs
334+
pub struct Baz;
329335
"#,
330336
expect![[r#"
331337
crate
332-
"#]],
338+
foo: t
339+
340+
crate::foo
341+
bar: t
342+
343+
crate::foo::bar
344+
Baz: t v
345+
"#]],
333346
);
334347
}
335348

crates/test_utils/src/fixture.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use stdx::{lines_with_ends, split_once, trim_indent};
88
pub struct Fixture {
99
pub path: String,
1010
pub text: String,
11+
pub explicit_root: bool,
1112
pub krate: Option<String>,
1213
pub deps: Vec<String>,
1314
pub cfg_atoms: Vec<String>,
@@ -64,6 +65,7 @@ impl Fixture {
6465
let path = components[0].to_string();
6566
assert!(path.starts_with('/'));
6667

68+
let mut explicit_root = false;
6769
let mut krate = None;
6870
let mut deps = Vec::new();
6971
let mut edition = None;
@@ -73,6 +75,7 @@ impl Fixture {
7375
for component in components[1..].iter() {
7476
let (key, value) = split_once(component, ':').unwrap();
7577
match key {
78+
"root" => explicit_root = true,
7679
"crate" => krate = Some(value.to_string()),
7780
"deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
7881
"edition" => edition = Some(value.to_string()),
@@ -98,6 +101,7 @@ impl Fixture {
98101
Fixture {
99102
path,
100103
text: String::new(),
104+
explicit_root: explicit_root,
101105
krate: krate,
102106
deps,
103107
cfg_atoms,

0 commit comments

Comments
 (0)