Closed
Description
Given the following code (playground):
#![feature(const_trait_impl)]
const fn trash<T>(_: T)
where
T: ~const std::marker::Destruct,
{
}
fn main() {
const HELLO: String = "Hello".to_string();
const F_RESULT: () = trash(HELLO);
}
The current output is:
error[E0277]: can't drop `Vec<u8>` in const contexts
--> src/main.rs:10:32
|
10 | const F_RESULT: () = trash(HELLO);
| ----- ^^^^^ within `String`, the trait `~const Destruct` is not implemented for `Vec<u8>`
| |
| required by a bound introduced by this call
|
note: the trait `Destruct` is implemented for `Vec<u8>`, but that implementation is not `const`
--> src/main.rs:10:32
|
10 | const F_RESULT: () = trash(HELLO);
| ^^^^^
= note: required because it appears within the type `String`
note: required by a bound in `trash`
--> src/main.rs:4:8
|
2 | const fn trash<T>(_: T)
| ----- required by a bound in this
3 | where
4 | T: ~const std::marker::Destruct,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `trash`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
8 | fn main() where Vec<u8>: ~const Destruct {
| ++++++++++++++++++++++++++++++
The suggestion at the end is nonsense for multiple reasons:
main
cannot have awhere
clause.- The suggestion introduces a
where
clause with a trivial bound, i.e. one that does not depend on any type or lifetime parameters). This is an unstable feature. - The bound is false and nothing this file does can make it true, because
Vec<u8>
andDestruct
are defined in other files. Destruct
is not in scope; it needs to be written asstd::marker::Destruct
.