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

Lifetime-polymorphic anonymous function causing compiler panic #30860

Closed
asajeffrey opened this issue Jan 12, 2016 · 6 comments
Closed

Lifetime-polymorphic anonymous function causing compiler panic #30860

asajeffrey opened this issue Jan 12, 2016 · 6 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@asajeffrey
Copy link

The program at https://play.rust-lang.org/?gist=1a60fe4cd514848f6788 generates the following:

<anon>:44:5: 44:26 error: internal compiler error: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<[closure@<anon>:40:19: 40:65] as core::ops::Fn<(<Str as TypeWithLifetime<'_>>::Type,)>>)),depth=1),OutputTypeParameterMismatch(Binder(<[closure@<anon>:40:19: 40:65] as core::ops::Fn<(&'static str,)>>), Binder(<[closure@<anon>:40:19: 40:65] as core::ops::Fn<(<Str as TypeWithLifetime<'_>>::Type,)>>), Sorts(ExpectedFound { expected: <Str as TypeWithLifetime<'_>>::Type, found: &'static str }))), FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<[closure@<anon>:40:19: 40:65] as core::ops::FnOnce<(<Str as TypeWithLifetime<'_>>::Type,)>>)),depth=1),OutputTypeParameterMismatch(Binder(<[closure@<anon>:40:19: 40:65] as core::ops::FnOnce<(&'static str,)>>), Binder(<[closure@<anon>:40:19: 40:65] as core::ops::FnOnce<(<Str as TypeWithLifetime<'_>>::Type,)>>), Sorts(ExpectedFound { expected: <Str as TypeWithLifetime<'_>>::Type, found: &'static str })))]` fulfilling during trans
<anon>:44     consumer.accept("hi");
              ^~~~~~~~~~~~~~~~~~~~~
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/diagnostic.rs:176

Reported on #rust-lang irc, @aturon reckons this is new, and should be filed with a mention of @nikomatsakis.

@jonas-schievink
Copy link
Contributor

Reduced:

trait TypeWithLifetime<'a> {
    type Type;
}

type At<'a,T> where T: TypeWithLifetime<'a> = T::Type;

fn main() {
    let _ = |x:At<()>| false;
}

@asajeffrey
Copy link
Author

The reduced example should fail to typecheck, I'd hope that my one actually would typecheck.

@jonas-schievink
Copy link
Contributor

Oh, you're right. I'm wondering if at least my example is caused by #21903

@nikomatsakis
Copy link
Contributor

Some data. First off, I modified the test by removing the At alias and got this, which fails differently:

http://is.gd/xIgh8f

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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: !projection_ty.has_escaping_regions()', ../src/librustc/middle/traits/fulfill.rs:149

At one point, I had modified the list closure to read |x:&str| instead http://is.gd/jSRlJG (which I think is equivalent) and then the error is somewhat different:

<anon>:44:14: 44:26 error: type mismatch: the type `[closure@<anon>:40:19: 40:62]` implements the trait `for<'r> core::ops::Fn<(&'r str,)>`, but the trait `for<'r> core::ops::Fn<(<Str as TypeWithLifetime<'r>>::Type,)>` is required (expected associated type, found &-ptr) [E0281]
<anon>:44     consumer.accept("hi");
                       ^~~~~~~~~~~~
<anon>:44:14: 44:26 help: see the detailed explanation for E0281
<anon>:44:14: 44:26 error: type mismatch: the type `[closure@<anon>:40:19: 40:62]` implements the trait `for<'r> core::ops::FnOnce<(&'r str,)>`, but the trait `for<'r> core::ops::FnOnce<(<Str as TypeWithLifetime<'r>>::Type,)>` is required (expected associated type, found &-ptr) [E0281]
<anon>:44     consumer.accept("hi");
                       ^~~~~~~~~~~~
<anon>:44:14: 44:26 help: see the detailed explanation for E0281
error: aborting due to 2 previous errors

what all of this is pointing at is some errors around the late-bound lifetimes. The ICE in question may well arise due to getting the accounting wrong in trans, unclear.

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 26, 2016
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@istankovic
Copy link
Contributor

With rustc 1.26.0-nightly (adf2135ad 2018-03-17) the reduced example by @jonas-schievink fails to typecheck i.e. it no longer ICEs, however http://is.gd/xIgh8f is still problematic.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 10, 2019

The only remaining issue here is http://is.gd/xIgh8f, which I am treating as duplicate of #62529, the issue where I will try to track future instances of this field of ICE. Closing as fixed for the initial bug report, and duplicate for the related issue http://is.gd/xIgh8f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

7 participants