Skip to content

Commit c589f90

Browse files
authored
Rollup merge of rust-lang#140445 - oli-obk:const-manually-drop, r=fee1-dead
Treat ManuallyDrop as ~const Destruct cc rust-lang#133214 (comment) r? ``@compiler-errors`` cc ``@fee1-dead``
2 parents 65051e2 + a1c7059 commit c589f90

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

+3
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
724724
let destruct_def_id = cx.require_lang_item(TraitSolverLangItem::Destruct);
725725

726726
match self_ty.kind() {
727+
// `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
728+
ty::Adt(adt_def, _) if adt_def.is_manually_drop() => Ok(vec![]),
729+
727730
// An ADT is `~const Destruct` only if all of the fields are,
728731
// *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
729732
ty::Adt(adt_def, args) => {

compiler/rustc_trait_selection/src/traits/effects.rs

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ fn evaluate_host_effect_for_destruct_goal<'tcx>(
252252
let self_ty = obligation.predicate.self_ty();
253253

254254
let const_conditions = match *self_ty.kind() {
255+
// `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
256+
ty::Adt(adt_def, _) if adt_def.is_manually_drop() => thin_vec![],
257+
255258
// An ADT is `~const Destruct` only if all of the fields are,
256259
// *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
257260
ty::Adt(adt_def, args) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@[new] compile-flags: -Znext-solver
2+
//@ revisions: old new
3+
//@ check-pass
4+
5+
use std::mem::ManuallyDrop;
6+
7+
struct Moose;
8+
9+
impl Drop for Moose {
10+
fn drop(&mut self) {}
11+
}
12+
13+
struct ConstDropper<T>(ManuallyDrop<T>);
14+
15+
const fn foo(_var: ConstDropper<Moose>) {}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@[new] compile-flags: -Znext-solver
2+
//@ revisions: old new
3+
//@ check-pass
4+
5+
#![feature(const_destruct)]
6+
#![feature(const_trait_impl)]
7+
8+
use std::mem::ManuallyDrop;
9+
10+
struct Moose;
11+
12+
impl Drop for Moose {
13+
fn drop(&mut self) {}
14+
}
15+
16+
struct ConstDropper<T>(ManuallyDrop<T>);
17+
18+
impl<T> const Drop for ConstDropper<T> {
19+
fn drop(&mut self) {}
20+
}
21+
22+
const fn foo(_var: ConstDropper<Moose>) {}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)