Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[doc ="..."] comments no longer allow escaped newlines #16980

Closed
siefkenj opened this issue Mar 30, 2024 · 2 comments · Fixed by #17024
Closed

#[doc ="..."] comments no longer allow escaped newlines #16980

siefkenj opened this issue Mar 30, 2024 · 2 comments · Fixed by #17024
Assignees
Labels
C-bug Category: bug

Comments

@siefkenj
Copy link

siefkenj commented Mar 30, 2024

In rust-analyzer rust-analyzer version: 0.3.1885-standalone (b6d1887bc 2024-03-17) in vscode, when writing a doc comment

#[doc = "\n\nThis is a \"quote\".\n\nFoo"]
fn main() {}

hovering over main() shows the doc comment as expected, with newlines. However, in rust-analyzer rust-analyzer version: 0.3.1896-standalone, while the quote characters display correctly, literal \n (backslash n) tokens appear in the tooltip.

@siefkenj siefkenj added the C-bug Category: bug label Mar 30, 2024
@siefkenj siefkenj changed the title #[doc ="..."] comments now longer allow escaped strings #[doc ="..."] comments no longer allow escaped newlines Mar 30, 2024
@roife
Copy link
Contributor

roife commented Mar 31, 2024

It might be caused by #16909.

update:

let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() {
Some(Interned::new(AttrInput::Literal(tt::Literal {
text: lit.token().text().into(),
span,
})))

AttrInput::Literal(it) => match it.text.strip_prefix('r') {
Some(it) => it.trim_matches('#'),
None => it.text.as_str(),
}
.strip_prefix('"')?
.strip_suffix('"'),

I guess we keep the whole token text to match spans. But I don't think using strip to get the string is a good approach since we can't distinguish between a raw-string and a normal string (in which characters can be escaped). And I found that when doc comments are within #[doc], \n should be escaped; whereas within /// it won't be escaped, the current code cannot handle this situation.

@roife
Copy link
Contributor

roife commented Mar 31, 2024

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants