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

ICE combining universal plus existential impl Trait #46685

Closed
nikomatsakis opened this issue Dec 12, 2017 · 1 comment
Closed

ICE combining universal plus existential impl Trait #46685

nikomatsakis opened this issue Dec 12, 2017 · 1 comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. 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.

Comments

@nikomatsakis
Copy link
Contributor

The following program will ICE:

#![feature(conservative_impl_trait)]
#![feature(universal_impl_trait)]

use std::fmt::Debug;

fn foo<'a>(x: &'a impl Debug) -> impl Into<&'a impl Debug> {
    x
}

fn main() { }

The problem derives from the fact that universal impl traits, during HIR lowering, do not generate entries in the hir::Generics structure -- they are synthesized after the fact, in the ty::Generics. This interferes with the resolve_lifetime code, which expects to use the HIR generics to determine the indices of things.

I'm not sure the best fix here. The easiest fix is probably to count the number of universal impl traits and take them into account in resolve_lifetime. The best fix feels like it would be to actually insert the type parameters for universal impl trait instances into hir::Generics.

cc @cramertj @chrisvittal

@nikomatsakis nikomatsakis added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. 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 12, 2017
@cramertj
Copy link
Member

cramertj commented Dec 12, 2017

The best fix feels like it would be to actually insert the type parameters for universal impl trait instances into hir::Generics

This actually might not be that hard-- you can probably re-use a lot of the code I set up for lowering in-band lifetime bindings. You'd have to synthesize names for them, though, and make sure there aren't any conflicting names, plus the names can't escape into error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. 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.
Projects
None yet
Development

No branches or pull requests

2 participants