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

NLL mode causes ICE (region_obligations not empty) #51771

Closed
danielrh opened this issue Jun 25, 2018 · 2 comments
Closed

NLL mode causes ICE (region_obligations not empty) #51771

danielrh opened this issue Jun 25, 2018 · 2 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@danielrh
Copy link

The following code fails on nightly, but worked several nightlies ago (perhaps in the ~1.25 era)

#![no_std]
#![feature(nll)]

#[cfg(not(feature="no-stdlib"))]
extern crate std;
use core::default::Default;
pub use core::ops::IndexMut;
pub use core::ops::Index;
pub use core::ops::Range;
pub trait SliceWrapper<T> {
    fn slice(& self) -> & [T];
    fn len(&self) -> usize{
        self.slice().len()
    }
}

pub trait SliceWrapperMut<T> : SliceWrapper<T> {
  fn slice_mut (&mut self) -> & mut [T];
}

pub trait AllocatedSlice<T>
    : SliceWrapperMut<T> + SliceWrapper<T> + Default {
}

impl<T, U> AllocatedSlice<T> for U where U : SliceWrapperMut<T> + SliceWrapper<T> + Default {

}


pub struct AllocatedStackMemory<'a, T:'a> {
    pub mem : &'a mut [T],
}

macro_rules! define_index_ops_mut {

    ($T0: ident, $T:ident, $MemoryType:ty) => {
        impl<'a, $T> ::core::ops::Index<usize> for $MemoryType
        {
            type Output = T;

            #[inline]
            fn index(&self, index: usize) -> &Self::Output {
                ::core::ops::Index::index(&**self, index)
            }
        }
        
        impl<'a, $T> ::core::ops::IndexMut<usize> for $MemoryType
        {
            #[inline]
            fn index_mut(&mut self, index: usize) -> &mut Self::Output {
                ::core::ops::IndexMut::index_mut(&mut **self, index)
            }
        }
        
        


        impl<'a, $T> ::core::ops::Deref for $MemoryType {
            type Target = [T];
            
            fn deref(&self) -> &[T] {
                self.slice()
            }
        }
        impl<'a, $T> ::core::ops::DerefMut for $MemoryType {
            fn deref_mut(&mut self) -> &mut [T] {
                self.slice_mut()
            }
        }
    }
}
define_index_ops_mut!(a, T, AllocatedStackMemory<'a, T>);

impl<'a, T: 'a> core::default::Default for AllocatedStackMemory<'a, T> {
    fn default() -> Self {
        return AllocatedStackMemory::<'a, T>{mem : &mut[]};
    }
}


impl<'a, T: 'a> SliceWrapper<T> for AllocatedStackMemory<'a, T> {
    fn slice(& self) -> & [T] {
        return & self.mem;
    }
}

impl<'a, T: 'a> SliceWrapperMut<T> for AllocatedStackMemory<'a, T> {
    fn slice_mut(& mut self) ->& mut [T] {
        return &mut self.mem;
    }
}

The command invoked was:

$ rustc lib.rs --crate-type lib
thread 'main' panicked at 'region_obligations not empty: [
    (
        NodeId(
            167
        ),
        RegionObligation(sub_region='_#2r, sup_type=T)
    )
]', librustc/infer/mod.rs:1057:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.

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: rustc 1.28.0-nightly (01cc982e9 2018-06-24) running on x86_64-apple-darwin

note: compiler flags: --crate-type lib

A standalone crate in the wild that shows the problem is:
https://github.com/dropbox/rust-alloc-no-stdlib/tree/nll

@danielrh danielrh changed the title NLL mode causes panic NLL mode causes ICE Jun 25, 2018
@danielrh
Copy link
Author

Probably a duplicate of #51649

@danielrh danielrh changed the title NLL mode causes ICE NLL mode causes ICE (region_obligations not empty) Jun 25, 2018
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 25, 2018
@lqd lqd added the A-NLL Area: Non-lexical lifetimes (NLL) label Jun 27, 2018
@nikomatsakis
Copy link
Contributor

Closing as duplicate of #51649

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) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants