-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: improve diagnostics on type mismatch #3766
Conversation
Also, it seems dead_code warnings now work properly by this patch.
|
I understand that #3039 had some MSRV hazards. What about this PR? |
Ah, I was thinking of #3583. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable to me.
One question though: Why not define two actual functions and have one call the other?
As far as I know, the change to macro itself by #3583 doesn't actually cause any problems about MSRV. The problem about MSRV in #3583 is that some of the tests #3583 adds cannot compile on older compilers. However, those tests cannot compile on older compilers with or without #3583's changes.
Do you mean I change the test as follows? If so, I'm not sure what the benefits of doing it are... #[tokio::main]
async fn missing_semicolon_or_return_type() {
missing_return_type()
}
#[tokio::main]
async fn missing_return_type() -> Result<(), ()> {
missing_semicolon_or_return_type()
}
I fixed this limitation in e1442a4. Both nightly and stable compilers now output error messages of almost the same quality. |
No I didn't mean change the test. I meant change the output to something like this async fn real_main() -> ... {
...
}
fn main() -> ... {
Runtime::new().block_on(real_main())
} |
Ah, thanks for clarifying. As said in #3039 (review), that approach causes a breaking change:
For example, the current
If we remove support for the trait method, we may be able to implement that approach, but it is a breaking change anyway. UPDATE: added test case for trait method to prevent accidental breakage (63ee506) |
We probably didn't originally intend to support this, but it works, and remove support for it can cause breakage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. I have approved it. Feel free to merge it whenever you feel it is ready.
By adjusting the span of some tokens, improve diagnostics on type mismatch
Unfortunately, with this approach,
only the nightly compiler can benefit from complete error messages untilit is not very robust, as it can be affected if the span pointed by the error message is significantly changed. Also, some of the help messages still point to the wrong span. That said, these issues are not uncommon in diagnostics of proc-macro, and I think this would be enough improvement in the common case.feature(proc_macro_span)
is stabilized (on the stable compiler, some error messages will probably only point to the first token of the statement that has the problem), andThis replaces #3039. Thanks @Aaron1011 for finding this issue and being the first to work on the fix.
Code:
Before (current master):
After (this PR):
Both help messages are correct.
Code:
Before (current master):
After (this PR):
The first help message still wrong.
The second help message is correct.
Code:
Before (current master):
After (this PR):
The help message still wrong.
Closes #3039
Fixes rust-lang/rust#71968