If someone tries to do the following async fn main() -> Result<(), Box<dyn std::error::Error> the error message is not helpful (though it is technically correct).
error[E0277]: `main` has invalid return type `impl futures::Future`
--> rs/agent-updater/src/main.rs:46:20
|
46 | async fn main() -> Result<(), Box<dyn std::error::Error>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
|
= help: consider using `()`, or a `Result`
I think that it should point to the async keyword and say that standard rust does not support async main.
This issue has been assigned to @Nokel81 via this comment.
Implementation notes:
fn main.Spanned from AST (https://doc.rust-lang.org/nightly/nightly-rustc/syntax/ast/struct.FnHeader.html#structfield.asyncness) to HIR (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.FnHeader.html#structfield.asyncness)cc @estebank who has dealt with fn main diagnostics recently.
This is a good first-contribution ticket I can help with.
I will take you up on that offer Wednesday evening if that is good with you.
@rustbot assign @Nokel81
@rustbot claim
@estebank Though I realize it might be too late for today. But how should be chat?
I'm on the street now, but if you have specific questions I can answer them when I get home.
Work is going well. I should have a preliminary PR up early next week.
I have two things that I have run into:
rustc_span::source_map::dummy_spanned?bug! panic at src/librustc_metadata/rmeta/decoder.rs:398: Cannot decode Span without Session., would anyone have an idea as to how to set up a Session? @Nokel81 could you push your code to a branch we can look at and comment inline? You should be extracting an existing span.
map_or_else or a default hir::IsAsync::NotAsync was used and I needed to a way to make it Spanned<hir::IsAsync>fn main is type checked as different then any other function.Ping from triage. @estebank, could you follow up?
Ping. @estebank, is this something you can continue to mentor? @Nokel81, are you still interested in working on this?
I am still interested in working on this.
I'm looking quickly over the branch, @Nokel81.
@estebank or others may feel differently but my take:
I don't think it's a good idea to return Spanned<hir::IsAsync> if we are going to sometimes use a dummy span. I see that we do use a similar pattern for VisibilityKind, but I'm of the opinion that dummy spans should be avoided and should not be common.
If we were going to use Spanned, I'd want to avoid the dummy span, and instead use the span of the fn keyword or something when the function is not async.
However, we could also just just include the span for the "yes, is async" variant. This is what the ast::Async type does (see the Yes variant). We could certainly modify hir::Async to include a span just on the Yes variant as well. I don't see a ton of precedent for that in the HIR, but it seems reasonable.
Thanks for the quick look over @nikomatsakis. I am wondering what should happen if an error occurs where it is required to be async but isn't (maybe I am thinking too hard in the future).
I sort of like the span of the fn keyword solution, and it is definitely better than using a dummy value.
@Nokel81 we can solve that problem later, but in that scenario, having a "dummy span" on hand would not be especially useful anyway -- that is, though, I think the right question to be asking, which is why I suggested the span for the "fn" keyword (or perhaps the fn name). i.e., what would you want to highlight in such a case?
but perhaps better to wait until indeed we have such a message to emit, which might help clarify things
Makes sense, I'll see about transitioning my change set to that using hir::Async::Yes with span information.
Most helpful comment
I will take you up on that offer Wednesday evening if that is good with you.