Skip to content

extract_format_args assist escapes \ character in \n etc. #16745

@kartva

Description

@kartva

rust-analyzer version: rust-analyzer version: 0.3.1860-standalone

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

code snippet to reproduce:
Add the following test in rust-analyzer/crates/ide-assists/src/handlers/extract_expressions_from_format_string.rs

    #[test]
    fn escaped_literals() {
        check_assist(
            extract_expressions_from_format_string,
            &add_macro_decl(
                r#"
fn main() {
    print!("\n {x + 1}$0");
}
            "#,
            ),
            &add_macro_decl(
                r#"
fn main() {
    print!("\n {}"$0, x + 1);
}
            "#,
            ),
        );
    }

fails and instead produces

fn main() {
    print!("\\n {}"$0, x + 1);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions