+ cargo +nightly-2023-07-10 fmt -- --check
Diff in /woodpecker/src/github.com/LemmyNet/lemmy/crates/utils/src/rate_limit/mod.rs at line 224:
use std::sync::atomic::{AtomicUsize, Ordering};
static CONCURRENT_API_USE: AtomicUsize = AtomicUsize::new(0);
-
impl<s> Service for RateLimitedMiddleware<s>
where
S: Service + 'static,
If I read that right you have one extra blank new line that the nightly rust fmt is not happy about.
You should just need to run cargo fmt on the code, might need the same nightly version as above though.</s></s>
Looks like it is now failing on the SQL fmt checks - which you have not changed and so are likely a problem in master. Seems https://github.com/LemmyNet/lemmy/pull/3800 fixes that issue and you are likely going to need to wait for that to be merged first. Or otherwise talk to the maintainers about it since it is broken in master and there is aPR to fix the issue.
Taking a quick look at the changes, most of the changed code is in a block, not a function. I know the argument to Box::pin looks like a function, but it’s actually an async block. So you don’t have a function to return from.
An anonymous function is introduced with an argument list surrounded by pipe characters (|) which you don’t have here. OTOH a block is introduced with curly braces. It is very common to use a block as the body of an anonymous function so it’s easy to mix those up.
A block introduces a new variable scope. It can have keyword modifiers, async and move, as you have here. The entire block is a value which is determined by the last expression in the block.
That’s a long way of saying: delete the return keyword, and remove the semicolon from the same line. That makes the value you want the last expression in the if body, which makes that become the value of the if expression, which then becomes the value of the block.
Flow control like return and break work differently in async blocks. They are much closer to closures than blocks in this regard. And need to be as they are lazily evaluated (like closures) and may even be evaluated well after the code that contains them has finished.
Looks like labels don’t work on async blocks, but using a nested inner block does work. Also, yeah, async blocks only exist to create Futures, they don’t execute until you start polling them. I don’t really see any reason why you couldn’t stick a label on the async block itself though, breaking would at worst just create one new state for the future - early returned.
Looks to be failing a
cargo fmt
check: https://woodpecker.join-lemmy.org/repos/129/pipeline/1821/8If I read that right you have one extra blank new line that the nightly rust fmt is not happy about.
You should just need to run
cargo fmt
on the code, might need the same nightly version as above though.</s></s>Thank you, removed the whitespace for another run: https://github.com/LemmyNet/lemmy/pull/3805/commits/33cc3967452d6b4a0369e4f85b17ff121c89451d
Looks like it is now failing on the SQL fmt checks - which you have not changed and so are likely a problem in master. Seems https://github.com/LemmyNet/lemmy/pull/3800 fixes that issue and you are likely going to need to wait for that to be merged first. Or otherwise talk to the maintainers about it since it is broken in master and there is aPR to fix the issue.
Thank you!
Taking a quick look at the changes, most of the changed code is in a block, not a function. I know the argument to
Box::pin
looks like a function, but it’s actually an async block. So you don’t have a function to return from.An anonymous function is introduced with an argument list surrounded by pipe characters (
|
) which you don’t have here. OTOH a block is introduced with curly braces. It is very common to use a block as the body of an anonymous function so it’s easy to mix those up.A block introduces a new variable scope. It can have keyword modifiers,
async
andmove
, as you have here. The entire block is a value which is determined by the last expression in the block.That’s a long way of saying: delete the
return
keyword, and remove the semicolon from the same line. That makes the value you want the last expression in theif
body, which makes that become the value of theif
expression, which then becomes the value of the block.Also worth mentioning, but you can early-return from a block in rust too, just using the
break
keyword and named blocks:Edit: I haven’t tried this with
async
blocks, but I’m guessing it works there too?Flow control like return and break work differently in async blocks. They are much closer to closures than blocks in this regard. And need to be as they are lazily evaluated (like closures) and may even be evaluated well after the code that contains them has finished.
Looks like labels don’t work on
async
blocks, but using a nested inner block does work. Also, yeah,async
blocks only exist to createFuture
s, they don’t execute until you start polling them. I don’t really see any reason why you couldn’t stick a label on the async block itself though, breaking would at worst just create one new state for the future - early returned.ahh, I tried removing the return, but forgot the original .await line had no semicolon… Thank you!