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

Weird error with new signals lifetimes #2036

Closed
marc2332 opened this issue Mar 9, 2024 · 0 comments · Fixed by #2064
Closed

Weird error with new signals lifetimes #2036

marc2332 opened this issue Mar 9, 2024 · 0 comments · Fixed by #2064
Labels
signals Related to the signals crate

Comments

@marc2332
Copy link
Contributor

marc2332 commented Mar 9, 2024

Problem

I am getting an error with signals that seems unnecessary and it used to compile just fine before.

Code:

#[allow(non_snake_case)]
#[component]
fn Comp(value: i32) -> Element {
    rsx!(
        label {
            "{value}"
        }
    )
}

fn app() -> Element {
    let count = use_signal(|| 0);

    rsx!(
        Comp {
            value: *count.read()
        }
    )
}

Error:

> cargo run --example counter
    Blocking waiting for file lock on build directory
   Compiling examples v0.0.0 (D:\Projects\freya)
error[E0597]: `count` does not live long enough
  --> examples\counter.rs:27:21
   |
23 |     let count = use_signal(|| 0);
   |         ----- binding `count` declared here
...
27 |             value: *count.read()
   |                     ^^^^^-------
   |                     |
   |                     borrowed value does not live long enough
   |                     a temporary with access to the borrow is created here ...
...
30 | }
   | -
   | |
   | `count` dropped here while still borrowed
   | ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `generational_box::references::GenerationalRef<Ref<'_, i32>>`
   |
   = note: the temporary is part of an expression at the end of a block;
           consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
   |
25 ~     let x = rsx!(
26 |         Comp {
27 |             value: *count.read()
28 |         }
29 ~     ); x
   |

For more information about this error, try `rustc --explain E0597`.
error: could not compile `examples` (example "counter") due to previous error

Expected behavior

Compile

Environment:

  • Dioxus version: 2d2e9dc56a59b4f3ad4deb55d15c27f337cf564c
  • Rust version: 1.76
  • OS info: Windows
  • App platform: freya
@marc2332 marc2332 changed the title Weird errors with new signals lifetimes Weird error with new signals lifetimes Mar 9, 2024
@ealmloff ealmloff added the signals Related to the signals crate label Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
signals Related to the signals crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants