Skip to content

Commit 2facd95

Browse files
committed
Escape string literals in Attr::from_src
1 parent 7a338e5 commit 2facd95

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

crates/hir_def/src/attr.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ impl Attrs {
166166
}
167167

168168
pub fn docs(&self) -> Option<Documentation> {
169-
let mut docs = String::new();
170-
self.by_key("doc")
169+
let docs = self
170+
.by_key("doc")
171171
.attrs()
172172
.flat_map(|attr| match attr.input.as_ref()? {
173173
AttrInput::Literal(s) => Some(s),
174174
AttrInput::TokenTree(_) => None,
175175
})
176176
.intersperse(&SmolStr::new_inline("\n"))
177-
// No FromIterator<SmolStr> for String
178-
.for_each(|s| docs.push_str(s.as_str()));
177+
.map(|it| it.as_str())
178+
.collect::<String>();
179179
if docs.is_empty() {
180180
None
181181
} else {
@@ -202,14 +202,8 @@ impl Attr {
202202
fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> {
203203
let path = ModPath::from_src(ast.path()?, hygiene)?;
204204
let input = if let Some(lit) = ast.literal() {
205-
// FIXME: escape?
206205
let value = match lit.kind() {
207-
ast::LiteralKind::String(string) if string.is_raw() => {
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-
}
206+
ast::LiteralKind::String(string) => string.value()?.into(),
213207
_ => lit.syntax().first_token()?.text().trim_matches('"').into(),
214208
};
215209
Some(AttrInput::Literal(value))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ fn module_resolution_explicit_path_mod_rs_with_win_separator() {
372372
check(
373373
r#"
374374
//- /main.rs
375-
#[path = "module\bar\mod.rs"]
375+
#[path = r"module\bar\mod.rs"]
376376
mod foo;
377377
378378
//- /module/bar/mod.rs

0 commit comments

Comments
 (0)