-
Notifications
You must be signed in to change notification settings - Fork 14.1k
lint: emit proper diagnostic for unsafe binders in improper_ctypes instead of ICE #149730
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
base: main
Are you sure you want to change the base?
Conversation
| ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"), | ||
| ty::UnsafeBinder(binder) => { | ||
| let ty = binder.skip_binder(); // extract the inner type | ||
| let _vars = binder.bound_vars(); // get bound vars if needed |
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.
When using a chatbot to generate the code, you have to at least review it afterwards. _var is unused and should be removed.
|
Rerolling, as I have no expertise in this area. @rustbot reroll |
| // build-fail | ||
| #![feature(unsafe_binders)] | ||
| //~^ WARN the feature `unsafe_binders` is incomplete | ||
| #![deny(improper_ctypes)] |
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.
// build-fail comment is not necessary. And if you use #![expect(incomple_feature)], the WARN will not occur.
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.
Hi, I see this is your first pull request - thank you for taking the time to submit it.
I’ve noticed the reasonable concerns raised by Mateusz above that this may have been AI-generated. If you'd like, you’re welcome to join the discussion below and help explain the reasoning behind the code decisions you made.
Also, I’d like to mention that we recently adopted a policy aimed at keeping reviews sustainable.
In short, it allows reviewers to redirect or close contributions that are overly burdensome to review - for example, when code or explanations appear inconsistent, contradictory, or don’t demonstrate an understanding of the existing codebase. You can read the full details here:
|
I have updated the PR with the following fixes: removed the unused _vars binding as suggested. adjusted the UI test as per the review (removed the unnecessary // build-fail comment ). reran the full test suite to confirm the diagnostic and stderr output are stable. I did use an AI tool initially to draft the change, but I fully reviewed, corrected, and refined the code myself. all changes now reflect my understanding of the lint and the unsafebinder handling. Please let me know if anything else should be improved. |
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.
And some nits I'm less concerned about, but still think are worth mentioning
|
thanks for asking and happy to explain and answer your questions i used skip_binder() because i only wanted to check the inner type that actually reaches the FFI boundary. The binder itself doesn’t matter for the FFI-safety check, since C doesn’t understand those binders. if I used the whole ty without skipping the binder, the lint wouldn’t look at the real inner type. i understand your point about the diagnostic looking like just &(). |
|
I see your point about using the fluent error messages instead of a raw string. I will take a look at the other arms and update this one to follow the same pattern so the diagnostic style stays consistent. I will push the fixes shortly. |
This comment has been minimized.
This comment has been minimized.
|
that makes sense. the current output only shows &(), while the span highlights the full unsafe &a (). I agree that the diagnostic should refer to the same type for consistency. I will update the diagnostic to report unsafe &a () instead of just &(), and then adjust the .stder file to match the updated message. Thanks for your clear explanation and feedback. it is really helpful as i am learning my way around the compiler codebase. |
|
Thanks for the detailed feedback I have updated the PR to address both concerns:
i removed the skip_binder() call since we are not actually checking the inner type and we are just reporting that unsafe binders aren't supported in FFI contexts yet. the test output now correctly shows the full type in the error message. let me know if there is anything else that needs adjusting. happy to learn and contribute. |
1adc7b7 to
8423d12
Compare
|
hi i have squashed the commits and cleaned up the history as requested. these are the updates included in the final commit:
thank you for the guidance and feedback it really helped me understand the lint behavior much better. |
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.
It would be great if you could restore the two lines that were accidentally removed
|
I ran ./x.py test tidy for clean format file checking because this automatically runs after running git push. So, to double check formatting i ran ./x.py test tidy and it gave errors at these two locations which you mentioned so i had to give an extra newline to pass the tidy test. |
|
I just copied your PR and tried add them locally and |
|
Why the error in
Yes, return it back please :) As you can see here all messages are spaced by a new line, you can't just remove it like this |
|
Squash please |
|
Tidy is failing because you change unrelated line, as I pointed it before
|
|
Pay attention to line number here please #149730 (comment) |
This comment has been minimized.
This comment has been minimized.
|
I have checked the tidy issues and fixed them. Also fixed the newline and whitespaces issues. Please verify now. |
Replaced _binder with _
|
Nice, thanks! Let's wait on CI and I will merge it afterwards |
|
Note: while I was patient and walked you through this process, other reviewers might handle things differently. In the future, similar PRs could be closed early if they require excessive back and forth for basic issues. I'm not trying to scare you, just want you to be aware so you can better prepare for next time. If you plan to keep contributing, I'd recommend spending more time studying the surrounding code and understanding the problem fully before submitting. |
|
Thanks for the guidance and for taking the time to walk me through the review. |
|
@bors r+ |



Fixes #149719
This PR replaces the
todo!("FIXME(unsafe_binder)")branch in theimproper_ctypeslint with a proper diagnostic.Previously, using an unsafe binder inside an extern
"C"block caused an internal compiler error.This fix now ensures that the compiler now emits a clear and stable error message explaining that types containing unsafe binders are not yet supported in FFI.
A new UI test
(unsafe-binder-basic.rs)is included to ensure this behavior remains stable and prevent regressions.