Skip to content

Commit 4e8664d

Browse files
bors[bot]ava57r
andcommitted
Merge #1478
1478: [WIP] Added resolve submodules with raw name r=matklad a=andreevlex #1211 Co-authored-by: Alexander Andreev <andreevlex.as@gmail.com>
2 parents 2b2cd82 + 6263aa1 commit 4e8664d

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

crates/ra_hir/src/name.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ pub(crate) trait AsName {
9898

9999
impl AsName for ast::NameRef {
100100
fn as_name(&self) -> Name {
101-
Name::new(self.text().clone())
101+
let name = resolve_name(self.text());
102+
Name::new(name)
102103
}
103104
}
104105

105106
impl AsName for ast::Name {
106107
fn as_name(&self) -> Name {
107-
Name::new(self.text().clone())
108+
let name = resolve_name(self.text());
109+
Name::new(name)
108110
}
109111
}
110112

@@ -184,3 +186,12 @@ impl AsName for KnownName {
184186
Name::new(s.into())
185187
}
186188
}
189+
190+
fn resolve_name(text: &SmolStr) -> SmolStr {
191+
let raw_start = "r#";
192+
if text.as_str().starts_with(raw_start) {
193+
SmolStr::new(&text[raw_start.len()..])
194+
} else {
195+
text.clone()
196+
}
197+
}

crates/ra_hir/src/nameres/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,32 @@ fn module_resolution_works_for_non_standard_filenames() {
338338
"###);
339339
}
340340

341+
#[test]
342+
fn module_resolution_works_for_raw_modules() {
343+
let map = def_map_with_crate_graph(
344+
"
345+
//- /library.rs
346+
mod r#async;
347+
use self::r#async::Bar;
348+
349+
//- /async.rs
350+
pub struct Bar;
351+
",
352+
crate_graph! {
353+
"library": ("/library.rs", []),
354+
},
355+
);
356+
357+
assert_snapshot_matches!(map, @r###"
358+
⋮crate
359+
⋮Bar: t v
360+
⋮async: t
361+
362+
⋮crate::async
363+
⋮Bar: t v
364+
"###);
365+
}
366+
341367
#[test]
342368
fn name_res_works_for_broken_modules() {
343369
covers!(name_res_works_for_broken_modules);

0 commit comments

Comments
 (0)