-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.F-const_trait_impl`#![feature(const_trait_impl)]``#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.