Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros: characterization tests for ? operator fail #7069

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Jan 6, 2025

When a ? operator is used in a tokio entry point function (wrapped in
#[tokio::main]), which has a Option or Result return type, but where
the function does not actually return that type correctly, currently the
compiler returns two errors instead of just one. The first of which is
incorrect and only exists due to the macro expanding to an async block.

cannot use the `?` operator in an async block that returns `()`

This commit is a characterization test for this behavior to help show
when it's fixed (or even changed for better / worse)

Motivation

Annoyed by incorrect error message. "cannot use the ? operator in an async block that returns ()". More specifically, when editing code in ways that break the code (by changing return values, or changing the order of things, seeing error messages that aren't actually relevant to fixes can be annoying, particularly in situations where these errors are reported inline to the code. There's a small amount of time where the brain leaves the problem at hand and moves into solve the bug mode, which is unnecessary (and hence worth addressing)

More details at #6930 (comment)

Solution

This PR is about just identifying and capturing the problem. It can be merged as-is, or can be left open while considering the options to fix this.

@Darksonn
Copy link
Contributor

Darksonn commented Jan 6, 2025

cc @Veykril

@joshka joshka changed the title macros: charecterization tests for ? operator fail macros: characterization tests for ? operator fail Jan 20, 2025
When a `?` operator is used in a tokio entry point function (wrapped in
`#[tokio::main]`), which has a Option or Result return type, but where
the function does not actually return that type correctly, currently the
compiler returns two errors instead of just one. The first of which is
incorrect and only exists due to the macro expanding to an async block.

```
cannot use the `?` operator in an async block that returns `()`
```

This commit is a characterization test for this behavior to help show
when it's fixed (or even changed for better / worse)
@joshka joshka force-pushed the jm/better-tokio-main-error-message branch from 8cbf6b2 to e24847f Compare January 20, 2025 11:37
@Darksonn
Copy link
Contributor

Since this is a draft PR, are you looking for input? This looks like it's just new tests? I'm happy to add tests.

@joshka joshka marked this pull request as ready for review January 22, 2025 02:26
@joshka
Copy link
Contributor Author

joshka commented Jan 22, 2025

Since this is a draft PR, are you looking for input? This looks like it's just new tests? I'm happy to add tests.

I was going to attempt to solve the problem, but it seemed like there was a bunch of hidden complexity around a couple of parts of this. Happy to see it reviewed instead as just the test.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@Darksonn Darksonn merged commit c081dfe into tokio-rs:master Jan 22, 2025
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-macros Area: The tokio-macros crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants