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

Internal compiler error #7741

Closed
heartpunk opened this issue Jul 12, 2013 · 4 comments
Closed

Internal compiler error #7741

heartpunk opened this issue Jul 12, 2013 · 4 comments
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@heartpunk
Copy link

➜  datastructures.rs git:(master) ✗ RUST_LOG="rustc=1;::rt::backtrace" rustc stack.rs &&./stack
rust: task failed at 'assertion failed: rp.is_none()', /private/tmp/rust-5o4g/rust-0.7/src/librustc/middle/typeck/collect.rs:1040
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /private/tmp/rust-5o4g/rust-0.7/src/librustc/rustc.rs:354
rust: domain main @0x7f9afc008410 root task failed

The code that caused it is:

trait ImmStack<T> {
    fn push(self, item : T) -> Self;
    fn pop(self) -> (Option<T>, Option<Self>);
    fn new() -> Self;
}

#[deriving(Eq, ToStr)]
enum Chain<T> {
    Link(T, ~Chain<T>),
    Break
}

//impl<T> ImmStack<T> for Chain<T> {
//    fn push(self, item : T) -> Chain<T> {
//        Link(item, ~self)
//    }
//    fn pop(self) -> (Option<T>, Option<Chain<T>>) {
//        match self {
//            Link(item, ~new_self) => return (Some(item), Some(new_self)),
//            Break => return (None, None)
//        }
//    }
//    fn new() -> Chain<T> {
//        Break
//    }
//}

fn push<'self, T>(stack : &'self mut Chain<T>, item : T) -> &'self mut Chain<T> {
    &mut Link(item, ~*stack)
}

fn pop<T>(stack : &mut Chain<T>) -> Option<T> {
    match *stack {
        Link(item, ~new_stack) => {
            stack = &mut new_stack;
            return Some(item);
        },
        Break => return None
    }
}

fn new<T>() -> &mut Chain<T> {
    &mut Break
}

fn main() {
    let mut b : &Chain<int> = ~Break;
    push(push(push(b, 1), 2), 3);
    println(b.to_str());
}
@heartpunk
Copy link
Author

It's probably related to lifetimes, as I'd only added the lifetime stuff to push before this error happened.

@bblum
Copy link
Contributor

bblum commented Jul 15, 2013

What happens if you change 'self to 'a?

@heartpunk
Copy link
Author

This happens:

immstack.rs:29:4: 30:1 error: borrowed value does not live long enough
immstack.rs:29     &mut Link(item, ~*stack)
immstack.rs:30 }
immstack.rs:28:71: 30:1 note: borrowed pointer must be valid for the lifetime &'a  as defined on the block at 28:71...
immstack.rs:28 fn push<'a, T>(stack : &'a mut Chain<T>, item : T) -> &'a mut Chain<T> {
immstack.rs:29     &mut Link(item, ~*stack)
immstack.rs:30 }
immstack.rs:28:71: 30:1 note: ...but borrowed value is only valid for the block at 28:71
immstack.rs:28 fn push<'a, T>(stack : &'a mut Chain<T>, item : T) -> &'a mut Chain<T> {
immstack.rs:29     &mut Link(item, ~*stack)
immstack.rs:30 }
immstack.rs:29:21: 29:27 error: cannot move out of dereference of & pointer
immstack.rs:29     &mut Link(item, ~*stack)
                                    ^~~~~~
immstack.rs:34:8: 34:30 error: cannot move out of dereference of & pointer
immstack.rs:34         Link(item, ~new_stack) => {
                       ^~~~~~~~~~~~~~~~~~~~~~
immstack.rs:34:19: 34:29 error: cannot move out of dereference of & pointer
immstack.rs:34         Link(item, ~new_stack) => {
                                  ^~~~~~~~~~
immstack.rs:35:20: 35:34 error: borrowed value does not live long enough
immstack.rs:35             stack = &mut new_stack;
                                   ^~~~~~~~~~~~~~
immstack.rs:32:46: 40:1 note: borrowed pointer must be valid for the anonymous lifetime #1 defined on the block at 32:46...
immstack.rs:32 fn pop<T>(stack : &mut Chain<T>) -> Option<T> {
immstack.rs:33     match *stack {
immstack.rs:34         Link(item, ~new_stack) => {
immstack.rs:35             stack = &mut new_stack;
immstack.rs:36             return Some(item);
immstack.rs:37         },
               ...
immstack.rs:33:4: 39:5 note: ...but borrowed value is only valid for the match at 33:4
immstack.rs:33     match *stack {
immstack.rs:34         Link(item, ~new_stack) => {
immstack.rs:35             stack = &mut new_stack;
immstack.rs:36             return Some(item);
immstack.rs:37         },
immstack.rs:38         Break => return None
               ...
immstack.rs:35:20: 35:34 error: cannot borrow immutable local variable as mutable
immstack.rs:35             stack = &mut new_stack;
                                   ^~~~~~~~~~~~~~
immstack.rs:35:12: 35:17 error: cannot assign to immutable argument
immstack.rs:35             stack = &mut new_stack;
                           ^~~~~
immstack.rs:43:4: 43:14 error: cannot borrow immutable static item as mutable
immstack.rs:43     &mut Break
                   ^~~~~~~~~~
immstack.rs:48:19: 48:20 error: cannot borrow immutable dereference of & pointer as mutable
immstack.rs:48     push(push(push(b, 1), 2), 3);
                                  ^
error: aborting due to 9 previous errors

Which seems like it's could be right, but I certainly don't understand well enough to judge yet.

@alexcrichton
Copy link
Member

Closing as a duplicate of #7989. When the lifetime is changed from 'self to 'a the compiler errors are all legitimate.

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 7, 2021
Make if_then_panic handle situation of BinOpKind::And || BinOpKind::Or

fixes rust-lang#7731

Make if_then_panic handle situation of cond.kind = ExprKind::DropTemps(ExprKind::Binary(BinOpKind::And || BinOpKind::Or, left, right), ..) =

changelog: [`if_then_panic`] Fix suggestion for more complex conditions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants