Skip to content

region error "Cannot encode region variables" #3888

Closed
@nejucomo

Description

@nejucomo

The following code causes the compiler to fail. Conversation on IRC suggests this is a known issue, but I could not find this specific error by searching tickets for "Cannot encode region variables" nor any of the hits for "region variables".

I apologize if this is a duplicate.

$ cat ./vecpeek.rs
extern mod std; // Only for tests.


fn vec_peek<T>(v: &r/[T]) -> Option< (&r/T, &r/[T]) > {
    if v.len() == 0 {
        None
    } else {
        let head = &v[0];
        let tail = v.view(1, v.len());
        Some( (head, tail) )
    }
}


mod tests {
    /* Testing the different storage locations covers features which
     * should be completely orthogonal (ie: that regions work with any
     * storage area, but the language is young, so we do test just
     * in case.
     */
    #[test]
    fn test_peek_empty_stack() {
        let v : &[int] = &[];
        assert (None == vec_peek(v));
    }

    #[test]
    fn test_peek_empty_unique() {
        let v : ~[int] = ~[];
        assert (None == vec_peek(v));
    }

    #[test]
    fn test_peek_empty_managed() {
        let v : @[int] = @[];
        assert (None == vec_peek(v));
    }

    /*
    #[test]
    fn test_peek_full_stack() {
        let v: &[int] = &[1, 2, 3];
        let head: &int = &v[0];
        let tail: &[int] = v.view(1, v.len());

        match

        assert (None == vec_peek(v));
    }
    */
}

$ rustc --test ./vecpeek.rs
error: internal compiler error: Cannot encode region variables

$ rustc --version
rustc 0.5 (07edf90 2012-10-13 05:57:13 -0700)
host: x86_64-unknown-linux-gnu

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions