-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
function pointers as match patterns have optimization-dependent behavior #70861
Comments
It is not clear to me what the best thing to do here is. @eddyb would like to disallow matching against function pointer constants entirely. I am thinking it might be better to issue a lint, since I know from experience some people simply are doing this, for better or for worse, and I suspect that its not a soundness issue, just a potential gotcha. Also, for you archeaologists out there, here is a classic rrrs-authors thread on this subject. Update: and yes, in case you were wondering, the scheme specifiers are still debating this matter nearly 30 years later: http://scheme-reports.org/mail/scheme-reports/msg03616.html |
The scary thing to me is this same thing happening with |
Looks like this is where the whitelisting is missing:
|
Very disconcertingly, it doesn't look like we turn Fixing that should probably be a priority, I wonder if @oli-obk already has plans for this. |
Not just that, I have an implementation of it! #70743 |
Ah, thanks, I vaguely remembered some discussion, I should've checked your PRs first, sorry! |
I believe the non-deterministic comparison of function pointers is already tracked by #54685, though the question of what to do about it w.r.t. patterns seems novel and worth tracking independently. |
Yesterday I wrote (#70861 (comment)):
But today I filed #70889, due to which we might need to do a completely separate check for const generics, so we don't have to be as strict on pattern |
I think this is basically a duplicate of #54685, caused by
|
Separate tracking may indeed be confusing, but I just want to note that I do not consider In particular, the point of rust-lang/rfcs#1445 is that the compiler has not historically treated such matches as being equivalent to Having said that, certainly this is related to #54685, and it may indeed be a good idea to merge these two tickets. But I want to make sure we do it for the right reason. |
This code causes forward-compat lints now, so once pointer_structural_match is a hard error this can be closed. (Cc #62411) |
…atterns, r=<try> Turn remaining non-structural-const-in-pattern lints into hard errors This completes the implementation of rust-lang#120362 by turning out remaining future-compat lints into hard errors: indirect_structural_match and pointer_structural_match. They have been future-compat lints for a while (indirect_structural_match for many years, pointer_structural_match since Rust 1.75), and have shown up in dependency breakage reports since Rust 1.78 (released yesterday). I don't expect any code will still depend on them, but we will of course do a crater run. A lot of cleanup is now possible in const_to_pat, but that is deferred to a later PR. Fixes rust-lang#70861
…r=pnkfelix Turn remaining non-structural-const-in-pattern lints into hard errors This completes the implementation of rust-lang/rust#120362 by turning our remaining future-compat lints into hard errors: indirect_structural_match and pointer_structural_match. They have been future-compat lints for a while (indirect_structural_match for many years, pointer_structural_match since Rust 1.75 (released Dec 28, 2023)), and have shown up in dependency breakage reports since Rust 1.78 (just released on May 2, 2024). I don't expect a lot of code will still depend on them, but we will of course do a crater run. A lot of cleanup is now possible in const_to_pat, but that is deferred to a later PR. Fixes rust-lang/rust#70861
…r=pnkfelix Turn remaining non-structural-const-in-pattern lints into hard errors This completes the implementation of rust-lang/rust#120362 by turning our remaining future-compat lints into hard errors: indirect_structural_match and pointer_structural_match. They have been future-compat lints for a while (indirect_structural_match for many years, pointer_structural_match since Rust 1.75 (released Dec 28, 2023)), and have shown up in dependency breakage reports since Rust 1.78 (just released on May 2, 2024). I don't expect a lot of code will still depend on them, but we will of course do a crater run. A lot of cleanup is now possible in const_to_pat, but that is deferred to a later PR. Fixes rust-lang/rust#70861
…r=pnkfelix Turn remaining non-structural-const-in-pattern lints into hard errors This completes the implementation of rust-lang/rust#120362 by turning our remaining future-compat lints into hard errors: indirect_structural_match and pointer_structural_match. They have been future-compat lints for a while (indirect_structural_match for many years, pointer_structural_match since Rust 1.75 (released Dec 28, 2023)), and have shown up in dependency breakage reports since Rust 1.78 (just released on May 2, 2024). I don't expect a lot of code will still depend on them, but we will of course do a crater run. A lot of cleanup is now possible in const_to_pat, but that is deferred to a later PR. Fixes rust-lang/rust#70861
I tried this code, supplied by @eddyb play:
I expected to see this happen: print out of
(and in debug builds, that is what happens).
Instead, this happened: in release builds, it prints:
Meta
This was on a playpen running 1.44.0-nightly, 2020-04-05.
This all arose from a conversation with @eddyb regarding structural match; you can read it on the zulip archive
cc #31434
The text was updated successfully, but these errors were encountered: