Skip to content

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

Closed
@woodsmur

Description

@woodsmur

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-dyn-traitArea: trait objects, vtable layoutC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions