aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/attr.rs16
-rw-r--r--crates/hir_def/src/nameres/tests/mod_resolution.rs2
2 files changed, 6 insertions, 12 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index af3edc9df..12f4b02e2 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -166,16 +166,16 @@ impl Attrs {
166 } 166 }
167 167
168 pub fn docs(&self) -> Option<Documentation> { 168 pub fn docs(&self) -> Option<Documentation> {
169 let mut docs = String::new(); 169 let docs = self
170 self.by_key("doc") 170 .by_key("doc")
171 .attrs() 171 .attrs()
172 .flat_map(|attr| match attr.input.as_ref()? { 172 .flat_map(|attr| match attr.input.as_ref()? {
173 AttrInput::Literal(s) => Some(s), 173 AttrInput::Literal(s) => Some(s),
174 AttrInput::TokenTree(_) => None, 174 AttrInput::TokenTree(_) => None,
175 }) 175 })
176 .intersperse(&SmolStr::new_inline("\n")) 176 .intersperse(&SmolStr::new_inline("\n"))
177 // No FromIterator<SmolStr> for String 177 .map(|it| it.as_str())
178 .for_each(|s| docs.push_str(s.as_str())); 178 .collect::<String>();
179 if docs.is_empty() { 179 if docs.is_empty() {
180 None 180 None
181 } else { 181 } else {
@@ -202,14 +202,8 @@ impl Attr {
202 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { 202 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> {
203 let path = ModPath::from_src(ast.path()?, hygiene)?; 203 let path = ModPath::from_src(ast.path()?, hygiene)?;
204 let input = if let Some(lit) = ast.literal() { 204 let input = if let Some(lit) = ast.literal() {
205 // FIXME: escape?
206 let value = match lit.kind() { 205 let value = match lit.kind() {
207 ast::LiteralKind::String(string) if string.is_raw() => { 206 ast::LiteralKind::String(string) => string.value()?.into(),
208 let text = string.text().as_str();
209 let text = &text[string.text_range_between_quotes()?
210 - string.syntax().text_range().start()];
211 text.into()
212 }
213 _ => lit.syntax().first_token()?.text().trim_matches('"').into(), 207 _ => lit.syntax().first_token()?.text().trim_matches('"').into(),
214 }; 208 };
215 Some(AttrInput::Literal(value)) 209 Some(AttrInput::Literal(value))
diff --git a/crates/hir_def/src/nameres/tests/mod_resolution.rs b/crates/hir_def/src/nameres/tests/mod_resolution.rs
index ef6f85e15..e80b593aa 100644
--- a/crates/hir_def/src/nameres/tests/mod_resolution.rs
+++ b/crates/hir_def/src/nameres/tests/mod_resolution.rs
@@ -372,7 +372,7 @@ fn module_resolution_explicit_path_mod_rs_with_win_separator() {
372 check( 372 check(
373 r#" 373 r#"
374//- /main.rs 374//- /main.rs
375#[path = "module\bar\mod.rs"] 375#[path = r"module\bar\mod.rs"]
376mod foo; 376mod foo;
377 377
378//- /module/bar/mod.rs 378//- /module/bar/mod.rs