Skip to content

Reject move from struct that implements drop - #435

Merged
nikomatsakis merged 13 commits into
rust-lang:mainfrom
kirloo:drop_no_moving
Jul 22, 2026
Merged

Reject move from struct that implements drop#435
nikomatsakis merged 13 commits into
rust-lang:mainfrom
kirloo:drop_no_moving

Conversation

@kirloo

@kirloo kirloo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Resolves #422

How does it work, what questions do you have?

I reused the logic from prove_ty_is_copy for a function prove_ty_is_drop and added a predicate that prove_ty_is_drop should fail for the TypedPlaceExpressionData::Field branch of prove_place_is_movable.

prove_ty_is_copy and prove_ty_is_drop are nearly the same function, so maybe I could have refactored into a function like "prove_ty_is_trait".

AI disclosure

  • I used an AI tool for research, autocomplete, or in other minimal ways

@rustbot

rustbot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Thanks for contributing to formality! :)
A reviewer will take a look at your PR within a week or two. If not, come talk to us on https://rust-lang.zulipchat.com/#narrow/channel/402470-t-types.2Fformality

@nikomatsakis nikomatsakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments on Zulip. Let's restructure this like so:

  • extend TypedPlaceExpressionData::Field with the AdtId and variant info
  • write a helper on Program to search for an impl of Drop for a given adt, taking advantage that we don't care about where-clauses etc
  • then in the rule we can just check like (if let None = program.find_drop_impl(adt_id))

View changes since this review

@kirloo
kirloo requested a review from nikomatsakis July 16, 2026 10:38
@kirloo

kirloo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

@nikomatsakis I'm curious about what you think now. I had to split the TypedPlaceExpressionData::Field variant into two variants, Field and TupleField, since tuples don't have an AdtId.

@rustbot

This comment has been minimized.

@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nikomatsakis nikomatsakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikomatsakis
nikomatsakis added this pull request to the merge queue Jul 22, 2026
Merged via the queue into rust-lang:main with commit 4bb0bdd Jul 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop: no moving from a struct that implements Drop

3 participants