Skip to content

Commit a939801

Browse files
committed
Auto merge of rust-lang#132329 - compiler-errors:fn-and-destruct, r=lcnr
Implement `~const Destruct` effect goal in the new solver This also fixed a subtle bug/limitation of the `NeedsConstDrop` check. Specifically, the "`Qualif`" API basically treats const drops as totally structural, even though dropping something that has an explicit `Drop` implementation cannot be structurally decomposed. For example: ```rust #![feature(const_trait_impl)] #[const_trait] trait Foo { fn foo(); } struct Conditional<T: Foo>(T); impl Foo for () { fn foo() { println!("uh oh"); } } impl<T> const Drop for Conditional<T> where T: ~const Foo { fn drop(&mut self) { T::foo(); } } const FOO: () = { let _ = Conditional(()); //~^ This should error. }; fn main() {} ``` In this example, when checking if the `Conditional(())` rvalue is const-drop, since `Conditional` has a const destructor, we would previously recurse into the `()` value and determine it has nothing to drop, which means that it is considered to *not* need a const drop -- even though dropping `Conditional(())` would mean evaluating the destructor which relies on that `T: const Foo` bound to hold! This could be fixed alternatively by banning any const conditions on `const Drop` impls, but that really sucks -- that means that basically no *interesting* const drop impls could be written. We have the capability to totally and intuitively support the right behavior, which I've implemented here.
2 parents fb6f0c2 + bc77567 commit a939801

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

core/src/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ marker_impls! {
953953
///
954954
/// This should be used for `~const` bounds,
955955
/// as non-const bounds will always hold for every type.
956-
#[unstable(feature = "const_trait_impl", issue = "67792")]
956+
#[unstable(feature = "const_destruct", issue = "133214")]
957957
#[lang = "destruct"]
958958
#[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)]
959959
#[rustc_deny_explicit_impl(implement_via_object = false)]

0 commit comments

Comments
 (0)