-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make pointer_structural_match normal and warn #110166
Conversation
bf2ac4c
to
a562eaa
Compare
cc also #74446 which contains some discussion of whether to allow fn pointers in match or not. |
a562eaa
to
679bf49
Compare
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? lang |
I tend to agree with the proposal to make it warn-by-default but not necessarily disallow it. That said, I think the lang team should discuss, so I nominated this PR for our next meeting. |
This comment has been minimized.
This comment has been minimized.
e4c1f26
to
5bf1491
Compare
We discussed this in our lang team meeting today. The consensus was:
|
This commit removes the pointer_structural_match forward compat lint from the forward compatibility warning mechanism, as there is no concrete plan for removal of matching on function pointers. It also turns the lint from allow-by-default to warn-by-default, as the behaviour might be surprising to users and they should specifically opt into the dangers. As the lint is recognized on older compilers, users can easily allow it after having made the descision on whether they want to keep it in their code or not.
5bf1491
to
86b8a21
Compare
I have changed the PR to now be warn by default and not be a forward compatibility lint. @rustbot ready |
@rfcbot fcp merge |
Team member @tmandry has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
@rfcbot fcp reviewed |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
/// compare as equal during runtime. This is because LLVM optimizations can deduplicate | ||
/// functions if their bodies are the same, thus also making pointers to these functions point | ||
/// to the same location. Additionally functions may get duplicated if they are instantiated | ||
/// Use of function pointers and wide raw pointers in patterns works in many cases as |
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.
/// Use of function pointers and wide raw pointers in patterns works in many cases as | |
/// Use of function pointers and `dyn Trait` raw pointers in patterns works in many cases as |
I assume this doesn't fire on slice raw pointers?
@oli-obk IIRC this was a future-compat lint because of our plans for match and value trees. With the current state of those plans, do we still need the future compat part? I assume no since #105750 landed. Function pointers and wide raw pointers do not have 'structural equality' but we allow them in So I guess this means we have no plans to change that, and instead accept that we allow matching on some non-structural-eq types. We have a pretty clear semantics for that now (just use |
There are a bunch of forward compat lints, including the one for floats, that might be removed if that's the direction you want to go in. Note that this PR is already removing the future compat part, but only for
Hmm yeah good point, ideally we'd warn both for == and on matches, and then the name should probably be adjusted, too. |
Ah, I forgot about those. Either we plan to eventually reject these non-structural-eq-matches, then they should all remain future-compat lints, or we don't plan to reject such code, then we probably should remove the future-compat status for all of them. |
Co-authored-by: Ralf Jung <post@ralfj.de>
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
So to summarize what @RalfJung suggested:
|
@est31 what is the status of this? I recently dug into the entire pattern matching situation a bit more and I fully agree now that we don't want this to be a future-incompat lint any more. (And same for |
I need to find time to update this PR with the listed todos. If someone else wants to beat me to it, please be my guest. Regarding |
Yeah that's the thing, the entire justification and wording of the lint was in the anticipation of fwd compat changes. If those are not going to happen we should start from scratch, i.e., remove the lint and think about what we actually want to lint against and why, and have a new lint for that. That can happen in the same PR but it doesn't have to. If we don't lint against |
@est31 any updates on this? |
I think this is superseded by #120423. |
Yeah let's close it. |
This PR does two things:
pointer_structural_match
from allow to warnpointer_structural_match
into a normal lint instead of being a forward compatibility lintThe
pointer_structural_match
lint was added in #70743 to look for code that matches on a function pointer. As pointed out in #70861, and #54685, LLVM's behaviour makes function pointers behave in unexpected ways: function pointers might not be equal to "themselves" if function pointers for the same function were created in two different crates, and on the other hand, two different functions might end up with the same address if LLVM detects that they have the same body. See the linked issues for examples.Thus, in #70743 an allow-by-default forward compatibility lint was added to address matching on pointers.
In #70861 (comment) preferences were expressed that there should be a lint for matching on function pointers, but it should not be disallowed completely. I'd interpret that as wanting a warn-by-default non forward compatibility lint. Therefore, there are two possible ways forward:
pointer_structural_match
into a normal lint that's not a forward compatibility lint, and make it warn by default, ORI think one should at least do one of the two things, even if it is only going to be a warning lint in the end.
The lang team has given the green light for the first approach. There is still the possibility that it will be forbidden in the future, but this will require concrete deprecation plans which don't exist right now.
cc @eddyb @pnkfelix @oli-obk