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 with borrowing with Futures #45437

Closed
mersinvald opened this issue Oct 21, 2017 · 3 comments
Closed

ICE with borrowing with Futures #45437

mersinvald opened this issue Oct 21, 2017 · 3 comments

Comments

@mersinvald
Copy link
Contributor

mersinvald commented Oct 21, 2017

Compiler ICEd on the code with mutable borrowing inside futures

I tried this code:

#![feature(conservative_impl_trait)] 
extern crate futures;

use futures::Future;
use futures::future::ok;

fn future1(data: &i32) -> impl Future<Item=&i32, Error=()> {
    ok(data)
}

fn main() {
    future1(&1).wait().unwrap();
}

https://play.rust-lang.org/?gist=62c4c9c732f500dab053d57fcd83fc11&version=nightly

I expected to see this happen:

Borrowing error saying me that I can't use anonymous lifetimes within futures

Instead, this happened:

ICE

Meta

rustc --version --verbose:

rustc 1.22.0-nightly (f6d751454 2017-10-17)
binary: rustc
commit-hash: f6d7514545cbe83e771a400d04049b96dfb210cd
commit-date: 2017-10-17
host: x86_64-unknown-linux-gnu
release: 1.22.0-nightly
LLVM version: 4.0

Backtrace:

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:439:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:69
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:58
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: rustc::session::opt_span_bug_fmt::{{closure}}
   8: rustc::session::span_bug_fmt
   9: rustc_typeck::check::Inherited::register_predicate
  10: <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  11: rustc_typeck::check::check_fn
  12: rustc_typeck::check::typeck_tables_of::{{closure}}
  13: rustc_typeck::check::typeck_tables_of
  14: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  15: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  16: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  17: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  18: rustc_typeck::check::typeck_item_bodies
  19: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  21: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  22: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  23: rustc_typeck::check_crate
  24: rustc::ty::context::TyCtxt::create_and_enter
  25: rustc_driver::driver::compile_input
  26: rustc_driver::run_compiler
@mersinvald mersinvald changed the title ICE with mutable borrowing with Futures ICE with borrowing with Futures Oct 21, 2017
@mersinvald
Copy link
Contributor Author

mersinvald commented Oct 21, 2017

Looks like an impl Trait is causing the problem. The following compiles well:

#![feature(conservative_impl_trait)] 
extern crate futures;

use futures::Future;
use futures::future::FutureResult;
use futures::future::ok;

fn future1(data: &i32) -> FutureResult<&i32, ()> {
    ok(data)
}

fn main() {
    future1(&1).wait().unwrap();
}

@mersinvald
Copy link
Contributor Author

mersinvald commented Oct 21, 2017

Also, the code with explicit lifetimes compiles well.

#![feature(conservative_impl_trait)] 
extern crate futures;

use futures::Future;
use futures::future::ok;

fn future1<'a>(data: &'a i32) -> impl Future<Item=&'a i32, Error=()> + 'a {
    ok(data)
}

fn main() {
    future1(&1).wait().unwrap();
}

@kennytm
Copy link
Member

kennytm commented Oct 22, 2017

Duplicate of #43396, #42479.

@kennytm kennytm closed this as completed Oct 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants