Skip to content

Commit 69a38de

Browse files
Check drop is trivial before checking ty needs drop
1 parent af0d566 commit 69a38de

File tree

12 files changed

+57
-180
lines changed

12 files changed

+57
-180
lines changed

compiler/rustc_const_eval/src/check_consts/qualifs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ impl Qualif for NeedsNonConstDrop {
175175
return false;
176176
}
177177

178+
// If this doesn't need drop at all, then don't select `~const Destruct`.
179+
if !ty.needs_drop(cx.tcx, cx.typing_env) {
180+
return false;
181+
}
182+
178183
// We check that the type is `~const Destruct` since that will verify that
179184
// the type is both `~const Drop` (if a drop impl exists for the adt), *and*
180185
// that the components of this type are also `~const Destruct`. This
@@ -203,7 +208,7 @@ impl Qualif for NeedsNonConstDrop {
203208
// in its value since:
204209
// 1. The destructor may have `~const` bounds which are not present on the type.
205210
// Someone needs to check that those are satisfied.
206-
// While this could be done instead satisfied by checking that the `~const Drop`
211+
// While this could be instead satisfied by checking that the `~const Drop`
207212
// impl holds (i.e. replicating part of the `in_any_value_of_ty` logic above),
208213
// even in this case, we have another problem, which is,
209214
// 2. The destructor may *modify* the operand being dropped, so even if we

compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ declare_features! (
426426
(unstable, const_async_blocks, "1.53.0", Some(85368)),
427427
/// Allows `const || {}` closures in const contexts.
428428
(incomplete, const_closures, "1.68.0", Some(106003)),
429-
/// Uwu
429+
/// Allows using `~const Destruct` bounds and calling drop impls in const contexts.
430430
(unstable, const_destruct, "CURRENT_RUSTC_VERSION", Some(133214)),
431431
/// Allows `for _ in _` loops in const contexts.
432432
(unstable, const_for, "1.56.0", Some(87575)),

compiler/rustc_middle/src/ty/context.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
pub mod tls;
66

7-
use std::assert_matches::assert_matches;
7+
use std::assert_matches::{assert_matches, debug_assert_matches};
88
use std::borrow::Borrow;
99
use std::cmp::Ordering;
1010
use std::hash::{Hash, Hasher};
@@ -377,14 +377,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
377377
}
378378

379379
fn impl_is_const(self, def_id: DefId) -> bool {
380+
debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true });
380381
self.is_conditionally_const(def_id)
381382
}
382383

383384
fn fn_is_const(self, def_id: DefId) -> bool {
385+
debug_assert_matches!(self.def_kind(def_id), DefKind::Fn | DefKind::AssocFn);
384386
self.is_conditionally_const(def_id)
385387
}
386388

387389
fn alias_has_const_conditions(self, def_id: DefId) -> bool {
390+
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::OpaqueTy);
388391
self.is_conditionally_const(def_id)
389392
}
390393

tests/ui/consts/const-block-const-bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ known-bug: #103507
22

33
#![allow(unused)]
4-
#![feature(const_trait_impl, negative_impls)]
4+
#![feature(const_trait_impl, negative_impls, const_destruct)]
55

66
use std::marker::Destruct;
77

Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
error[E0658]: use of unstable library feature `const_destruct`
2-
--> $DIR/const-block-const-bound.rs:6:5
3-
|
4-
LL | use std::marker::Destruct;
5-
| ^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
8-
= help: add `#![feature(const_destruct)]` to the crate attributes to enable
9-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10-
11-
error[E0658]: use of unstable library feature `const_destruct`
12-
--> $DIR/const-block-const-bound.rs:8:22
13-
|
14-
LL | const fn f<T: ~const Destruct>(x: T) {}
15-
| ^^^^^^^^
16-
|
17-
= note: see issue #133214 <https://github.com/rust-lang/rust/issues/133214> for more information
18-
= help: add `#![feature(const_destruct)]` to the crate attributes to enable
19-
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20-
211
error: `~const` can only be applied to `#[const_trait]` traits
222
--> $DIR/const-block-const-bound.rs:8:15
233
|
@@ -40,7 +20,6 @@ LL | const fn f<T: ~const Destruct>(x: T) {}
4020
| |
4121
| the destructor for this type cannot be evaluated in constant functions
4222

43-
error: aborting due to 5 previous errors
23+
error: aborting due to 3 previous errors
4424

45-
Some errors have detailed explanations: E0493, E0658.
46-
For more information about an error, try `rustc --explain E0493`.
25+
For more information about this error, try `rustc --explain E0493`.

tests/ui/consts/fn_trait_refs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(unboxed_closures)]
66
#![feature(const_trait_impl)]
77
#![feature(const_cmp)]
8+
#![feature(const_destruct)]
89

910
use std::marker::Destruct;
1011

0 commit comments

Comments
 (0)