Closed
Description
Given the following code (playground):
#![allow(unused)]
#![feature(const_fn_trait_bound, const_trait_impl, inline_const)]
const fn f<T: ~const Drop>(x: T) {}
struct UnconstDrop;
impl Drop for UnconstDrop {
fn drop(&mut self) {}
}
fn main() {
const {
f(UnconstDrop);
}
}
The current output is:
error[E0080]: evaluation of `main::{constant#0}::<()>` failed
|
::: src/main.rs:4:35
|
4 | const fn f<T: ~const Drop>(x: T) {}
| - inside `f::<UnconstDrop>` at src/main.rs:4:35
...
14 | f(UnconstDrop);
| -------------- inside `main::{constant#0}::<()>` at src/main.rs:14:9
Ideally, the output should be the same as when such a call is made in a const
item:
error[E0277]: the trait bound `UnconstDrop: Drop` is not satisfied
--> src/lib.rs:14:11
|
14 | f(UnconstDrop);
| - ^^^^^^^^^^^ the trait `Drop` is not implemented for `UnconstDrop`
| |
| required by a bound introduced by this call
|
note: required by a bound in `f`
--> src/lib.rs:4:15
|
4 | const fn f<T: ~const Drop>(x: T) {}
| ^^^^^^^^^^^ required by this bound in `f`
... which can be improved further with the suggestion given in #92712:
error[E0277]: the trait bound `UnconstDrop: const Drop` is not satisfied
--> src/lib.rs:14:11
|
14 | f(UnconstDrop);
| - ^^^^^^^^^^^ the trait `Drop` is not implemented for `UnconstDrop` in const contexts
| |
| required by a bound introduced by this call
|
note: required by a bound in `f`
--> src/lib.rs:4:15
|
4 | const fn f<T: ~const Drop>(x: T) {}
| ^^^^^^^^^^^ required by this bound in `f`
|
help: in const contexts, `~const` trait bounds only accept `const` trait impls
help: for more information, see tracking issue #67792/the Rust Reference
@rustbot modify labels: +A-const-eval +A-traits +D-confusing +D-terse +F-const_trait_impl +F-inline_const
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Messages for errors, warnings, and lintsArea: Trait systemDiagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.`#![feature(const_trait_impl)]`Inline constants (aka: const blocks, const expressions, anonymous constants)Relevant to the compiler team, which will review and decide on the PR/issue.