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

Unhelpful error message and cycles with const_evaluatable_checked #84971

Closed
WorldSEnder opened this issue May 6, 2021 · 3 comments
Closed

Unhelpful error message and cycles with const_evaluatable_checked #84971

WorldSEnder opened this issue May 6, 2021 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WorldSEnder
Copy link

Given the following code: playground link

#![feature(const_generics, const_evaluatable_checked)]

trait FiniteGroup : Sized {
    const group_size: usize;
    const elems: [Self; Self::group_size];
}

impl FiniteGroup for () {
    const group_size: usize = 1;
    const elems: [Self; Self::group_size] = [()];
}

Currently the compiler complains

error: unconstrained generic constant
 --> src/lib.rs:5:5
  |
5 |     const elems: [Self; Self::group_size];
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: try adding a `where` bound using this expression: `where [(); Self::group_size]:`

This is problematic:

  • it is not clear where to put the suggested where bound. The parser errors when put behind elems: or before the final ;. Maybe I'm missing something obvious?
  • the suggested expression is incomplete, and most likely missing a : Sized

Possible related to #80976, #82934 and #82509 but additionally, the bound is required on the trait's own associated constant, not in an impl, a struct or construction related to the trait.

Note: I believe correct code would look like

trait FiniteGroup : Sized where [Self; Self::group_size]: Sized {
    const group_size: usize;
    const elems: [Self; Self::group_size];
}

but this leads to

cycle detected when building an abstract representation for FiniteGroup::{constant#0}

note: ...which requires processing MIR for `FiniteGroup::{constant#0}`...
note: ...which requires unsafety-checking `FiniteGroup::{constant#0}`...
note: ...which requires building MIR for `FiniteGroup::{constant#0}`...
note: ...which requires type-checking `FiniteGroup::{constant#0}`...
note: ...which again requires building an abstract representation for FiniteGroup::{constant#0}, completing the cycle
@WorldSEnder WorldSEnder 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 May 6, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented May 6, 2021

the suggested expression is incomplete, and most likely missing a : Sized

it's actually not where T: is a valid where clause 😅 (not to say this isnt confusing)

@WorldSEnder
Copy link
Author

Maybe I did after all incorrectly understand what the compiler was complaining about, and I'm more confused! I thought it was complaining that [Self; Self::group_size] can not be used like that as the type for a const item, since that would have to be Sized.

@jonas-schievink jonas-schievink added F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. labels May 6, 2021
@lcnr
Copy link
Contributor

lcnr commented Jun 24, 2022

the cycle error with the where bound is tracked in #79356 (comment)

and the unclear + confusing error messages are well known. While I don't know whether we have an explicit tracking issue for them, we do keep them in mind and will deal with them as part of rust-lang/project-const-generics#41.

decided during triage (https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/.60F-generic_const_exprs.60.20triage/near/287342437) to close this issue as its content is already tracked elsewhere. Still thank you for opening this issue 👍

@lcnr lcnr closed this as completed Jun 24, 2022
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 F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. 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