Skip to content

E0277 reports const Drop bounds as Drop bounds  #92712

Closed
@PatchMixolydic

Description

@PatchMixolydic

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

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-confusingDiagnostics: Confusing error or lint that should be reworked.F-const_trait_impl`#![feature(const_trait_impl)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions