-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add a strange test for unsafe_code
lint.
#89821
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
I think the particular case tested here probably shouldn't lint, since the macro has requested a call site span. However, I believe the lint doesn't currently consider the span of the unsafe block at all. That seems like it might be good to fix to help with writing macros which enforce safety through static checking at compile-time (like println!) and currently can't easily do so without allowing unsafe in their arguments as well, due to needing to make sure the unsafe block is appropriately scoped. For example, see #89139. But it's also totally fine to leave that for future PR(s) or discussions; we can merge the test in the meantime. I think the broader changes here would likely need to start as a T-lang MCP proposing an initiative to look at the unsafe code interaction with macros, though maybe a PR would be small enough to be OK. I'm a little hesitant personally to pursue small steps without a broader plan in mind though here. |
db3d234
to
7326a97
Compare
I think i'd recommend just leave any potential discussions or changes to the future, because any change would quite likely break existing code in the wild. We can just land this test in the test suite so this special case won't get forgotten. |
This comment has been minimized.
This comment has been minimized.
7326a97
to
545de51
Compare
545de51
to
c76c620
Compare
@bors r+ |
📌 Commit c76c620 has been approved by |
…askrgr Rollup of 7 pull requests Successful merges: - rust-lang#86011 (move implicit `Sized` predicate to end of list) - rust-lang#89821 (Add a strange test for `unsafe_code` lint.) - rust-lang#89859 (add dedicated error variant for writing the discriminant of an uninhabited enum variant) - rust-lang#89870 (Suggest Box::pin when Pin::new is used instead) - rust-lang#89880 (Use non-checking TLS relocation in aarch64 asm! sym test.) - rust-lang#89885 (add long explanation for E0183) - rust-lang#89894 (Remove unused dependencies from rustc_const_eval) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The current behavior is a little surprising to me. I'm not sure whether people would change it, but at least let me document the current behavior with a test.
I learnt about this from the totally-speedy-transmute crate.
cc #10599 the original implementation pr.