Closed
Description
I encountered this issue while trying to remove box_free
.
I tried this code:
#![feature(const_trait_impl, const_fn_trait_bound, const_mut_refs)]
trait X {
fn x();
}
struct Y<T: X>(T);
impl<T: ~const X> const Drop for Y<T> {
fn drop(&mut self) {
T::x();
}
}
I expected the code to compile.
Instead, I got the following error:
error[E0367]: `Drop` impl requires `T: X` but the struct it is implemented for does not
--> src/lib.rs:9:9
|
9 | impl<T: ~const X> const Drop for Y<T> {
| ^^^^^^^^
|
note: the implementor must specify the same requirement
--> src/lib.rs:7:1
|
7 | struct Y<T: X>(T);
| ^^^^^^^^^^^^^^^^^^
Meta
rustc --version --verbose
:
rustc 1.60.0-nightly (22e491ac7 2022-01-13)
binary: rustc
commit-hash: 22e491ac7ed454d34669151a8b6464cb643c9b41
commit-date: 2022-01-13
host: x86_64-pc-windows-msvc
release: 1.60.0-nightly
LLVM version: 13.0.0
Activity
lilasta commentedon Jan 14, 2022
workaround: play
compiler-errors commentedon Jan 14, 2022
Might be enough to just replace
ConstIfConst
withNotConst
when comparing the list of predicates indropck
, if someone wants to try that.crlf0710 commentedon Jan 14, 2022
cc @fee1-dead
beepster4096 commentedon Jan 15, 2022
This workaround causes the type to impl
~const Drop
when it shouldn't causing errors when interpreting instead of during type checking. (playground) This needs to be fixed too.This isn't enough. The constness of the bound seems to not get checked at all.
beepster4096 commentedon Jan 15, 2022
I'm not exactly sure how trait selection works, but I think the problem may be here, where only the constness of the impl is checked, and not any of the bounds.
compiler-errors commentedon Jan 15, 2022
@drmeepster you wouldn't believe that the same exact line was on my clipboard, and I was going to say that it was somewhere around
assemble_const_drop_candidates
😆Yeah, it seems like we need to enforce that the
~const
bounds on the drop impl are actually const during confirmation.compiler-errors commentedon Jan 15, 2022
Perhaps need to add some real confirmation logic here: https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/traits/select/confirmation.rs#L162
compiler-errors commentedon Jan 18, 2022
I'll take a stab at this, if nobody else is planning on it already!
@rustbot claim
cc @fee1-dead:
I'm planning on rewriting
assemble_const_drop_candidates
to prefer selecting a user-providedimpl const Drop
if it is provided (e.g. by an ADT), and fleshing out a realconfirm_const_drop_candidate
so we make sure to check those obligations that come from the user-providedimpl const Drop
.const Drop
impls considering~const
Bounds #93028