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

cycle detected when evaluating type-level constant on invalid return type #114918

Closed
asquared31415 opened this issue Aug 17, 2023 · 4 comments · Fixed by #115313
Closed

cycle detected when evaluating type-level constant on invalid return type #114918

asquared31415 opened this issue Aug 17, 2023 · 4 comments · Fixed by #115313
Assignees
Labels
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.

Comments

@asquared31415
Copy link
Contributor

asquared31415 commented Aug 17, 2023

Code

// Does not repro without the braces.
#[allow(unused_braces)]
fn uwu() -> [(); { () }] {
    loop {}
}

Current output

error[[E0391]](https://doc.rust-lang.org/stable/error_codes/E0391.html): cycle detected when evaluating type-level constant
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
  |
note: ...which requires const-evaluating + checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires const-evaluating + checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires caching mir of `uwu::{constant#0}` for CTFE...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires elaborating drops for `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires borrow-checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires promoting constants in MIR for `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires const checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires preparing `uwu::{constant#0}` for borrow checking...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires unsafety-checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires building MIR for `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires match-checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires building THIR for `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
note: ...which requires type-checking `uwu::{constant#0}`...
 --> src/lib.rs:3:18
  |
3 | fn uwu() -> [(); { () }] {
  |                  ^^^^^^
  = note: ...which again requires evaluating type-level constant, completing the cycle
note: cycle used when checking that `uwu` is well-formed
 --> src/lib.rs:3:1
  |
3 | fn uwu() -> [(); { () }] {
  | ^^^^^^^^^^^^^^^^^^^^^^^^

Desired output

error[[E0308]](https://doc.rust-lang.org/stable/error_codes/E0308.html): mismatched types
 --> src/lib.rs:3:20
  |
3 | fn uwu() -> [(); { () }] {
  |                    ^^ expected `usize`, found `()`
@asquared31415 asquared31415 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 Aug 17, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 17, 2023
@gurry
Copy link
Contributor

gurry commented Aug 18, 2023

Looks more like a type check bug than a diagnostic issue per se. Output of rustc -Z treat-err-as-bug:

<snip>
query stack during panic:
#0 [typeck] type-checking `uwu::{constant#0}`
#1 [thir_body] building THIR for `uwu::{constant#0}`
#2 [check_match] match-checking `uwu::{constant#0}`
#3 [mir_built] building MIR for `uwu::{constant#0}`
#4 [unsafety_check_result] unsafety-checking `uwu::{constant#0}`
#5 [mir_const] preparing `uwu::{constant#0}` for borrow checking
#6 [mir_const_qualif] const checking `uwu::{constant#0}`
#7 [mir_promoted] promoting constants in MIR for `uwu::{constant#0}`
#8 [mir_borrowck] borrow-checking `uwu::{constant#0}`
#9 [mir_drops_elaborated_and_const_checked] elaborating drops for `uwu::{constant#0}`
#10 [mir_for_ctfe] caching mir of `uwu::{constant#0}` for CTFE
#11 [eval_to_allocation_raw] const-evaluating + checking `uwu::{constant#0}`
#12 [eval_to_allocation_raw] const-evaluating + checking `uwu::{constant#0}`
#13 [eval_to_valtree] evaluating type-level constant
#14 [check_well_formed] checking that `uwu` is well-formed
#15 [check_mod_type_wf] checking that types are well-formed in top-level module
#16 [analysis] running analysis passes on this crate
end of query stack

@gurry
Copy link
Contributor

gurry commented Aug 21, 2023

@rustbot claim

@gurry gurry removed their assignment Aug 22, 2023
@gurry
Copy link
Contributor

gurry commented Aug 22, 2023

@rustbot claim

@gurry
Copy link
Contributor

gurry commented Aug 28, 2023

Contrary to my comment above, the issue is related to diagnostics (I know better now).

It occurs because we mistake the block in the return type ([(); { () }]) for the block that contains the function's body, which triggers the suggestion to change the return type and during that suggestion we run into the cycle.

@bors bors closed this as completed in 2128efd Aug 30, 2023
@Nilstrieb Nilstrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 4, 2023
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 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.

4 participants