Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

E0277 reports const Drop bounds as Drop bounds #92712

Closed
PatchMixolydic opened this issue Jan 10, 2022 · 3 comments
Closed

E0277 reports const Drop bounds as Drop bounds #92712

PatchMixolydic opened this issue Jan 10, 2022 · 3 comments
Assignees
Labels
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. F-const_trait_impl `#![feature(const_trait_impl)]` 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)]

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

@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-trait-system Area: Trait system D-confusing Diagnostics: Confusing error or lint that should be reworked. F-const_trait_impl `#![feature(const_trait_impl)]` labels Jan 10, 2022
@compiler-errors
Copy link
Member

@rustbot claim

@fee1-dead
Copy link
Member

@compiler-errors I already have a PR up to fix this: #92256

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 15, 2022
…-const-block, r=fee1-dead

Do not fail evaluation in const blocks

Evaluate const blocks with a const param-env, so we properly check `~const` trait bounds.

Fixes rust-lang#92713
(I will fix the poor diagnostics in rust-lang#92713 and rust-lang#92712 in a separate PR)

cc `@nbdd0121` who wrote the code this PR touches in rust-lang#89561
@compiler-errors
Copy link
Member

Someone with powers mind closing this? @fee1-dead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. F-const_trait_impl `#![feature(const_trait_impl)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants