rust-lang / rust-lang/rust-analyzer
FP `Syntax Error: unknown character escape` CRLF
Open
@dfireBird is already working on this.
Since Sep 3, 2026.
C-bug
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
The following code
//@ run-pass
//@ reference: input.crlf
// ignore-tidy-file-cr
// license is ignored because tidy can't handle the CRLF here properly.
// N.B., this file needs CRLF line endings. The .gitattributes file in
// this directory should enforce it.
/// Doc comment that ends in CRLF
pub fn foo() {}
/** Block doc comment that
* contains CRLF characters
*/
pub fn bar() {}
fn main() {
let s = "string
literal";
assert_eq!(s, "string\nliteral");
let s = "literal with \
escaped newline";
assert_eq!(s, "literal with escaped newline");
let s = r"string
literal";
assert_eq!(s, "string\nliteral");
let s = br"byte string
literal";
assert_eq!(s, "byte string\nliteral".as_bytes());
// validate that our source file has CRLF endings
}
comiled with rustc (cargo check):
Checking _lexer-crlf-line-endings-string-literal-doc-comment v0.1.0 (/tmp/icemaker_global_tempdir.ZS5myupsVHNh/rustc_testrunner_tmpdir.bnJhsBBoXlX7/_lexer-crlf-line-endings-string-literal-doc-comment)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
but errors were issued by rust-analyzer diagnostics
at crate _lexer_crlf_line_endings_string_literal_doc_comment, file /tmp/icemaker_global_tempdir.ZS5myupsVHNh/rustc_testrunner_tmpdir.bnJhsBBoXlX7/_lexer-crlf-line-endings-string-literal-doc-comment/src/main.rs: Error SyntaxError from LineCol { line: 22, col: 12 } to LineCol { line: 23, col: 29 }: Syntax Error: unknown character escape
at crate _lexer_crlf_line_endings_string_literal_doc_comment, file /tmp/icemaker_global_tempdir.ZS5myupsVHNh/rustc_testrunner_tmpdir.bnJhsBBoXlX7/_lexer-crlf-line-endings-string-literal-doc-comment/src/main.rs: Error SyntaxError from LineCol { line: 18, col: 19 } to LineCol { line: 18, col: 19 }: Syntax Error: Character must be escaped: `
`
at crate _lexer_crlf_line_endings_string_literal_doc_comment, file /tmp/icemaker_global_tempdir.ZS5myupsVHNh/rustc_testrunner_tmpdir.bnJhsBBoXlX7/_lexer-crlf-line-endings-string-literal-doc-comment/src/main.rs: Error SyntaxError from LineCol { line: 22, col: 26 } to LineCol { line: 22, col: 26 }: Syntax Error: Invalid escape
diagnostic scan complete
Error: diagnostic error detected
Stack backtrace:
0: <anyhow::Error>::msg::<&str>
at /home/matthias/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/backtrace.rs:10:14
1: anyhow::__private::format_err
at /home/matthias/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/lib.rs:687:13
2: <rust_analyzer::cli::flags::Diagnostics>::run_
at /home/matthias/vcs/github/rust-analyzer/crates/rust-analyzer/src/cli/diagnostics.rs:123:13
3: <rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}
at /home/matthias/vcs/github/rust-analyzer/crates/rust-analyzer/src/cli/diagnostics.rs:20:29
4: <stdx::thread::Builder>::spawn::<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}
at /home/matthias/vcs/github/rust-analyzer/crates/stdx/src/thread.rs:74:13
5: std::sys::backtrace::__rust_begin_short_backtrace::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:166:18
6: std::thread::lifecycle::spawn_unchecked::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:70:13
7: <core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:275:9
8: std::panicking::catch_unwind::do_call::<core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>, core::result::Result<(), anyhow::Error>>
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:576:43
9: std::panicking::catch_unwind::<core::result::Result<(), anyhow::Error>, core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>>
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:544:19
10: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}::{closure#0}>, core::result::Result<(), anyhow::Error>>
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
11: std::thread::lifecycle::spawn_unchecked::<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1}
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/lifecycle.rs:68:26
12: <std::thread::lifecycle::spawn_unchecked<<stdx::thread::Builder>::spawn<<rust_analyzer::cli::flags::Diagnostics>::run::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#0}, core::result::Result<(), anyhow::Error>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
13: <alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output = ()> + core::marker::Send> as core::ops::function::FnOnce<()>>::call_once
at /rustc/ba28ff76f353a722f31c4f3dd2ac4e437d36411b/library/alloc/src/boxed.rs:2318:9
14: <std::sys::thread::unix::Thread>::new::thread_start
at /rustc/ba28ff76f353a722f31c4f3dd2ac4e437d36411b/library/std/src/sys/thread/unix.rs:123:17
15: <unknown>
16: <unknown>
version information
rust-analyzer 0.0.0 (baabc5825f 2026-08-13)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.