Skip to content

ICE in compute_type_of_item #55796

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

Closed
jneem opened this issue Nov 8, 2018 · 2 comments
Closed

ICE in compute_type_of_item #55796

jneem opened this issue Nov 8, 2018 · 2 comments
Labels
A-type-system Area: Type system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another.

Comments

@jneem
Copy link
Contributor

jneem commented Nov 8, 2018

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

@estebank estebank added A-type-system Area: Type system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Nov 8, 2018
@estebank
Copy link
Contributor

estebank commented Nov 8, 2018

This is caused by a lifetime check failing. I have a small patch that will side-step this issue and fix the ICE.

@estebank estebank added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Nov 8, 2018
@estebank
Copy link
Contributor

estebank commented Nov 8, 2018

Introduced in 1.28, it was fine before then.

pietroalbini added a commit to pietroalbini/rust that referenced this issue Nov 10, 2018
…r=oli-obk

Fix ICE in `return_type_impl_trait`

Fix rust-lang#55796.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another.
Projects
None yet
Development

No branches or pull requests

2 participants