Closed
Description
Given the following code (playground):
#![allow(unused)]
#![feature(const_fn_trait_bound, const_trait_impl)]
const fn f<T: ~const Drop>(x: T) {}
struct UnconstDrop;
impl Drop for UnconstDrop {
fn drop(&mut self) {}
}
const X: () = f(UnconstDrop);
The current output is:
error[E0277]: the trait bound `UnconstDrop: Drop` is not satisfied
--> src/lib.rs:12:17
|
12 | const X: () = 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`
The diagnostic claims that UnconstDrop
doesn't implement Drop
, but it does. The issue is that f
's argument has a ~const Drop
bound, UnconstDrop
does not implement const Drop
, and the call to f
was made in a const context.
Ideally the output should look something like this:
error[E0277]: the trait bound `UnconstDrop: const Drop` is not satisfied
--> src/lib.rs:12:17
|
12 | const X: () = 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-traits +D-confusing +F-const_trait_impl