How to tell rust rover the entire function body is not wrong?

This is the error I'm getting

How to remove this issue without disabling the whole syntax checking?

What is the error?

And does the cargo check complete successfully? If not, you might want to share the error it emits - it would have more context than the IDE-shortened one.

I know but, the whole thing is way too distracting to look at. It somehow stopped showing like that. The code is changed. I don't have output of cargo check of that code now. Anyway, thanks

If you disable all those squiggly lines you may not see errors, but I understand they are distracting.

NOTE: The solution below is not directly applicable to RustRover since it doesn't use rust-analyzer.

There was an earlier discussion about how to disable them in rust-analyzer. The last post has the solution.

The solution involves changing the rust-analyzer config. However, in the post the config is changed in emacs, and you'll have to do the same thing in RustRover. I don't use either one, so I can't tell you how to do that.

1 Like

Taking a guess, the error is that the value tower::service_fn(|..| async { .. }) doesn't implement some trait required by the second argument of route_service. There is nothing you can do to make the squiggly lines shorter in this case. The problem is that the IDE has no more special knowledge about your error than "this value that you tried to pass is wrong", so it underlines the entire value. It's likely that in practice the mismatch is caused by something relatively simple, e.g. your returned future is not Send, or your async block returns a wrong value, or you have a closure signature mismatch etc. However, that kind of analysis is very specific to the API you used, and cannot be applied in general, so the IDE can't show a more specific error either.

That said, you can extract parts of the second argument into a separate variable. The value of the variable would be typechecked as usual, without any annoying extensive squiggly lines, and you'd get only an error on the parameter itself. I.e.something like this:

let service_fn = |req: Request| async { ... };
router.route_service(path, tower::service_fn(service_fn));
                        // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error blah

Alternatively, you can try putting a todo!() as the returned value of your async block, or even the closure itself. It doesn't always work, sometimes you need a specific type rather than ! in order for the code to typecheck, but it often helps.