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

internal compiler error when inferring _ type for Associated Type bound #79590

Open
woodsmur opened this issue Dec 1, 2020 · 12 comments
Open
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-objects Area: trait objects, vtable layout C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@woodsmur
Copy link

woodsmur commented Dec 1, 2020

Rust compiler error for simple code like this:

Code

playaround

trait Database: Restriction<Inner = u32> {}

trait Restriction {
    type Inner;
}

struct Test {}

impl Database for Test {}
impl Restriction for Test {
    type Inner = u32;
}

fn main() {
    let t = Test {};
    let x: &dyn Database<Inner = _> = &t;
}

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-apple-darwin
release: 1.48.0
LLVM version: 11.0

Error output

   Compiling aaaa v0.1.0 (/Users/dudu/tmp/aaaa)
warning: trait objects without an explicit `dyn` are deprecated
  --> src/main.rs:16:13
   |
16 |     let x: &Database<Inner = _> = &t;
   |             ^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Database<Inner = _>`
   |
   = note: `#[warn(bare_trait_objects)]` on by default

warning: unused variable: `x`
  --> src/main.rs:16:9
   |
16 |     let x: &Database<Inner = _> = &t;
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: Error finalizing incremental compilation session directory `/Users/dudu/tmp/aaaa/target/debug/incremental/aaaa-3t9641te2lvvd/s-ftkew3bbem-6oinlz-working`: No such file or directory (os error 2)

warning: 3 warnings emitted

error: internal compiler error: broken MIR in DefId(0:10 ~ aaaa[fab6]::main) (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Ty(General(U0)) }, CanonicalVarInfo { kind: Region(U0) }], value: Ty(&dyn Database<Inner = ^1_1, Inner = u32>) }, span: src/main.rs:16:12: 16:32 (#0), inferred_ty: &dyn Database<Inner = u32, Inner = u32> }): bad user type (&dyn Database<Inner = _, Inner = u32> = &dyn Database<Inner = u32, Inner = u32>): NoSolution
  |
  = note: delayed at compiler/rustc_mir/src/borrow_check/type_check/mod.rs:258:27

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:961:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.48.0 (7eac88abb 2020-11-16) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: could not compile `aaaa`

To learn more, run the command again with --verbose.
Backtrace

<backtrace>

@woodsmur woodsmur added 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. labels Dec 1, 2020
@matthiaskrgr
Copy link
Member

@rustbot prioritize

@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 1, 2020
@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 1, 2020

Reproduces on
stable 1.48.0
beta 1.49.0-beta.2
nightly 1.50.0 (1c389ff 2020-11-24)

@matthiaskrgr
Copy link
Member

The ICE triggers since 1.45

@matthiaskrgr
Copy link
Member

@rustbot label +regression-from-stable-to-stable

@rustbot rustbot added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Dec 1, 2020
@camelid camelid added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 1, 2020
@camelid
Copy link
Member

camelid commented Dec 1, 2020

Assigning P-high and removing I-prioritize as discussed in the prioritization working group.

@camelid
Copy link
Member

camelid commented Dec 1, 2020

rustbot added a commit to rustbot/glacier that referenced this issue Dec 1, 2020
camelid added a commit to rust-lang/glacier that referenced this issue Dec 1, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 1, 2020
@osa1
Copy link
Contributor

osa1 commented Jan 30, 2021

I'm trying to debug this and have a question on Zulip (also copied to internals). If anyone have any pointers that would be helpful.

@osa1
Copy link
Contributor

osa1 commented Feb 2, 2021

I found the code where we add the duplicate Inner = _ predicate mentioned in the Zulip and internals links above, and confirmed that if I don't add the duplicate the program compiles fine. I'm not 100% sure this is the root cause but I think having two predicates for the same associated type doesn't make sense so I'm hopeful.

If I remove the code block that adds the duplicate predicate I get 8 UI test failures. I'll try to figure out why that code exists by looking at failing tests now.

@jackh726 jackh726 added the WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 label Feb 3, 2022
@oli-obk oli-obk added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 labels Jul 15, 2022
@lcnr
Copy link
Contributor

lcnr commented Jul 15, 2022

@rustbot claim

@pnkfelix
Copy link
Member

Visiting for P-high review

@lcnr is there a roadmap for resolving this? Should we open it up for other people to claim?

(The error does seem like it remains P-high worthy, since I can imagine this to be pretty frustrating to someone since it doesn't print any diagnostic info guiding them towards even the obvious workaround of plugging in u32 for the _ type)

@pnkfelix pnkfelix changed the title internal compiler error: unexpected panic internal compiler error when inferring _ type for Associated Type bound Dec 16, 2022
@lcnr lcnr removed their assignment Dec 16, 2022
@lcnr
Copy link
Contributor

lcnr commented Dec 16, 2022

The issue here is that the associated type bound is redundant, we're specifying Inner on Database even though that one is already fully constrained by the trait definition of Database itself.

I don't think it necessarily needs a roadmap, I expect it to be a fairly self-contained - if complex - fix.

@compiler-errors compiler-errors self-assigned this Dec 16, 2022
@compiler-errors
Copy link
Member

I've taken a look at this in the past but I can again 👀

@compiler-errors compiler-errors removed their assignment Aug 11, 2023
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
@fmease fmease added A-associated-items Area: Associated items (types, constants & functions) A-trait-objects Area: trait objects, vtable layout labels Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-objects Area: trait objects, vtable layout C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests