1478: [WIP] Added resolve submodules with raw name r=matklad a=andreevlex

#1211

Co-authored-by: Alexander Andreev <andreevlex.as@gmail.com>
This commit is contained in:
bors[bot] 2019-07-03 19:29:21 +00:00
commit 4e8664d9d3
2 changed files with 39 additions and 2 deletions

View file

@ -98,13 +98,15 @@ pub(crate) trait AsName {
impl AsName for ast::NameRef {
fn as_name(&self) -> Name {
Name::new(self.text().clone())
let name = resolve_name(self.text());
Name::new(name)
}
}
impl AsName for ast::Name {
fn as_name(&self) -> Name {
Name::new(self.text().clone())
let name = resolve_name(self.text());
Name::new(name)
}
}
@ -184,3 +186,12 @@ impl AsName for KnownName {
Name::new(s.into())
}
}
fn resolve_name(text: &SmolStr) -> SmolStr {
let raw_start = "r#";
if text.as_str().starts_with(raw_start) {
SmolStr::new(&text[raw_start.len()..])
} else {
text.clone()
}
}

View file

@ -338,6 +338,32 @@ fn module_resolution_works_for_non_standard_filenames() {
"###);
}
#[test]
fn module_resolution_works_for_raw_modules() {
let map = def_map_with_crate_graph(
"
//- /library.rs
mod r#async;
use self::r#async::Bar;
//- /async.rs
pub struct Bar;
",
crate_graph! {
"library": ("/library.rs", []),
},
);
assert_snapshot_matches!(map, @r###"
crate
Bar: t v
async: t
crate::async
Bar: t v
"###);
}
#[test]
fn name_res_works_for_broken_modules() {
covers!(name_res_works_for_broken_modules);