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

expressions in the type of const params can cause cycle errors #75047

Closed
lcnr opened this issue Aug 2, 2020 · 1 comment · Fixed by #75069
Closed

expressions in the type of const params can cause cycle errors #75047

lcnr opened this issue Aug 2, 2020 · 1 comment · Fixed by #75069
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Aug 2, 2020

#![feature(const_generics)]
struct Bar<T>(T);

impl<T> Bar<T> {
    const fn value() -> usize {
        42
    }
}

struct Foo<const N: [u8; Bar::<u32>::value()]>;

This results in

warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error[E0391]: cycle detected when computing type of `Foo`
  --> src/lib.rs:10:1
   |
10 | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires computing type of `Foo::N`...
  --> src/lib.rs:10:18
   |
10 | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   |                  ^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
  --> src/lib.rs:10:26
   |
10 | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   |                          ^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
  --> src/lib.rs:10:26
   |
10 | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   |                          ^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
  --> src/lib.rs:10:26
   |
10 | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   |                          ^^^^^^^^^^^^^^^^^^^
note: ...which requires type-checking `Foo::{{constant}}#0`...
  --> src/lib.rs:10:26
   |
10 | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   |                          ^^^^^^^^^^^^^^^^^^^
note: ...which requires computing the variances of `Bar`...
  --> src/lib.rs:2:1
   |
2  | struct Bar<T>(T);
   | ^^^^^^^^^^^^^^^^^
   = note: ...which requires computing the variances for items in this crate...
   = note: ...which again requires computing type of `Foo`, completing the cycle
note: cycle used when collecting item types in top-level module
  --> src/lib.rs:1:1
   |
1  | / #![feature(const_generics)]
2  | | struct Bar<T>(T);
3  | |
4  | | impl<T> Bar<T> {
...  |
9  | |
10 | | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   | |_______________________________________________^

error: aborting due to previous error; 1 warning emitted

@lcnr lcnr added C-bug Category: This is a bug. A-const-generics Area: const generics (parameters and arguments) F-const_generics `#![feature(const_generics)]` labels Aug 2, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Aug 2, 2020

This should compile. For some details on why this is happening, see #74199 (comment)

@JohnTitor JohnTitor added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 2, 2020
tmandry added a commit to tmandry/rust that referenced this issue Aug 19, 2020
move const param structural match checks to wfcheck

fixes rust-lang#75047 fixes rust-lang#74950

We currently check for structural match violations inside of `type_of`.
As we need to check the array length when checking if `[NonEq; arr_len]` is structural match, we potentially require the variance of an expression. Computing the variance requires `type_of` for all types though, resulting in a cycle error.

r? @varkor @eddyb
@bors bors closed this as completed in 672d009 Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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.

2 participants