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

Rust ICE when using for all binder (panics in MIR) on stable 1.34.0 and nightly 1.35.0 #60274

Closed
RustyYato opened this issue Apr 25, 2019 · 4 comments · Fixed by #60327
Closed
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. 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

@RustyYato
Copy link
Contributor

pub trait Generator<'this> {
    type Yield: 'this;
    
    fn next(&'this mut self) -> Option<Self::Yield>;
}

pub trait FromGenerator<'gen, G: Generator<'gen>> {
    fn from_generator(g: G) -> Self;
}

impl<T, G> FromGenerator<'_, G> for Vec<T>
where G: for<'a> Generator<'a, Yield = T> {
    fn from_generator(mut g: G) -> Self {
        let mut vec = Self::new();

        while let Some(x) = g.next() {
            vec.push(x)
        }

        vec
    }
}

pub struct Iter<I: ?Sized>(I);

impl<'this, I: ?Sized + Iterator> Generator<'this> for Iter<I> where I::Item: 'this {
    type Yield = I::Item;

    fn next(&'this mut self) -> Option<Self::Yield> {
        self.0.next()
    }
}

fn main() {
    let indicies = [];
    Vec::<&u32>::from_generator(Iter(indicies.iter()));
}

While I was trying to make a general Generator impl, I came across this ICE. Note that inlining indicies makes this ICE go away.

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. 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 Apr 25, 2019
@jonas-schievink
Copy link
Contributor

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:347:21
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   7: rust_begin_unwind
             at src/libstd/panicking.rs:308
   8: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   9: core::panicking::panic
             at src/libcore/panicking.rs:49
  10: rustc_mir::borrow_check::nll::region_infer::error_reporting::<impl rustc_mir::borrow_check::nll::region_infer::RegionInferenceContext>::free_region_constraint_info
  11: rustc_mir::borrow_check::nll::explain_borrow::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::explain_why_borrow_contains_point
  12: rustc_mir::borrow_check::error_reporting::<impl rustc_mir::borrow_check::MirBorrowckCtxt>::report_borrowed_value_does_not_live_long_enough
  13: rustc_mir::borrow_check::MirBorrowckCtxt::check_for_invalidation_at_exit
  14: rustc_mir::borrow_check::flows::Flows::with_outgoing_borrows
  15: <rustc_mir::borrow_check::MirBorrowckCtxt as rustc_mir::dataflow::DataflowResultsConsumer>::visit_terminator_entry
  16: rustc_mir::borrow_check::do_mir_borrowck
  17: rustc::ty::context::GlobalCtxt::enter_local
  18: rustc_mir::borrow_check::mir_borrowck
  19: rustc::ty::query::__query_compute::mir_borrowck
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  21: rustc::dep_graph::graph::DepGraph::with_task_impl
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  23: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  24: rustc::util::common::time
  25: rustc_interface::passes::analysis
  26: rustc::ty::query::__query_compute::analysis
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  30: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  31: rustc_interface::passes::create_global_ctxt::{{closure}}
  32: rustc_interface::passes::BoxedGlobalCtxt::enter
  33: rustc_interface::interface::run_compiler_in_existing_thread_pool
  34: std::thread::local::LocalKey<T>::with
  35: scoped_tls::ScopedKey<T>::set
  36: syntax::with_globals
query stack during panic:
#0 [mir_borrowck] processing `main`
#1 [analysis] running analysis passes on this crate
end of query stack

@jonas-schievink jonas-schievink added the A-NLL Area: Non-lexical lifetimes (NLL) label Apr 25, 2019
@RustyYato
Copy link
Contributor Author

RustyYato commented Apr 25, 2019

@jonas-schievink thanks for putting the stack-trace, I forgot about that

This also works

Vec::<u32>::from_generator(Iter(indicies.iter().cloned()));

@matthewjasper
Copy link
Contributor

Small repro:

pub trait Outlives<'this> {}

impl<'this, T> Outlives<'this> for T where T: 'this {}

fn assert_static_via_hrtb<G>(_: G) where for<'a> G: Outlives<'a> {}

fn main() {
    let local = 0;
    assert_static_via_hrtb(&local);
}

I'll try to have a PR up for this next week.

@jonas-schievink
Copy link
Contributor

Another repro from #60314:

trait Trait {
    type AssociatedType;
}

impl<'a, T : 'a> Trait for &'a T {
    type AssociatedType = &'a ();
}

/// Calling this with some T when we don't have `T : 'static` leads to an ICE
fn foo<T> (_: &'_ T)
where
    for<'a> &'a T : Trait<AssociatedType = &'a ()>,
{}

/// proof
fn main ()
{
    use ::core::convert::identity as force_local;
    match force_local(()) { ref not_static => {
        foo(&not_static);
    }}
}

Centril added a commit to Centril/rust that referenced this issue May 1, 2019
…-lbl, r=nikomatsakis

Search for incompatible universes in borrow errors

If we have a borrow that has to live for `'static` we need to check for
any regions in incompatible universes when trying to find the cause.

closes rust-lang#60274
Centril added a commit to Centril/rust that referenced this issue May 1, 2019
…-lbl, r=nikomatsakis

Search for incompatible universes in borrow errors

If we have a borrow that has to live for `'static` we need to check for
any regions in incompatible universes when trying to find the cause.

closes rust-lang#60274
Centril added a commit to Centril/rust that referenced this issue May 1, 2019
…-lbl, r=nikomatsakis

Search for incompatible universes in borrow errors

If we have a borrow that has to live for `'static` we need to check for
any regions in incompatible universes when trying to find the cause.

closes rust-lang#60274
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. 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

Successfully merging a pull request may close this issue.

3 participants