pop-os / libcosmic

WIP library for COSMIC applications
https://pop-os.github.io/libcosmic/cosmic/
Mozilla Public License 2.0
473 stars 49 forks source link

build error: "temporary value dropped while borrowed" #596

Closed ldare373 closed 2 months ago

ldare373 commented 3 months ago

When building a project using libcosmic, I keep getting the following errors:

error[E0716]: temporary value dropped while borrowed
   --> ~/.cargo/git/checkouts/libcosmic-b367e32ffc370f4f/0a1922d/iced/graphics/src/text/editor.rs:753:18
    |
753 |       let layout = line
    |  __________________^
754 | |         .layout_opt()
    | |_____________________^ creates a temporary value which is freed while still in use
755 |           .as_ref()
756 |           .expect("Line layout should be cached");
    |                                                  - temporary value is freed at the end of this statement
757 |
758 |       layout.iter().map(move |visual_line| {
    |       ------ borrow later used here
    |
help: consider using a `let` binding to create a longer lived value
    |
753 ~     let binding = line
754 +         .layout_opt();
755 ~     let layout = binding
    |

error[E0716]: temporary value dropped while borrowed
   --> ~/.cargo/git/checkouts/libcosmic-b367e32ffc370f4f/0a1922d/iced/graphics/src/text/editor.rs:173:34
    |
173 |                       let layout = line
    |  __________________________________^
174 | |                         .layout_opt()
    | |_____________________________________^ creates a temporary value which is freed while still in use
175 |                           .as_ref()
176 |                           .expect("Line layout should be cached");
    |                                                                  - temporary value is freed at the end of this statement
177 |
178 |                       let mut lines = layout.iter().enumerate();
    |                                       ------ borrow later used here
    |
    = note: consider using a `let` binding to create a longer lived value

error[E0716]: temporary value dropped while borrowed
   --> ~/.cargo/git/checkouts/libcosmic-b367e32ffc370f4f/0a1922d/iced/graphics/src/text/editor.rs:607:34
    |
607 |                       let layout = line
    |  __________________________________^
608 | |                         .layout_opt()
    | |_____________________________________^ creates a temporary value which is freed while still in use
609 |                           .as_ref()
610 |                           .expect("Line layout should be cached");
    |                                                                  - temporary value is freed at the end of this statement
...
613 |                       for layout_line in layout.iter() {
    |                                          ------ borrow later used here
    |
help: consider using a `let` binding to create a longer lived value
    |
607 ~                     let binding = line
608 +                         .layout_opt();
609 ~                     let layout = binding
    |

error[E0716]: temporary value dropped while borrowed
   --> ~/.cargo/git/checkouts/libcosmic-b367e32ffc370f4f/0a1922d/iced/graphics/src/text/editor.rs:809:26
    |
809 |               let layout = line
    |  __________________________^
810 | |                 .layout_opt()
    | |_____________________________^ creates a temporary value which is freed while still in use
811 |                   .as_ref()
812 |                   .expect("Line layout should be cached");
    |                                                          - temporary value is freed at the end of this statement
813 |               for layout_line in layout.iter() {
    |                                  ------ borrow later used here
    |
help: consider using a `let` binding to create a longer lived value
    |
809 ~             let binding = line
810 +                 .layout_opt();
811 ~             let layout = binding
    |

For more information about this error, try `rustc --explain E0716`.
error: could not compile `iced_graphics` (lib) due to 4 previous errors

I've attached the project's Cargo.toml, Cargo.lock, a Nix flake I'm using for it, and the full output of cargo build.

I also tried building this project the same way. It builds and runs correctly with the Cargo.lock in the repo, but gives the same errors if built after running cargo update.

Cargo.toml Cargo.lock flake.nix cargo-build.txt

cargo v1.80.0 (376290515 2024-07-16)

l-const commented 3 months ago

I am not so good about how cargo deals with semver and upgrades, but I saw this upgrade in 0.12.1 cosmic-text : https://github.com/pop-os/cosmic-text/commit/b68f4ad5c68c91d76a23cc09f218c2e05fccdc1a regarding the .layout_opt() and I am seeing here that we use master for cosmic-text: https://github.com/pop-os/iced/blob/master/Cargo.toml#L154. What do you think @mmstick @jackpot51 ?

Screenshot 2024-09-03 at 5 28 41 PM
mmstick commented 3 months ago

@l-const We're not using semver for cosmic-text yet: https://github.com/pop-os/iced/blob/master/Cargo.toml#L154. So it's necessary to pin it to a specific commit or version until it's fixed.

mmstick commented 3 months ago
cargo update -p cosmic-text:0.12.1
ldare373 commented 3 months ago
cargo update -p cosmic-text:0.12.1

Still no luck with either project, but I'll try to find a combination of versions that work and post an update later.

ldare373 commented 3 months ago

cargo update --precise c751217 cosmic-text seems to work as a temporary solution.

jackpot51 commented 2 months ago

cosmic-text does bump the version appropriately for breaking changes, but libcosmic is currently using the master branch directly (to keep up with the latest changes). I've adapted iced to the cosmic-text API changes.