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

region error "Cannot encode region variables" #3888

Closed
nejucomo opened this issue Oct 30, 2012 · 5 comments
Closed

region error "Cannot encode region variables" #3888

nejucomo opened this issue Oct 30, 2012 · 5 comments
Assignees
Labels
A-lifetimes Area: lifetime related I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Milestone

Comments

@nejucomo
Copy link

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
@nikomatsakis
Copy link
Contributor

hmm. I wasn't aware of this error. Sounds like a failing in region inference somehow (underconstrained?)

@ghost ghost assigned nikomatsakis Nov 1, 2012
@catamorphism
Copy link
Contributor

As of 89ed595 , this fails with a different error:

------------------------------------------
stderr:
------------------------------------------
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:6:19: 6:20 error: illegal borrow: borrowed value does not live long enough
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:6         let tail = v.view(1, v.len());
                                                                            ^
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:1:54: 9:1 note: borrowed pointer must be valid for the lifetime &r as defined on the block at 1:54...
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:1 fn vec_peek<T>(v: &r/[T]) -> Option< (&r/T, &r/[T]) > {
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:2     if v.len() == 0 {
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:3         None
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:4     } else {
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:5         let head = &v[0];
/Users/tchevalier/rust/src/test/run-pass/issue-3888.rs:6         let tail = v.view(1, v.len());
                                                         ...
note: ...but borrowed value is only valid for unknown scope: 79.  Please report a bug.
error: aborting due to previous error

Not sure if the illegal borrow part is intended or not, but the "unknown scope" part is at least a bad error message.

@catamorphism
Copy link
Contributor

I fixed the unknown scope error in my branch, but I'm still puzzled. I think the code should be valid.

I figured out that this minimized version still errors out:

fn vec_peek<T>(v: &r/[T]) -> &r/[T] {
    v.view(1, 5)
}

but this one compiles successfully:

fn vec_peek<T>(v: &r/[T]) -> &r/[T] {
    vec::view(v, 1, 5)
}

so I'm guessing this has to do with a bug with autoslicing and methods.

@pnkfelix
Copy link
Member

The "cannot encode region variables" error has been fixed.

I verified the results reported by catamorphism. That may be a bug, but the title of this bug is confusing matters. So I will open up a separate bug for the borrow checking issue.

@pnkfelix
Copy link
Member

Spawned off new ticket #5541. Closing this one.

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Mar 25, 2013
… astconv

and from typeck, which is verboten.  We are supposed to write inference results
into the FnCtxt and then these get copied over in writeback.  Add assertions
that no inference by-products are added to this table.

Fixes rust-lang#3888
Fixes rust-lang#4036
Fixes rust-lang#4492
nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Mar 26, 2013
… astconv

and from typeck, which is verboten.  We are supposed to write inference results
into the FnCtxt and then these get copied over in writeback.  Add assertions
that no inference by-products are added to this table.

Fixes rust-lang#3888
Fixes rust-lang#4036
Fixes rust-lang#4492
bors added a commit that referenced this issue Mar 26, 2013
…encode-region-variables, r=nikomatsakis

The basic problem was that vtables were not being resolved.  The fix uncovered another issue, which was that the syntax extensions were not creating method calls properly and were relying on outdated code in typeck, so I fixed that too.  

Resolves issues #3888, #4036, #4492.

r? @catamorphism
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants