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

ICE: cycle detected when computing function signature of #125512

Closed
matthiaskrgr opened this issue May 24, 2024 · 0 comments · Fixed by #131239
Closed

ICE: cycle detected when computing function signature of #125512

matthiaskrgr opened this issue May 24, 2024 · 0 comments · Fixed by #131239
Labels
A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_ispatch` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(object_safe_for_dispatch)]
trait B {
    fn f(a: A) -> A;
}
trait A {
    fn concrete(b: B) -> B;
}
fn main() {}

original:

#![feature(object_safe_for_dispatch)]
trait B { fn f(a: A) -> A; }
trait A { fn concrete(b: B) -> B; }
fn main() {}

Version information

rustc 1.80.0-nightly (9e297bf54 2024-05-24)
binary: rustc
commit-hash: 9e297bf54d31eb3b30067208ff9af4416945a2ed
commit-date: 2024-05-24
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zunstable-options --edition=2024

Program output

warning: trait `B` is never used
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:2:7
  |
2 | trait B {
  |       ^
  |
  = note: `#[warn(dead_code)]` on by default

warning: trait `A` is never used
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:5:7
  |
5 | trait A {
  |       ^

warning: 2 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error[E0391]: cycle detected when computing function signature of `B::f`
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:3:5
  |
3 |     fn f(a: A) -> A;
  |     ^^^^^^^^^^^^^^^^
  |
note: ...which requires checking if trait `A` is object safe...
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:5:1
  |
5 | trait A {
  | ^^^^^^^
note: ...which requires determining object safety of trait `A`...
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:5:1
  |
5 | trait A {
  | ^^^^^^^
note: ...which requires computing function signature of `A::concrete`...
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:6:5
  |
6 |     fn concrete(b: B) -> B;
  |     ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires checking if trait `B` is object safe...
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:2:1
  |
2 | trait B {
  | ^^^^^^^
note: ...which requires determining object safety of trait `B`...
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:2:1
  |
2 | trait B {
  | ^^^^^^^
  = note: ...which again requires computing function signature of `B::f`, completing the cycle
note: cycle used when checking that `B` is well-formed
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:2:1
  |
2 | trait B {
  | ^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
note: delayed at compiler/rustc_query_system/src/query/job.rs:597:16 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:3:5
  |
3 |     fn f(a: A) -> A;
  |     ^^^^^^^^^^^^^^^^

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:6:20
  |
6 |     fn concrete(b: B) -> B;
  |                    ^
  |
  = note: `B` it is not object safe, so it can't be `dyn`
note: delayed at compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs:63:17 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:6:20
  |
6 |     fn concrete(b: B) -> B;
  |                    ^
help: use a new generic type parameter, constrained by `B`
  |
6 |     fn concrete<T: B>(b: T) -> B;
  |                ++++++    ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
  |
6 |     fn concrete(b: impl B) -> B;
  |                    ++++

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:6:26
  |
6 |     fn concrete(b: B) -> B;
  |                          ^
  |
note: delayed at compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs:63:17 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:6:26
  |
6 |     fn concrete(b: B) -> B;
  |                          ^
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
  |
6 |     fn concrete(b: B) -> impl B;
  |                          ++++

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:3:13
  |
3 |     fn f(a: A) -> A;
  |             ^
  |
  = note: `A` it is not object safe, so it can't be `dyn`
note: delayed at compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs:63:17 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:3:13
  |
3 |     fn f(a: A) -> A;
  |             ^
help: use a new generic type parameter, constrained by `A`
  |
3 |     fn f<T: A>(a: T) -> A;
  |         ++++++    ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
  |
3 |     fn f(a: impl A) -> A;
  |             ++++

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:3:19
  |
3 |     fn f(a: A) -> A;
  |                   ^
  |
note: delayed at compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs:63:17 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.Y2ZB7VqiZYxB/rustc_testrunner_tmpdir_reporting.n6c2niMcV32C/mvce.rs:3:19
  |
3 |     fn f(a: A) -> A;
  |                   ^
help: `A` is not object safe, use `impl A` to return an opaque type, as long as you return a single underlying type
  |
3 |     fn f(a: A) -> impl A;
  |                   ++++

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.80.0-nightly (9e297bf54 2024-05-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@rustbot label +F-object_safe_for_dispatch

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 24, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_ispatch` labels May 24, 2024
@jieyouxu jieyouxu added A-HIR Area: The high-level intermediate representation (HIR) S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 8, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 12, 2024
…lcnr

Don't assume traits used as type are trait objs in 2021 edition

Fixes rust-lang#127548

When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case.
This PR fixes the bug where you don't need a trait object, so the error message was changed to:
```
error[E0782]: expected a type, found a trait
```
Also fixes some ICEs:
Fixes rust-lang#120241
Fixes rust-lang#120482
Fixes rust-lang#125512
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 12, 2024
…lcnr

Don't assume traits used as type are trait objs in 2021 edition

Fixes rust-lang#127548

When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case.
This PR fixes the bug where you don't need a trait object, so the error message was changed to:
```
error[E0782]: expected a type, found a trait
```
Also fixes some ICEs:
Fixes rust-lang#120241
Fixes rust-lang#120482
Fixes rust-lang#125512
@bors bors closed this as completed in 663da00 Oct 13, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 13, 2024
Rollup merge of rust-lang#131239 - VulnBandit:trait-vulnerability, r=lcnr

Don't assume traits used as type are trait objs in 2021 edition

Fixes rust-lang#127548

When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case.
This PR fixes the bug where you don't need a trait object, so the error message was changed to:
```
error[E0782]: expected a type, found a trait
```
Also fixes some ICEs:
Fixes rust-lang#120241
Fixes rust-lang#120482
Fixes rust-lang#125512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: The high-level intermediate representation (HIR) C-bug Category: This is a bug. F-dyn_compatible_for_dispatch `#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_ispatch` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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