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 #18

Open
paulzhang5511 opened this issue Jul 25, 2024 · 6 comments
Open

expected string literal #18

paulzhang5511 opened this issue Jul 25, 2024 · 6 comments

Comments

@paulzhang5511
Copy link

image

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

kyrias commented Jul 25, 2024

And what is the actual error you get when you compile it? Pretty sure this is just rust-analyzer weirdness.

@paulzhang5511
Copy link
Author

paulzhang5511 commented Jul 26, 2024

@kyrias It can compile and run normally, with the output being correct, but Rust Analyzer issues an error.

table: users

image

code:

#[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(())
}

The output result is:

2024-07-26T01:00:28.686493Z DEBUG sqlx_mysql::connection::tls: not performing TLS upgrade: TLS support not compiled in
2024-07-26T01:00:28.688584Z DEBUG sqlx::query: summary="SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),time_zone='+00:00',NAMES …" db.statement="\n\nSET\n  sql_mode =(\n    SELECT\n      CONCAT(\n        @ @sql_mode,\n        ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION'\n      )\n  ),\n  time_zone = '+00:00',\n  NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;\n" rows_affected=0 rows_returned=0 elapsed=290.1µs elapsed_secs=0.0002901
2024-07-26T01:00:28.690331Z DEBUG sqlx::query: summary="select id, name from …" db.statement="\n\nselect\n  id,\n  name\nfrom\n  users\nlimit\n  ?\n" rows_affected=0 rows_returned=5 elapsed=572µs elapsed_secs=0.000572
2024-07-26T01:00:28.690700Z DEBUG sqlxdemo01: -------------------
2024-07-26T01:00:28.690855Z DEBUG sqlxdemo01: 0
2024-07-26T01:00:28.691044Z DEBUG sqlxdemo01: test0
2024-07-26T01:00:28.691215Z DEBUG sqlxdemo01: -------------------
2024-07-26T01:00:28.691406Z DEBUG sqlxdemo01: 1
2024-07-26T01:00:28.691530Z DEBUG sqlxdemo01: test
2024-07-26T01:00:28.691653Z DEBUG sqlxdemo01: -------------------
2024-07-26T01:00:28.691779Z DEBUG sqlxdemo01: 2
2024-07-26T01:00:28.691912Z DEBUG sqlxdemo01: test2
2024-07-26T01:00:28.692048Z DEBUG sqlxdemo01: -------------------
2024-07-26T01:00:28.692161Z DEBUG sqlxdemo01: 3
2024-07-26T01:00:28.692293Z DEBUG sqlxdemo01: test3
2024-07-26T01:00:28.692473Z DEBUG sqlxdemo01: -------------------
2024-07-26T01:00:28.692588Z DEBUG sqlxdemo01: 4
2024-07-26T01:00:28.692701Z DEBUG sqlxdemo01: test4

ISSUE expected string literal

image

@paulzhang5511
Copy link
Author

@kyrias When you have time, could you please resolve it as soon as possible?

@kyrias
Copy link
Owner

kyrias commented Jul 29, 2024

It's a rust-analyzer bug where it appears to now be expanding macros differently from how the Rust compiler does, so there's nothing I can do here other than try to report it to them when I have the time.

@paulzhang5511
Copy link
Author

@kyrias Thanks.

@ihor-rud
Copy link

I posted it to rust-analizer repo rust-lang/rust-analyzer#18686. If you have more input, just write a comment there

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

No branches or pull requests

3 participants