Skip to content
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

Let qualify_min_const_fn deal with drop terminators #12681

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

y21
Copy link
Member

@y21 y21 commented Apr 16, 2024

Fixes #12677

The method_accepts_droppable check that was there seemed overly conservative.

Returns true if any of the method parameters is a type that implements Drop.
The method can't be made const then, because drop can't be const-evaluated.

Accepting parameters that implement Drop should still be fine as long as the parameter isn't actually dropped, as is the case in the linked issue where the droppable is moved into the return place. This more accurate analysis ("is there a drop terminator") is already done by qualify_min_const_fn here, so I don't think this additional check is really necessary?

Fixing the other, second case in the linked issue was only slightly more involved, since Vec::new() is a function call that has the ability to panic, so there must be a drop() terminator for cleanup, however we should be able to freely ignore that. Const checking ignores cleanup blocks, so we should, too?

r? @Jarcho


changelog: [missing_const_for_fn]: continue linting on fns with parameters implementing Drop if they're not actually dropped

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 16, 2024
@y21
Copy link
Member Author

y21 commented Apr 16, 2024

I do wonder what

if let Err((span, err)) = is_min_const_fn(cx.tcx, mir, &self.msrv) {
if cx.tcx.is_const_fn_raw(def_id.to_def_id()) {
cx.tcx.dcx().span_err(span, err);
}
} else {
is for... That seems like dead code essentially. We are early-returning if already_const before this, so I don't see how is_const_fn_raw() could be true.

@bors
Copy link
Collaborator

bors commented May 15, 2024

☔ The latest upstream changes (presumably #12713) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

missing_const_for_fn misses some cases with generics involved
4 participants