Skip to content

ICE: rustc panics on trait bound with array associated type (stable) #48984

Closed
@fspmarshall

Description

@fspmarshall

I came across a compiler error (stable channel) while working with a trait which extends another trait (eg: trait Dog: Mammal { .. }). After some experimenting, it appears the error occurs when the base trait has at least one associated type, and the extending trait specifies the associated type as an array of some kind. In order to trigger the error, the extending trait must be defined in an external crate, and used to constrain a generic type parameter.

Here is the simplest replication of the error I could come up with:

define my_crate like so:

pub trait Foo { type Item; } // can be any trait w/ an associated type

pub trait Bar: Foo<Item=[u8;1]> {  } // length & type of array does not seem to matter

pull in my_crate from another crate:

extern crate my_crate;
use my_crate::Bar;

fn do_thing<T: Bar>() { } // bounds on structs and impls also trigger bug

attempting to compile the above generates this error:

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.24.1 (d3ae9a9e0 2018-02-27) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:335:21

Judging by the backtrace it seems likely that the offending unwrap is one of these two, but that is just a guess.

I've replicated this bug with my local rust install as well as the latest version of the official rust docker image.

Verbose rustc version info for my local install:

rustc 1.24.1 (d3ae9a9e0 2018-02-27)
binary: rustc
commit-hash: d3ae9a9e08edf12de0ed82af57ba2a56c26496ea
commit-date: 2018-02-27
host: x86_64-unknown-linux-gnu
release: 1.24.1
LLVM version: 4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions