• Starfighter@discuss.tchncs.de
    link
    fedilink
    arrow-up
    1
    ·
    43 minutes ago

    I was under the impression that the compiler already optimizes out a lot of clones where the clone is primarily used to satisfy the borrow checker. Is that not the case?

  • SorteKanin@feddit.dkOP
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    2 hours ago

    Really not a fan of this approach. Makes the order of operations extremely weird. I would much prefer having super blocks that are explicitly inserted in the above scope. I.e. this:

    tokio::task::spawn(async move {
        do_something_else_with(
            super { self.some_a.clone() },
            super { self.some_a.clone() },
            super { self.some_a.clone() },
        )
    });
    

    Would desugar to:

    tokio::task::spawn({
        let first_block = { self.some_a.clone() };
        let second_block = { self.some_a.clone() };
        let third_block = { self.some_a.clone() };
        async move {
            do_something_else_with(
                first_block,
                second_block,
                third_block,
            )
        }
    });
    

    Only problem is if the clone is inside another block… but perhaps you could do super super { ... }? But that sort of gets crazy and makes it very hard to read again.