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

expected string literal error #18686

Open
ihor-rud opened this issue Dec 13, 2024 · 0 comments
Open

expected string literal error #18686

ihor-rud opened this issue Dec 13, 2024 · 0 comments
Labels
C-bug Category: bug

Comments

@ihor-rud
Copy link

Just posting it here to let you know about bug in macro expansion. Basically, rust-analyzer reports expected string literal error for completely valid code. More information can be found here kyrias/sqlx-conditional-queries#18

rust-analyzer version: 0.3.2212
rustc version: rustc 1.83.0 (90b35a623 2024-11-26)
editor or extension: VSCode 2024-12-11, 22:49:33
code snippet to reproduce:

#[derive(Debug)]
struct OutputType {
    id: i32,
    name: String,
}

async fn query_conditional(db: &MySqlPool) -> Result<(), sqlx::Error> {
    let limit = Some(5);
    let rows: Vec<OutputType> = conditional_query_as!(
        OutputType,
        r#"
        select id, name from users
        {#limit}
    "#,
    #limit = match limit {
        Some(_) => "limit {limit}",
        None => ""
    },
    )
    .fetch_all(db)
    .await?;

    for row in rows {
        debug!("-------------------");
        debug!("{}", row.id);
        debug!("{}", row.name);
    }

    Ok(())
}
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

No branches or pull requests

1 participant