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: trait takes 1 generic argument but 0 generic arguments were supplied #128249

Closed
matthiaskrgr opened this issue Jul 26, 2024 · 2 comments · Fixed by #128377
Closed

ICE: trait takes 1 generic argument but 0 generic arguments were supplied #128249

matthiaskrgr opened this issue Jul 26, 2024 · 2 comments · Fixed by #128377
Assignees
Labels
C-bug Category: This is a bug. 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.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 26, 2024

auto-reduced (treereduce-rust):

trait Trait<Type> {
    type Type;

    fn method(&self) -> impl Trait<Type: '_>;
}

original:

trait Trait<Type> {
    type Type;

    fn method(&self) -> impl Trait<Type: '_>;
    // the problematic bound ------------^^
}

Version information

rustc 1.82.0-nightly (2d5a628a1 2024-07-26)
binary: rustc
commit-hash: 2d5a628a1de1d38318909a710ef37da6251e362e
commit-date: 2024-07-26
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --crate-type=lib

Program output

warning: trait `Trait` is never used
 --> /tmp/icemaker_global_tempdir.esDLOVYEjfST/rustc_testrunner_tmpdir_reporting.Iwz5Hytr9bHo/mvce.rs:1:7
  |
1 | trait Trait<Type> {
  |       ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning 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[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied
 --> /tmp/icemaker_global_tempdir.esDLOVYEjfST/rustc_testrunner_tmpdir_reporting.Iwz5Hytr9bHo/mvce.rs:4:30
  |
4 |     fn method(&self) -> impl Trait<Type: '_>;
  |                              ^^^^^ expected 1 generic argument
  |
note: trait defined here, with 1 generic parameter: `Type`
 --> /tmp/icemaker_global_tempdir.esDLOVYEjfST/rustc_testrunner_tmpdir_reporting.Iwz5Hytr9bHo/mvce.rs:1:7
  |
1 | trait Trait<Type> {
  |       ^^^^^ ----
note: delayed at compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs:1133:23 - disabled backtrace
 --> /tmp/icemaker_global_tempdir.esDLOVYEjfST/rustc_testrunner_tmpdir_reporting.Iwz5Hytr9bHo/mvce.rs:4:30
  |
4 |     fn method(&self) -> impl Trait<Type: '_>;
  |                              ^^^^^
help: add missing generic argument
  |
4 |     fn method(&self) -> impl Trait<Type, Type: '_>;
  |                                    +++++

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs:543:29 - disabled backtrace

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.82.0-nightly (2d5a628a1 2024-07-26) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
end of query stack

@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 Jul 26, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 26, 2024
@matthiaskrgr
Copy link
Member Author

#126054 cc @veera-sivarajan 🤔

@veera-sivarajan
Copy link
Contributor

@rustbot claim

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2024
@bors bors closed this as completed in 333c63b Aug 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Aug 7, 2024
Rollup merge of rust-lang#128377 - veera-sivarajan:fix-128249, r=davidtwco

Fix ICE Caused by Incorrectly Delaying E0107

Fixes  rust-lang#128249

For the following code:
```rust
trait Foo<T> {}
impl Foo<T: Default> for u8 {}
```
rust-lang#126054 added some logic to delay emitting E0107 as the names of associated type `T` in the impl header and generic parameter `T` in `trait Foo` match.

But it failed to ensure whether such unexpected associated type bounds are coming from a impl block header. This caused an ICE as the compiler was delaying E0107 for code like:
```rust
trait Trait<Type> {
    type Type;

    fn method(&self) -> impl Trait<Type: '_>;
}
```
because it assumed the associated type bound `Type: '_` is for the generic parameter `Type` in `trait Trait` since the names are same.

This PR adds a check to ensure that E0107 is delayed only in the context of impl block header.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants