-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Erroneous compiler error message for extra semicolon with try operator #6306
Comments
Adding a semi-colon to the final statement in a function turns it from an expression, to a statement, which does not return the value (from https://doc.rust-lang.org/book/ch03-03-how-functions-work.html, at the end of Statements and Expressions, just before Functions with Returns Values). My suspicion is that adding the semi-colon makes it return None, which doesn't conform to the return constraints, and thus is not an issue with the Rust compiler or Tokio. |
@just-an-engineer The compile failure is expected - what is unexpected is the message it generates. |
I don't know how easy it would be to fix this, but I would be happy to receive a PR for it. |
@ik1ne Ah, my apologies. I'll take a closer look tonight. |
Tough to figure out the proper way to do this. I left it as a draft because if I'm way off, I'm not going to dive further into it. I can't get as nice of an error as the compiler would give without the macro though... Or at least I don't quite know how. I don't think the |
I have reviewed many PRs/suggestions for improving error messages in macros, and those that were rejected or not implemented basically adopted one of the following two approaches:
Roughly summarizing the problems and solutions of the problems of these approaches:
Some complexity is unavoidable with either, but my understanding is that the former has more benefits, but may be more complex in terms of both implementation and testing, as the 2 approaches will need to be retained internally. If we don't care about the increase in compile-time, the latter implementation in a pattern that uses a |
Thanks for the detailed response @taiki-e! I'm happy to do the latter if we don't care about compile times, but if we do, then I will close my PR as it isn't taking the right approach. It's such a catch-22. If the author of a dependent crate cares about compile times, they can easily opt out of using the macro; it's really easy to use the builder to build a runtime. But in the same vein, it's really easy to figure out what's wrong with your code here. If that's the error message that stumps you, I think you'll have a really hard time with some other things. Is there CI that benchmarks compile times? If so, how can I check the difference from using the You (we?) could even add another macro with better compile performance if you (we?) wanted to. If one of you (the maintainers) wants to make a judgment call, I'm happy to proceed by either finishing this up or closing it. I really just stumbled upon it and have been enjoying a little metaprogramming lately, so I figured I would make an attempt. |
Compile-time regressions for users of the macro is one thing, but if we also hurt the compile-times of people who just enable the Are those extra syn features really so critical? We don't have benchmarks for the macro compile-times, unfortunately. |
@Darksonn, I don't think the I might have to drop the attempt at solving this issue... 😞 |
Version
Cargo.toml:
tokio = { version = "1", features = ["full"] }
% cargo tree | grep tokio └── tokio v1.35.1 └── tokio-macros v2.2.0 (proc-macro)
Platform
% uname -a Darwin (my hostname) 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64 % rustc --version rustc 1.75.0 (82e1608df 2023-12-21)
Description
[short summary of the bug]
Compiler error message for an extra semicolon with
?
(try operator) is confusing.[code sample that causes the bug]
I expected to see this compiler error message with or without
#[tokio::main]
attribute:The compiler error message clearly states that line number 4's extra semicolon should be fixed, and there's no error at line 3.
Instead, this happened:
The compiler incorrectly states that line number 3 is problematic, and the compiler error at line number 4 is slightly different.
The text was updated successfully, but these errors were encountered: