kurtbuilds / ormlite

An ORM in Rust for developers that love SQL.
https://crates.io/crates/ormlite
MIT License
216 stars 11 forks source link

proc-macro derive panicked using many_to_one_key #19

Closed gmLucario closed 1 year ago

gmLucario commented 1 year ago

using the example:

#[derive(Model, Debug)]
pub struct Person {
    pub id: Uuid,
    pub name: String,
    pub age: i32,

    pub organization_id: Uuid,

    #[ormlite(many_to_one_key = organization_id)]
    pub organization: Join<Organization>,
}

#[derive(Model, Debug)]
pub struct Organization {
    pub id: Uuid,
    pub name: String,
}

the compiler diagnostic shows the following message in the first Model:

   | #[derive(Model, Debug)]
   |          ^^^^^
   |
   = help: message: use-after-free of `proc_macro` symbol

using:

kurtbuilds commented 1 year ago

Hey! There were a few typos in the README example, but it works almost as-is (I'll fix the typos).

See this project: https://github.com/kurtbuilds/ormlite-issue-19-test

Can you share more information about what situation you're encountering this issue in? If you're saying compiler diagnostics- are you referring to an error with rust-analyzer or something? I didn't fully follow what error you're encountering.

Also on rustc 1.67.1 (d5a82bbd2 2023-02-07)

gmLucario commented 1 year ago

sure!

in your example i splitted the models into modules and the error is shown. I upload the src code folder src.zip

kurtbuilds commented 1 year ago

I'm happy to take a look if you can create a reproducible example. The code you shared doesn't include a Cargo.toml file and doesn't follow standard Rust project structure, so it's hard to know what issues you're encountering.

gmLucario commented 1 year ago

my bad !

i tried to make a pr jaja in your example but i couldn't.

so i share you the code with the expected folder structure:

ormlite-issue-19-test.zip

kurtbuilds commented 1 year ago

Thanks for catching this. I think there's something about order of operations that causes problems. The Join logic uses cached data in a proc_macro, which is relatively uncharted territory.

I refactored it, such that I believe this is now fixed, and I confirm the test project you provided is compiling. Please let me know if you encounter any issues!

Cut as 0.10.0.