Skip to content

ICE in compute_type_of_item #55796

Closed
Closed

Description

The following two trait definitions cause an ICE in current nightly, beta, and stable.

pub trait EdgeTrait<N> {
    fn target(&self) -> N;
}

pub trait Graph<'a> {
    type Node;
    type Edge: EdgeTrait<Self::Node>;
    type NodesIter: Iterator<Item = Self::Node> + 'a;
    type EdgesIter: Iterator<Item = Self::Edge> + 'a;

    fn nodes(&'a self) -> Self::NodesIter;
    fn out_edges(&'a self, u: &Self::Node) -> Self::EdgesIter;
    fn in_edges(&'a self, u: &Self::Node) -> Self::EdgesIter;

    fn out_neighbors(&'a self, u: &Self::Node) -> Box<Iterator<Item = Self::Node>> {
        Box::new(self.out_edges(u).map(|e| e.target()))
    }

    fn in_neighbors(&'a self, u: &Self::Node) -> Box<Iterator<Item = Self::Node>> {
        Box::new(self.in_edges(u).map(|e| e.target()))
    }
}

The error is:

error: internal compiler error: librustc_typeck/collect.rs:1202: compute_type_of_item: unexpected item type: Trait(No, Normal, Generics { params: [GenericParam { id: NodeId(15), name: Plain('a#0), attrs: [], bounds: [], span: src/lib.rs:5:17: 5:19, pure_wrt_drop: false, kind: Lifetime { kind: Explicit } }], where_clause: WhereClause { id: NodeId(16), predicates: [] }, span: src/lib.rs:5:16: 5:20 }, [], [TraitItemRef { id: TraitItemId { node_id: NodeId(17) }, ident: Node#0, kind: Type, span: src/lib.rs:6:5: 6:15, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(19) }, ident: Edge#0, kind: Type, span: src/lib.rs:7:5: 7:38, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(23) }, ident: NodesIter#0, kind: Type, span: src/lib.rs:8:5: 8:54, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(29) }, ident: EdgesIter#0, kind: Type, span: src/lib.rs:9:5: 9:54, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(35) }, ident: nodes#0, kind: Method { has_self: true }, span: src/lib.rs:11:5: 11:43, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(43) }, ident: out_edges#0, kind: Method { has_self: true }, span: src/lib.rs:12:5: 12:63, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(55) }, ident: in_edges#0, kind: Method { has_self: true }, span: src/lib.rs:13:5: 13:62, defaultness: Default { has_value: false } }, TraitItemRef { id: TraitItemId { node_id: NodeId(67) }, ident: out_neighbors#0, kind: Method { has_self: true }, span: src/lib.rs:15:5: 17:6, defaultness: Default { has_value: true } }, TraitItemRef { id: TraitItemId { node_id: NodeId(95) }, ident: in_neighbors#0, kind: Method { has_self: true }, span: src/lib.rs:19:5: 21:6, defaultness: Default { has_value: true } }])
  --> src/lib.rs:5:1
   |
5  | / pub trait Graph<'a> {
6  | |     type Node;
7  | |     type Edge: EdgeTrait<Self::Node>;
8  | |     type NodesIter: Iterator<Item = Self::Node> + 'a;
...  |
21 | |     }
22 | | }
   | |_^

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:538:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Here is a playground link demonstrating the issue: https://play.rust-lang.org/?version=beta&mode=debug&edition=2015&gist=ff49511ceb983c9d173452b455b574f8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-typesystemArea: The type systemI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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