Skip to content

Const drop#88558

Merged
bors merged 16 commits intorust-lang:masterfrom
fee1-dead-contrib:const-drop
Sep 15, 2021
Merged

Const drop#88558
bors merged 16 commits intorust-lang:masterfrom
fee1-dead-contrib:const-drop

Conversation

@fee1-dead
Copy link
Copy Markdown
Member

@fee1-dead fee1-dead commented Sep 1, 2021

The changes are pretty primitive at this point. But at least it works. ^-^

Problems with the current change that I can think of now:

  • ~const Drop shouldn't change anything in the non-const world.
  • types that do not have drop glues shouldn't fail to satisfy ~const Drop in const contexts. struct S { a: u8, b: u16 } This might not fail for needs_non_const_drop, but it will fail in rustc_trait_selection.
  • The current change accepts types that have const Drop impls but have non-const Drop glue.

Fixes #88424.

Significant Changes:

  • ~const Drop is no longer treated as a normal trait bound. In non-const contexts, this bound has no effect, but in const contexts, this restricts the input type and all of its transitive fields to either a) have a const Drop impl or b) can be trivially dropped (i.e. no drop glue)
  • T: ~const Drop will not be linted like T: Drop.
  • Instead of recursing and iterating through the type in rustc_mir::transform::check_consts, we use the trait system to special case ~const Drop. See rustc_trait_selection::...::candidate_assembly#assemble_const_drop_candidates and others.

Changes not related to const Dropping and/or changes that are insignificant:

  • Node.constness_for_typeck no longer returns hir::Constness::Const for type aliases in traits. This was previously used to hack how we determine default bound constness for items. But because we now use an explicit opt-in, it is no longer needed.
  • Removed is_const_impl_raw query. We have impl_constness, and the only existing use of that query uses HirId, which means we can just operate it with hir.
  • ty::Destructor now has a field constness, which represents the constness of the destructor.

r? @oli-obk

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New problem with const_trait_impl

8 participants