you are viewing a single comment's thread
view the rest of the comments
[–] [S] 4 points 1 year ago* (2 children)

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.

  • source
  • hideshow 2 child comments
  • [–] 2 points 1 year ago* (last edited 1 year ago) (1 child)

    I like this solution more too, what about something like?

    code examples

    {
        spawn(async move {
            do_something_else_with(
                ^{ self.some_a.clone() },
                ^{ self.some_a.clone() },
                ^{ self.some_a.clone() },
            )
        });
    }
    

    Which desugars to

    {
        let (a, b, c) = (self.some_a.clone(), self.some_a.clone(), self.some_a.clone());
        
        spawn(async move {
            do_something_else_with(a, b, c)
        });
    }
    

    Then have like

    'super1: {
        'super2: {
            spawn(async move {
                do_something_else_with(
                    ^super1: { self.some_a.clone() },
                    ^super1: { self.some_a.clone() },
                    ^super1: { self.some_a.clone() },
                )
            });
        }
    }
    

    Which desugars to

    'super1: {
        let (a, b, c) = (self.some_a.clone(), self.some_a.clone(), self.some_a.clone());
    
        'super2: {
            spawn(async move {
                do_something_else_with(a, b, c)
            });
        }
    }
    

    And finally, the harder to read

    'super1: {
        'super2: {
            spawn(async move {
                do_something_else_with(
                    ^^{ self.some_a.clone() },
                    ^^{ self.some_a.clone() },
                    ^^{ self.some_a.clone() },
                )
            });
        }
    }
    

    Which desugars to

    'super1: {
        let (a, b, c) = (self.some_a.clone(), self.some_a.clone(), self.some_a.clone());
    
        'super2: {
            spawn(async move {
                do_something_else_with(a, b, c)
            });
        }
    }
    

  • source
  • parent
  • hideshow 1 child comment
  • [–] [S] 2 points 1 year ago

    I like the idea of using block labels, but I don't like the ^ symbol. There's already precedent for using keywords before blocks, like with async. There's also already super let in nightly I believe.

  • source
  • parent