Skip to content

Poor diagnostic when passing T: Drop (nonconst only) to a function that takes ~const Drop in an inline const #92713

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
PatchMixolydic opened this issue Jan 10, 2022 · 1 comment · Fixed by #92892
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-const_trait_impl `#![feature(const_trait_impl)]` F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Jan 10, 2022

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

@PatchMixolydic PatchMixolydic added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 10, 2022
@rustbot rustbot added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-const_trait_impl `#![feature(const_trait_impl)]` F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) labels Jan 10, 2022
@compiler-errors
Copy link
Member

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-const_trait_impl `#![feature(const_trait_impl)]` F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants