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

Impl trait crash: invalid region in impl Trait: ReEmpty #35668

Closed
SirVer opened this issue Aug 14, 2016 · 3 comments
Closed

Impl trait crash: invalid region in impl Trait: ReEmpty #35668

SirVer opened this issue Aug 14, 2016 · 3 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@SirVer
Copy link

SirVer commented Aug 14, 2016

This is on MacOS X with rustc 1.12.0-nightly (1deb02ea6 2016-08-12).

This program:

#![feature(conservative_impl_trait)]

fn func<'a, T>(a: &'a [T]) -> impl Iterator<Item=&'a T> {
    a.iter().map(|a| a*a)
}

fn main() {
    let a = (0..30).collect::<Vec<_>>();

    for k in func(&a) {
        println!("{}", k);
    }
}

crashes with

Compiling blub v0.1.0 (file:///private/tmp/blub)
error[E0369]: binary operation `*` cannot be applied to type `&T`
 --> src/main.rs:4:22
  |
4 |     a.iter().map(|a| a*a)
  |                      ^
  |
note: an implementation of `std::ops::Mul` might be missing for `&T`
 --> src/main.rs:4:22
  |
4 |     a.iter().map(|a| a*a)
  |                      ^

error: internal compiler error: ../src/librustc_typeck/check/writeback.rs:343: invalid region in impl Trait: ReEmpty
 --> src/main.rs:3:31
  |
3 | fn func<'a, T>(a: &'a [T]) -> impl Iterator<Item=&'a T> {
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^

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/librustc_errors/lib.rs:580
stack backtrace:
   1:        0x10b78343e - std::sys::backtrace::tracing::imp::write::h29f5fdb9fc0a7395
   2:        0x10b79258f - std::panicking::default_hook::_{{closure}}::h17d8437f66223ab1
   3:        0x10b790a1d - std::panicking::default_hook::hbbe7fa36a995aca0
   4:        0x10b791136 - std::panicking::rust_panic_with_hook::h105c3d42fcd2fb5e
   5:        0x106dc932b - std::panicking::begin_panic::hccc513334ab977d2
   6:        0x106f24c7d - rustc::session::opt_span_bug_fmt::_{{closure}}::h62b0957667555cfe
   7:        0x106df9959 - rustc::session::span_bug_fmt::hcdfbe9cf944f6fc3
   8:        0x106f1f9f9 - rustc_typeck::check::writeback::WritebackCx::visit_anon_types::_{{closure}}::hc59c3ae4d9a65396
   9:        0x107f3a55d - _<rustc..ty..fold..RegionFolder<'a, 'gcx, 'tcx> as rustc..ty..fold..TypeFolder<'gcx, 'tcx>>::fold_region::hf546bdf998324773
  10:        0x106de1948 - rustc::ty::fold::TypeFolder::fold_substs::h55fbad8fa7647f08
  11:        0x106de2922 - rustc::ty::fold::TypeFolder::fold_ty::hb0362f5378b07a40
  12:        0x106de1b99 - rustc::ty::fold::TypeFolder::fold_substs::h55fbad8fa7647f08
  13:        0x106de2922 - rustc::ty::fold::TypeFolder::fold_ty::hb0362f5378b07a40
  14:        0x106e26e95 - rustc_typeck::check::writeback::_<impl rustc_typeck..check..FnCtxt<'a, 'gcx, 'tcx>>::resolve_type_vars_in_fn::h2c631aecefe427eb
  15:        0x106e8e2b8 - rustc_typeck::check::check_bare_fn::h705fb24e3f39423b
  16:        0x106e92232 - rustc_typeck::check::check_item_body::h26c5d995a8cf2591
  17:        0x106e8af75 - rustc_typeck::check::check_item_bodies::h879e0600ff9f7c52
  18:        0x106f09998 - rustc_typeck::check_crate::h3586447e34ddb139
  19:        0x106bfb53a - rustc_driver::driver::phase_3_run_analysis_passes::_{{closure}}::h7f2cec505064b4bf
  20:        0x106b62372 - rustc::ty::context::TyCtxt::create_and_enter::he5dca3f2a7a0810a
  21:        0x106bc426f - rustc_driver::driver::compile_input::hb4cc34cf85dc1edf
  22:        0x106bec440 - rustc_driver::run_compiler::h50f95674bd902ab5
  23:        0x106b3794e - std::panicking::try::call::h31fc30b58c55d6c3
  24:        0x10b79940a - __rust_maybe_catch_panic
  25:        0x106b51033 - _<F as alloc..boxed..FnBox<A>>::call_box::h24f3eb0b42327962
  26:        0x10b78f7d5 - std::sys::thread::Thread::new::thread_start::h8f3bd45211e9f5ea
  27:     0x7fff82f2599c - _pthread_body
  28:     0x7fff82f25919 - _pthread_start

error: Could not compile `blub`.

To learn more, run the command again with --verbose.
@Aatch
Copy link
Contributor

Aatch commented Aug 15, 2016

/cc @rust-lang/compiler

@eddyb
Copy link
Member

eddyb commented Aug 15, 2016

Ah, I didn't take into account the possibility of type errors resulting in TyEmpty.

@eddyb eddyb added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Aug 15, 2016
@eddyb
Copy link
Member

eddyb commented Sep 6, 2016

I haven't went back to this because @nikomatsakis mentioned looking into redoing the lifetime interactions of impl Trait, at least as an experiment.

But if anyone else wants to patch it, the case of ReEmpty should be handled like ReStatic in the same match (they can be conflated into a single arm by doing gcx.mk_region(*r)).

@eddyb eddyb added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Sep 6, 2016
Manishearth added a commit to Manishearth/rust that referenced this issue Sep 10, 2016
bors added a commit that referenced this issue Sep 10, 2016
Handle `ReEmpty` for `impl Trait`

Closes #35668

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants